Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change @__FILE__, @__DIR__, etc. to give right runtime answer #38682

Closed
StefanKarpinski opened this issue Dec 3, 2020 · 6 comments
Closed

change @__FILE__, @__DIR__, etc. to give right runtime answer #38682

StefanKarpinski opened this issue Dec 3, 2020 · 6 comments
Labels
minor change Marginal behavior change acceptable for a minor release

Comments

@StefanKarpinski
Copy link
Member

Currently these macros are expanded at build time to an absolute path based on the source location at build time. This means that any use of them in precompilable packages causes the resulting .ji files to be non-relocatable. It also means that any use of them in a stdlib will break the resulting Julia sysimg by causing it to be non-relocatable. I would propose that instead of expanding to a static path, these macros be changed to expand to code that will give the correct path at runtime. This is a technically breaking change, but I suspect that 99% of uses won't notice and changing this will silently make people's code do what they thought it was doing already.

@StefanKarpinski StefanKarpinski added minor change Marginal behavior change acceptable for a minor release triage This should be discussed on a triage call labels Dec 3, 2020
@KristofferC
Copy link
Member

This means that any use of them in precompilable packages causes the resulting .ji files to be non-relocatable.

FWIW, if they use @__DIR__ at runtime they are likely to be non-relocatable anyway since if you transfer something as a sysimage or .ji file, it is unlikely the original files exist anyway.

@StefanKarpinski
Copy link
Member Author

True, but pathof and pkgdir at least give a somewhat correct answer at runtime. Maybe there's just no way to do this correctly if we anticipate that packages might be loaded directly from .ji files with the source files gone.

@KristofferC
Copy link
Member

pathof and pkgdir also "freeze" but instead of when the package is precompiled it is when the package is loaded. So if you put them in a sysimage, those will also give the old values.

@vtjnash
Copy link
Member

vtjnash commented Jun 3, 2021

Perhaps we could reserve a special path representation to represent a pkgdir in a path, which becomes an absolute path when calling realpath or expanduser, such as @NetworkOptions/data/config.toml

But closing in favor of #38696, which seems slightly less speculative and relatively straightforward

@vtjnash vtjnash closed this as completed Jun 3, 2021
@JeffBezanson JeffBezanson removed the triage This should be discussed on a triage call label Jul 1, 2021
@omus
Copy link
Member

omus commented Dec 21, 2024

As this is the only issue to mention both pkgdir and "sysimage" I just wanted to mention that the following code works better in sysimages that are relocated:

pkg = Base.identify_package(...)
pkg_dir = dirname(dirname(Base.locate_package(pkg)))  # Naive logic here, could be improved for extensions

This was used in JuliaTime/TimeZones.jl#479 as a work around

@DilumAluthge
Copy link
Member

The best long-term solution is probably something like #56053

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor change Marginal behavior change acceptable for a minor release
Projects
None yet
Development

No branches or pull requests

6 participants