Skip to content

Commit 54946b0

Browse files
authored
Merge pull request #37592 from JuliaLang/sf/artifacts_with_pkg
2 parents f45c799 + c4226dd commit 54946b0

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

contrib/generate_precompile.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ Artifacts = get(Base.loaded_modules,
8181
nothing)
8282
if Artifacts !== nothing
8383
precompile_script *= """
84-
using Artifacts, Base.BinaryPlatforms
85-
artifacts_toml = abspath($(repr(joinpath(Sys.STDLIB, "Artifacts", "test", "Artifacts.toml"))))
84+
using Artifacts, Base.BinaryPlatforms, Libdl
85+
artifacts_toml = abspath(joinpath(Sys.STDLIB, "Artifacts", "test", "Artifacts.toml"))
8686
cd(() -> @artifact_str("c_simple"), dirname(artifacts_toml))
8787
artifacts = Artifacts.load_artifacts_toml(artifacts_toml)
8888
platforms = [Artifacts.unpack_platform(e, "c_simple", artifacts_toml) for e in artifacts["c_simple"]]
8989
best_platform = select_platform(Dict(p => triplet(p) for p in platforms))
90+
dlopen("libjulia", RTLD_LAZY | RTLD_DEEPBIND)
9091
"""
9192
end
9293

doc/make.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ DocMeta.setdocmeta!(SparseArrays, :DocTestSetup, :(using SparseArrays, LinearAlg
181181
DocMeta.setdocmeta!(SuiteSparse, :DocTestSetup, :(using SparseArrays, LinearAlgebra, SuiteSparse), recursive=true, warn=false)
182182
DocMeta.setdocmeta!(UUIDs, :DocTestSetup, :(using UUIDs, Random), recursive=true, warn=false)
183183
DocMeta.setdocmeta!(Pkg, :DocTestSetup, :(using Pkg, Pkg.Artifacts), recursive=true, warn=false)
184-
DocMeta.setdocmeta!(Pkg.BinaryPlatforms, :DocTestSetup, :(using Pkg, Pkg.BinaryPlatforms), recursive=true, warn=false)
185184
DocMeta.setdocmeta!(Base.BinaryPlatforms, :DocTestSetup, :(using Base.BinaryPlatforms), recursive=true, warn=false)
186185

187186
let r = r"buildroot=(.+)", i = findfirst(x -> occursin(r, x), ARGS)

stdlib/Artifacts/src/Artifacts.jl

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ function jointail(dir, tail)
478478
end
479479
end
480480

481-
function _artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dict, hash)
481+
function _artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dict, hash, platform)
482482
if haskey(Base.module_keys, __module__)
483483
# Process overrides for this UUID, if we know what it is
484484
process_overrides(artifact_dict, Base.module_keys[__module__].uuid)
@@ -495,7 +495,7 @@ function _artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dic
495495
# If not, we need to download it. We look up the Pkg module through `Base.loaded_modules()`
496496
# then invoke `ensure_artifact_installed()`:
497497
Pkg = first(filter(p-> p[1].name == "Pkg", Base.loaded_modules))[2]
498-
return jointail(Pkg.Artifacts.ensure_artifact_installed(string(name), artifacts_toml), path_tail)
498+
return jointail(Pkg.Artifacts.ensure_artifact_installed(string(name), artifacts_toml; platform), path_tail)
499499
end
500500

