Skip to content

Commit f6b6cb1

Browse files
author
KristofferC
committed
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
1 parent b1f8d16 commit f6b6cb1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

stdlib/Artifacts/src/Artifacts.jl

Lines changed: 7 additions & 2 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, artifact_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 artifact_path === nothing
663+
find_artifacts_toml(srcfile)
664+
else
665+
artifact_path
666+
end
662667
if artifacts_toml === nothing
663668
error(string(
664669
"Cannot locate '(Julia)Artifacts.toml' file when attempting to use artifact '",

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(Expr(:macrocall, Symbol("@artifact_str"), nothing, "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)