Skip to content

feat(pj_base): add platform helpers for env and user data dir#61

Merged
pabloinigoblasco merged 1 commit into
developmentfrom
fix/pj-base-platform-helpers
Apr 19, 2026
Merged

feat(pj_base): add platform helpers for env and user data dir#61
pabloinigoblasco merged 1 commit into
developmentfrom
fix/pj-base-platform-helpers

Conversation

@pabloinigoblasco
Copy link
Copy Markdown
Collaborator

Summary

Add pj_base/sdk/platform.hpp with two Qt-free, header-only helpers:

  • PJ::sdk::getEnv(name) — read an env variable into std::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 matching QStandardPaths::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 #if ladders and stumbles like MSVC's C4996 on std::getenv. Centralising the helpers in pj_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.cpp covers:

  • getEnv roundtrip (set / unset / empty-string)
  • userDataDir ends in plotjuggler and is absolute
  • Per-OS branches: Windows LOCALAPPDATA, macOS Library/Application Support, Linux XDG_DATA_HOME and HOME/.local/share fallback

Downstream

The matching consumer PR in pj-official-plugins will remove the local pjUserDataDir() implementation in toolbox_reactive_scripts_editor and switch to this helper. That PR depends on this one landing on development so CPM picks it up on the next CI run.

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.
@pabloinigoblasco pabloinigoblasco merged commit 9de516c into development Apr 19, 2026
2 checks passed
@pabloinigoblasco pabloinigoblasco deleted the fix/pj-base-platform-helpers branch May 4, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant