Skip to content

Commit 1720a54

Browse files
allow artifact string macro to take an explicit path to the artifact file (#46755)
* allow artifact string macro to take an explicit path can be used by JLLs to avoid scour throgh the file system for the Artifacts.toml when it already knows where it is * address review comments * Fix `@artifact_str` invocation We must provide the `platform` argument here before we provide the `artifacts_toml_path` argument. * Catch quoted `nothing` values as well Co-authored-by: Elliot Saba <[email protected]>
1 parent dccf331 commit 1720a54

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

stdlib/Artifacts/src/Artifacts.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,18 @@ access a single file/directory within an artifact. Example:
652652
!!! compat "Julia 1.6"
653653
Slash-indexing requires at least Julia 1.6.
654654
"""
655-
macro artifact_str(name, platform=nothing)
655+
macro artifact_str(name, platform=nothing, artifacts_toml_path=nothing)
656656
# Find Artifacts.toml file we're going to load from
657657
srcfile = string(__source__.file)
658658
if ((isinteractive() && startswith(srcfile, "REPL[")) || (!isinteractive() && srcfile == "none")) && !isfile(srcfile)
659659
srcfile = pwd()
660660
end
661-
local artifacts_toml = find_artifacts_toml(srcfile)
661+
# Sometimes we know the exact path to the Artifacts.toml file, so we can save some lookups
662+
local artifacts_toml = if artifacts_toml_path === nothing || artifacts_toml_path == :(nothing)
663+
find_artifacts_toml(srcfile)
664+
else
665+
eval(artifacts_toml_path)
666+
end
662667
if artifacts_toml === nothing
663668
error(string(
664669
"Cannot locate '(Julia)Artifacts.toml' file when attempting to use artifact '",
@@ -688,7 +693,7 @@ macro artifact_str(name, platform=nothing)
688693

689694
# If `name` is a constant, (and we're using the default `Platform`) we can actually load
690695
# and parse the `Artifacts.toml` file now, saving the work from runtime.
691-
if isa(name, AbstractString) && platform === nothing
696+
if isa(name, AbstractString) && (platform === nothing || platform == :(nothing))
692697
# To support slash-indexing, we need to split the artifact name from the path tail:
693698
platform = HostPlatform()
694699
artifact_name, artifact_path_tail, hash = artifact_slash_lookup(name, artifact_dict, artifacts_toml, platform)

stdlib/Artifacts/test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ end
9191
HelloWorldC_exe_path = joinpath(HelloWorldC_dir, "bin", "hello_world$(exeext)")
9292
@test isfile(HelloWorldC_exe_path)
9393

94+
HelloWorldC_dir_explicit_artifact = eval(:(@artifact_str "HelloWorldC" nothing joinpath(@__DIR__, "Artifacts.toml")))
95+
@test isdir(HelloWorldC_dir_explicit_artifact)
96+
9497
# Simple slash-indexed lookup
9598
HelloWorldC_bin_path = artifact"HelloWorldC/bin"
9699
@test isdir(HelloWorldC_bin_path)

0 commit comments

Comments
 (0)