feat(pj_base): add platform helpers for env and user data dir#61
Merged
Conversation
Introduce pj_base/sdk/platform.hpp with two Qt-free, header-only helpers that plugins would otherwise need to reimplement: - getEnv(name): reads an environment variable, returns std::optional. Wraps std::getenv with a local MSVC C4996 suppression so callers compile under /W4 /WX without the project-wide _CRT_SECURE_NO_WARNINGS flag. - userDataDir(): cross-platform per-user data directory matching QStandardPaths::writableLocation(GenericDataLocation) + "/plotjuggler", with a temp-dir fallback so the return is never empty. Adds platform_test with env-roundtrip coverage and per-OS userDataDir expectations. No existing code is migrated here; consumers will move to these helpers in follow-up patches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
pj_base/sdk/platform.hppwith two Qt-free, header-only helpers:PJ::sdk::getEnv(name)— read an env variable intostd::optional<std::string>, with a local MSVC C4996 suppression so callers compile cleanly under/W4 /WX.PJ::sdk::userDataDir()— cross-platform per-user data directory matchingQStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/plotjuggler", with a temp-dir fallback.Motivation
Plugins that need on-disk state (script libraries, cached downloads) currently reimplement this logic privately because they can't depend on Qt. That leads to duplicated platform
#ifladders and stumbles like MSVC's C4996 onstd::getenv. Centralising the helpers inpj_base— zero external deps, consumed by every plugin via CPM — gives us one place to fix, test, and evolve.No existing code is migrated in this PR. Consumers will switch over in follow-ups.
Test coverage
pj_base/tests/platform_test.cppcovers:getEnvroundtrip (set / unset / empty-string)userDataDirends inplotjugglerand is absoluteLOCALAPPDATA, macOSLibrary/Application Support, LinuxXDG_DATA_HOMEandHOME/.local/sharefallbackDownstream
The matching consumer PR in
pj-official-pluginswill remove the localpjUserDataDir()implementation intoolbox_reactive_scripts_editorand switch to this helper. That PR depends on this one landing ondevelopmentso CPM picks it up on the next CI run.