From 601ba06584623cf0c26569913502e7636674fdcf Mon Sep 17 00:00:00 2001 From: KristofferC Date: Wed, 14 Sep 2022 10:35:36 +0200 Subject: [PATCH 1/4] 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 --- stdlib/Artifacts/src/Artifacts.jl | 9 +++++++-- stdlib/Artifacts/test/runtests.jl | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/stdlib/Artifacts/src/Artifacts.jl b/stdlib/Artifacts/src/Artifacts.jl index 5c02803959f05..a7d512c613c83 100644 --- a/stdlib/Artifacts/src/Artifacts.jl +++ b/stdlib/Artifacts/src/Artifacts.jl @@ -652,13 +652,18 @@ access a single file/directory within an artifact. Example: !!! compat "Julia 1.6" Slash-indexing requires at least Julia 1.6. """ -macro artifact_str(name, platform=nothing) +macro artifact_str(name, platform=nothing, artifact_path=nothing) # Find Artifacts.toml file we're going to load from srcfile = string(__source__.file) if ((isinteractive() && startswith(srcfile, "REPL[")) || (!isinteractive() && srcfile == "none")) && !isfile(srcfile) srcfile = pwd() end - local artifacts_toml = find_artifacts_toml(srcfile) + # Sometimes we know the exact path to the Artifacts.toml file, so we can save some lookups + local artifacts_toml = if artifact_path === nothing + find_artifacts_toml(srcfile) + else + artifact_path + end if artifacts_toml === nothing error(string( "Cannot locate '(Julia)Artifacts.toml' file when attempting to use artifact '", diff --git a/stdlib/Artifacts/test/runtests.jl b/stdlib/Artifacts/test/runtests.jl index 67117217be549..b4b6b6d73161f 100644 --- a/stdlib/Artifacts/test/runtests.jl +++ b/stdlib/Artifacts/test/runtests.jl @@ -91,6 +91,9 @@ end HelloWorldC_exe_path = joinpath(HelloWorldC_dir, "bin", "hello_world$(exeext)") @test isfile(HelloWorldC_exe_path) + HelloWorldC_dir_explicit_artifact = eval(Expr(:macrocall, Symbol("@artifact_str"), nothing, "HelloWorldC", nothing, joinpath(@__DIR__, "Artifacts.toml"))) + @test isdir(HelloWorldC_dir_explicit_artifact) + # Simple slash-indexed lookup HelloWorldC_bin_path = artifact"HelloWorldC/bin" @test isdir(HelloWorldC_bin_path) From 05dcc5b4970f29e5ef0ae1dbee2e700ee8b23b7c Mon Sep 17 00:00:00 2001 From: KristofferC Date: Thu, 15 Sep 2022 13:07:33 +0200 Subject: [PATCH 2/4] address review comments --- stdlib/Artifacts/src/Artifacts.jl | 6 +++--- stdlib/Artifacts/test/runtests.jl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/Artifacts/src/Artifacts.jl b/stdlib/Artifacts/src/Artifacts.jl index a7d512c613c83..cf51b8efddd1d 100644 --- a/stdlib/Artifacts/src/Artifacts.jl +++ b/stdlib/Artifacts/src/Artifacts.jl @@ -652,17 +652,17 @@ access a single file/directory within an artifact. Example: !!! compat "Julia 1.6" Slash-indexing requires at least Julia 1.6. """ -macro artifact_str(name, platform=nothing, artifact_path=nothing) +macro artifact_str(name, platform=nothing, artifacts_toml_path=nothing) # Find Artifacts.toml file we're going to load from srcfile = string(__source__.file) if ((isinteractive() && startswith(srcfile, "REPL[")) || (!isinteractive() && srcfile == "none")) && !isfile(srcfile) srcfile = pwd() end # Sometimes we know the exact path to the Artifacts.toml file, so we can save some lookups - local artifacts_toml = if artifact_path === nothing + local artifacts_toml = if artifacts_toml_path === nothing find_artifacts_toml(srcfile) else - artifact_path + artifacts_toml_path end if artifacts_toml === nothing error(string( diff --git a/stdlib/Artifacts/test/runtests.jl b/stdlib/Artifacts/test/runtests.jl index b4b6b6d73161f..b6ffb43c52dc9 100644 --- a/stdlib/Artifacts/test/runtests.jl +++ b/stdlib/Artifacts/test/runtests.jl @@ -91,7 +91,7 @@ end HelloWorldC_exe_path = joinpath(HelloWorldC_dir, "bin", "hello_world$(exeext)") @test isfile(HelloWorldC_exe_path) - HelloWorldC_dir_explicit_artifact = eval(Expr(:macrocall, Symbol("@artifact_str"), nothing, "HelloWorldC", nothing, joinpath(@__DIR__, "Artifacts.toml"))) + HelloWorldC_dir_explicit_artifact = eval(:(@artifact_str "HelloWorldC" joinpath(@__DIR__, "Artifacts.toml"))) @test isdir(HelloWorldC_dir_explicit_artifact) # Simple slash-indexed lookup From 02f3df84d8ada307101c1ec63d7556b8b78795c4 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Thu, 29 Sep 2022 18:24:45 +0000 Subject: [PATCH 3/4] Fix `@artifact_str` invocation We must provide the `platform` argument here before we provide the `artifacts_toml_path` argument. --- stdlib/Artifacts/test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Artifacts/test/runtests.jl b/stdlib/Artifacts/test/runtests.jl index b6ffb43c52dc9..248d851ccad79 100644 --- a/stdlib/Artifacts/test/runtests.jl +++ b/stdlib/Artifacts/test/runtests.jl @@ -91,7 +91,7 @@ end HelloWorldC_exe_path = joinpath(HelloWorldC_dir, "bin", "hello_world$(exeext)") @test isfile(HelloWorldC_exe_path) - HelloWorldC_dir_explicit_artifact = eval(:(@artifact_str "HelloWorldC" joinpath(@__DIR__, "Artifacts.toml"))) + HelloWorldC_dir_explicit_artifact = eval(:(@artifact_str "HelloWorldC" nothing joinpath(@__DIR__, "Artifacts.toml"))) @test isdir(HelloWorldC_dir_explicit_artifact) # Simple slash-indexed lookup From 0f309bc9faa12cf12e1a1d9b5dc06259ed129fea Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Fri, 30 Sep 2022 00:14:37 +0000 Subject: [PATCH 4/4] Catch quoted `nothing` values as well --- stdlib/Artifacts/src/Artifacts.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/Artifacts/src/Artifacts.jl b/stdlib/Artifacts/src/Artifacts.jl index cf51b8efddd1d..3f1574db4c4a6 100644 --- a/stdlib/Artifacts/src/Artifacts.jl +++ b/stdlib/Artifacts/src/Artifacts.jl @@ -659,10 +659,10 @@ macro artifact_str(name, platform=nothing, artifacts_toml_path=nothing) srcfile = pwd() end # Sometimes we know the exact path to the Artifacts.toml file, so we can save some lookups - local artifacts_toml = if artifacts_toml_path === nothing + local artifacts_toml = if artifacts_toml_path === nothing || artifacts_toml_path == :(nothing) find_artifacts_toml(srcfile) else - artifacts_toml_path + eval(artifacts_toml_path) end if artifacts_toml === nothing error(string( @@ -693,7 +693,7 @@ macro artifact_str(name, platform=nothing, artifacts_toml_path=nothing) # If `name` is a constant, (and we're using the default `Platform`) we can actually load # and parse the `Artifacts.toml` file now, saving the work from runtime. - if isa(name, AbstractString) && platform === nothing + if isa(name, AbstractString) && (platform === nothing || platform == :(nothing)) # To support slash-indexing, we need to split the artifact name from the path tail: platform = HostPlatform() artifact_name, artifact_path_tail, hash = artifact_slash_lookup(name, artifact_dict, artifacts_toml, platform)