Skip to content

fixes #26296; relative --nimcache/--outdir paths with $ are made absolute - #26526

Open
konaito wants to merge 6 commits into
nim-lang:develfrom
konaito:fix-26296-dollar-paths
Open

konaito wants to merge 6 commits into
nim-lang:develfrom
konaito:fix-26296-dollar-paths

Conversation

@konaito

@konaito konaito commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

fixes #26296

processPath and processCfgPath do not prepend the base directory when the path contains $, because most variables ($nim, $lib, $home, $config, $projectdir, $nimcache) expand to absolute paths. $projectName expands to a bare name, so

nim c '--nimcache:build/nimcache/$projectName' '--outdir:build/$projectName' src/repro.nim

left querySetting(nimcacheDir) and querySetting(outDir) relative (build/nimcache/repro), while the same paths written without $ became absolute. In a config NimScript the same switch already comes back absolute, because pathRelativeToConfig prepends the config dir before processPath runs.

Fix: substitute first, and if the original path contained $ and the result is still relative, prepend the same base directory a path without $ would get (the current directory for --nimcache/--outdir/--out, the project path for --path, the config file's directory in processCfgPath). Paths without $, and $ paths that expand to an absolute path, are handled as before.

Test: a new block in tests/misc/trunner.nim runs nim check with relative --nimcache/--outdir containing $projectName and checks that querySetting returns absolute paths (tests/misc/m26296.nim).

Verification, on macOS arm64:

  • Before the fix, ./koch test run tests/misc/trunner.nim fails on the new assertion for both c and cpp (the output is build/D26296/nimcache/m26296). After the fix, it passes for both.
  • ./koch boot -d:release reaches a fixed point.
  • ./koch tests c for newconfig, nimble, import_in_config, compileoption, compilerapi, misc: all pass except tests/misc/tjoinable.nim, which asserts defined(nimMegatest) and only passes inside megatest. In manyloc and tools, nakefile, keineschweine (need the zip package) and tnimgrep (needs a built nimgrep) fail in my local setup for reasons unrelated to this change.
  • Not tested on Windows or Linux locally; relying on CI for those.

`processPath` and `processCfgPath` skipped prepending the base directory
when the path contained `$`, because `$nim`, `$lib`, `$config` etc. expand
to absolute paths. `$projectName` does not, so
`--nimcache:build/nimcache/$projectName` stayed relative while
`--nimcache:build/nimcache/foo` became absolute.

The base directory is now prepended after the substitution when the
result is still relative.
@Araq

Araq commented Oct 23, 2026

Copy link
Copy Markdown
Member

Implementation is too messy, probably improves a lot with a helper proc.

@konaito

konaito commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Moved the shared logic into a resolvePath helper.

@Araq

Araq commented Oct 23, 2026

Copy link
Copy Markdown
Member

Sorry but I'm still not happy. Instead put the logic into pathSubs or a new variant of it, where it belongs.

@konaito

konaito commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Moved the logic into a pathSubs overload that takes the base dir: it resolves relative paths against it, also after $ substitution. processPath and processCfgPath now only pick the base and call it.

This branch has not been deployed

No deployments
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.

--nimcache / --outdir paths containing $ are never made absolute

2 participants