-
Notifications
You must be signed in to change notification settings - Fork 810
lake: __dir__ contains relative path, that is cached and becomes wrong when using -d=.. flag #7498
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
__dir__ provided by lake when running from the package's root is ./.. When running from a subdirectory using -d=.., __dir__ is ../.. If running again without changing lakefile and without -R, __dir__ doesn't change regardless of cwd or -d=. As I understand, this is because it is stored in lakefile.olean.
Context
Steps to Reproduce
- Create a project
- To lakefile add:
script myScript do
IO.println __dir__
return 0
- From the package's root, run:
lake run myScript - From a subdirectory run
lake run -d=.. myScript - From the same subdirectory run
lake run -R -d=.. myScript
Expected behavior:
Output contains paths to the package's directory.
Actual behavior:
Second path is invalid (it is a relative path, that is correct only when starting from the package's root).
Third path is valid, because -R triggers re-elaboration.
Versions
"4.18.0-rc1"
Linux 6.12.6-100.fc40.x86_64
Additional Information
I think it can be fixed by using IO.FS.realPath in Lake.DSL.elabDirConst.
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.