501501
"""
@@ -539,16 +539,19 @@ function split_artifact_slash(name::String)
539539
end
540540

541541
"""
542-
artifact_slash_lookup(name::String, artifacts_toml::String)
542+
artifact_slash_lookup(name::String, atifact_dict::Dict,
543+
artifacts_toml::String, platform::Platform)
543544
544545
Returns `artifact_name`, `artifact_path_tail`, and `hash` by looking the results up in
545546
the given `artifacts_toml`, first extracting the name and path tail from the given `name`
546547
to support slash-indexing within the given artifact.
547548
"""
548-
function artifact_slash_lookup(name::String, artifact_dict::Dict, artifacts_toml::String)
549+
function artifact_slash_lookup(name::String, artifact_dict::Dict,
550+
artifacts_toml::String, platform::Platform)
549551
artifact_name, artifact_path_tail = split_artifact_slash(name)
550552

551-
meta = artifact_meta(artifact_name, artifact_dict, artifacts_toml)
553+
@show platform
554+
meta = artifact_meta(artifact_name, artifact_dict, artifacts_toml; platform)
552555
if meta === nothing
553556
error("Cannot locate artifact '$(name)' in '$(artifacts_toml)'")
554557
end
@@ -577,7 +580,7 @@ access a single file/directory within an artifact. Example:
577580
!!! compat "Julia 1.6"
578581
Slash-indexing requires at least Julia 1.6.
579582
"""
580-
macro artifact_str(name)
583+
macro artifact_str(name, platform=nothing)
581584
# Find Artifacts.toml file we're going to load from
582585
srcfile = string(__source__.file)
583586
if ((isinteractive() && startswith(srcfile, "REPL[")) || (!isinteractive() && srcfile == "none")) && !isfile(srcfile)
@@ -601,18 +604,23 @@ macro artifact_str(name)
601604
# Invalidate calling .ji file if Artifacts.toml file changes
602605
Base.include_dependency(artifacts_toml)
603606

604-
# If `name` is a constant, we can actually load and parse the `Artifacts.toml` file now,
605-
# saving the work from runtime.
606-
if isa(name, AbstractString)
607+
# If `name` is a constant, (and we're using the default `Platform`) we can actually load
608+
# and parse the `Artifacts.toml` file now, saving the work from runtime.
609+
if isa(name, AbstractString) && platform === nothing
607610
# To support slash-indexing, we need to split the artifact name from the path tail:
608-
local artifact_name, artifact_path_tail, hash = artifact_slash_lookup(name, artifact_dict, artifacts_toml)
611+
platform = HostPlatform()
612+
local artifact_name, artifact_path_tail, hash = artifact_slash_lookup(name, artifact_dict, artifacts_toml, platform)
609613
return quote
610-
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), $(artifact_name), $(artifact_path_tail), $(artifact_dict), $(hash))
614+
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), $(artifact_name), $(artifact_path_tail), $(artifact_dict), $(hash), $(platform))
611615
end
612616
else
617+
if platform === nothing
618+
platform = :($(HostPlatform)())
619+
end
613620
return quote
614-
local artifact_name, artifact_path_tail, hash = artifact_slash_lookup($(esc(name)), $(artifact_dict), $(artifacts_toml))
615-
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), artifact_name, artifact_path_tail, $(artifact_dict), hash)
621+
local platform = $(esc(platform))
622+
local artifact_name, artifact_path_tail, hash = artifact_slash_lookup($(esc(name)), $(artifact_dict), $(artifacts_toml), platform)
623+
Base.invokelatest(_artifact_str, $(__module__), $(artifacts_toml), artifact_name, artifact_path_tail, $(artifact_dict), hash, platform)
616624
end
617625
end
618626
end

stdlib/Artifacts/test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,14 @@ end
106106
end
107107
end
108108
end
109+
110+
@testset "@artifact_str Platform passing" begin
111+
mktempdir() do tempdir
112+
with_artifacts_directory(tempdir) do
113+
win64 = Platform("x86_64", "windows")
114+
mac64 = Platform("x86_64", "macos")
115+
@test basename(@artifact_str("c_simple", win64)) == "444cecb70ff39e8961dd33e230e151775d959f37"
116+
@test basename(@artifact_str("c_simple", mac64)) == "7ba74e239348ea6c060f994c083260be3abe3095"
117+
end
118+
end
119+
end

stdlib/Pkg.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
PKG_BRANCH = master
2-
PKG_SHA1 = 6a235eb813be335b54c97c5c7d631bdbd1059115
2+
PKG_SHA1 = c2c99807b157d6b9e23d09fa597800ec0e715cee

0 commit comments

Comments
 (0)