Skip to content

feat: Replace eval with ${VAR} env expansion in Target#13

Merged
haugoug merged 1 commit intogvsoc:mainfrom
germainh512:env-templates
Mar 10, 2026
Merged

feat: Replace eval with ${VAR} env expansion in Target#13
haugoug merged 1 commit intogvsoc:mainfrom
germainh512:env-templates

Conversation

@germainh512
Copy link

Breaking Change

sourceme and envvars values in target configs now use ${VAR} syntax instead of Python expressions.

Before

{
  "sourceme": "os.path.join(os.environ.get(\"PULP_SDK_HOME\"), \"configs\", \"pulp-open.sh\")",
  "envvars": {
    "TOOLCHAIN": "os.environ.get(\"PULP_NN_GCC_TOOLCHAIN\")"
  }
}

After

{
  "sourceme": "${PULP_SDK_HOME}/configs/pulp-open.sh",
  "envvars": {
    "TOOLCHAIN": "${PULP_NN_GCC_TOOLCHAIN}"
  }
}

How it works

  • ${VAR}os.environ.get("VAR", "")
  • Missing vars expand to empty string
  • Multiple ${VAR} refs per value supported
  • No code execution — pure regex-based string substitution

No backward compatibility

Existing configs using os.path.join / os.environ.get expressions need to be updated to the new ${VAR} syntax.

126 tests passing (6 new target tests added).

sourceme and envvars values now use ${VAR} syntax for environment
variable expansion instead of Python eval()/ast.literal_eval().

Before (Python expression, broken by literal_eval):
  "sourceme": "os.path.join(os.environ.get(\"SDK\"), \"setup.sh\")"

After (simple template):
  "sourceme": "${SDK}/setup.sh"

- ${VAR} expands to os.environ.get("VAR", "")
- Missing variables expand to empty string
- Multiple ${VAR} refs in one value are supported
- No code execution at all — pure string substitution
- No backward compat shim (existing configs need updating)

126 tests passing (20 target tests, 6 new).
@haugoug haugoug merged commit 428a913 into gvsoc:main Mar 10, 2026
3 checks passed
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.

2 participants