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

Some uses of @__DIR__ should be relocatable. #54430

Open
gbaraldi opened this issue May 10, 2024 · 6 comments · May be fixed by #55146 or #56053
Open

Some uses of @__DIR__ should be relocatable. #54430

gbaraldi opened this issue May 10, 2024 · 6 comments · May be fixed by #55146 or #56053

Comments

@gbaraldi
Copy link
Member

gbaraldi commented May 10, 2024

The proposed use I have for this is for when packages are looking for their Artifacts.toml file, they have to annoying things, and non relocatable ones even more annyoingly. (Maybe we need to add something like @__PKGDIR that does the relocatable thing)

Currently @__DIR__ bakes in the current path of the whenever it's called, but for this it's usually the path of the src directory of a package. Examples of this are the Artifacts.toml file or a examples/directory, The issue arises if one tries to move that package to another place, either via PkgCompiler or via copying the depot around. Those baked in absolute paths mean that it's not safe for this package to be relocatable.

I don't have a clear proposal for this, but I imagine it would just be a expansion of the relocatable package image work done by @fatteneder, specially since if you get the package those files are already there, we just don't have a nice way of getting to them.

@gbaraldi gbaraldi changed the title Making some uses of @__DIR__ relocatable Some uses of @__DIR__ should be relocatable. May 10, 2024
@topolarity
Copy link
Member

I agree with @gbaraldi that this is a serious limitation. It means that most uses of @__DIR__ cause your package to become immediately non-relocatable.

There are two common exceptions that are relocatable:

  • the @__DIR__ path is used to access files entirely at parse-time / compile-time - e.g. JLL's do this:
    # Load Artifacts.toml at compile time, so that we don't have to use `__source__.file`
    # at runtime, which gets stale if the `.ji` file is relocated.
    local artifact_dict = load_artifacts_toml(artifacts_toml)
  • the @__DIR__ path is never used to open/write any files at all (just printing/logging) - @error does this

#53906 added a Base.isrelocatable predicate, but it is not able to detect this problem.

@topolarity
Copy link
Member

The issue arises if one tries to move that package to another place, either via PkgCompiler or via copying the depot around.

There are more challenges for PackageCompiler.jl too.

It deletes any source files from its relocated "depot". So even if this is relocatable, it would need to have a way to detect a dependency on package source so that it can copy those files to make this work.

@KristofferC
Copy link
Member

https://github.com/JuliaPackaging/RelocatableFolders.jl is a bit of a "hack" to work around this.

@fatteneder
Copy link
Member

fatteneder commented May 10, 2024

FWIW Pkg.jl best practices already mention that one should not assume a package to be located in a stable location. So this rules out the use of the current @__DIR__ for pkg code.

@KristofferC
Copy link
Member

What should be done for this issue to be solved? It seems to lack a clear goal right now.

@fatteneder
Copy link
Member

fatteneder commented May 29, 2024

I personally would not bother with making uses of @__DIR__ relocatable. I have used things like normpath(joinpath(@__DIR__, <some relative path>)) myself before, and I tinkering with @__DIR__ would only break those uses.

Instead I would add another macro, something like @__PKGDIR__ as suggested by Gabriel initially.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants