Skip to content

Commit

Permalink
Propagate preferences to .pkg/select_artifacts.jl
Browse files Browse the repository at this point in the history
Co-authored-by: Elliot Saba <[email protected]>
  • Loading branch information
vchuravy and staticfloat committed Jan 6, 2022
1 parent 66c13e8 commit 9e770ea
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
9 changes: 6 additions & 3 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,10 @@ function collect_artifacts(pkg_root::String; platform::AbstractPlatform=HostPlat

# If there is a dynamic artifact selector, run that in an appropriate sandbox to select artifacts
if isfile(selector_path)
select_cmd = Cmd(`$(gen_build_code(selector_path)) $(triplet(platform))`)
addenv(select_cmd, "JULIA_LOAD_PATH" => "@stdlib")
# Despite the fact that we inherit the project, since the in-memory manifest
# has not been updated yet, if we try to load any dependencies, it may fail.
# Therefore, this project inheritance is really only for Preferences, not dependencies.
select_cmd = Cmd(`$(gen_build_code(selector_path; inherit_project=true)) $(triplet(platform))`)
meta_toml = String(read(select_cmd))
push!(artifacts_tomls, (artifacts_toml, TOML.parse(meta_toml)))
else
Expand Down Expand Up @@ -878,7 +880,7 @@ function dependency_order_uuids(env::EnvCache, uuids::Vector{UUID})::Dict{UUID,I
return order
end

function gen_build_code(build_file::String)
function gen_build_code(build_file::String; inherit_project::Bool = false)
code = """
$(Base.load_path_setup_code(false))
cd($(repr(dirname(build_file))))
Expand All @@ -888,6 +890,7 @@ function gen_build_code(build_file::String)
$(Base.julia_cmd()) -O0 --color=no --history-file=no
--startup-file=$(Base.JLOptions().startupfile == 1 ? "yes" : "no")
--compiled-modules=$(Bool(Base.JLOptions().use_compiled_modules) ? "yes" : "no")
$(inherit_project ? "--project=$(Base.active_project())" : "")
--eval $code
```
end
Expand Down
60 changes: 36 additions & 24 deletions test/artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ end
end
end

using Preferences
@testset "Artifact Usage" begin
# Don't use `temp_pkg_dir()` here because we need `Pkg.test()` to run in the
# same package context as the one we're running in right now. Yes, this pollutes
Expand Down Expand Up @@ -426,11 +427,16 @@ end
wrong_hash = engaged_hash
end

withenv("FLOOBLECRANK" => flooblecrank_status) do
add_this_pkg()
@test isdir(artifact_path(right_hash))
@test !isdir(artifact_path(wrong_hash))
end
# Set the flooblecrank via its preference
set_preferences!(
joinpath(ap_path, "LocalPreferences.toml"),
"AugmentedPlatform",
"flooblecrank" => flooblecrank_status,
)

add_this_pkg()
@test isdir(artifact_path(right_hash))
@test !isdir(artifact_path(wrong_hash))

# Manual test that artifact is installed by instantiate()
artifacts_toml = joinpath(ap_path, "Artifacts.toml")
Expand Down Expand Up @@ -465,16 +471,19 @@ end
Pkg.activate(ap_path)
@test !isdir(artifact_path(engaged_hash))
@test !isdir(artifact_path(disengaged_hash))

# Set the flooblecrank via its preference
set_preferences!(
joinpath(ap_path, "LocalPreferences.toml"),
"AugmentedPlatform",
"flooblecrank" => "disengaged",
)

# Instantiate with the environment variable set, but with an explicit
# tag set in the platform object, which overrides.
withenv("FLOOBLECRANK" => "disengaged") do
p = HostPlatform()
p["flooblecrank"] = "engaged"
add_this_pkg(; platform=p)
@test isdir(artifact_path(engaged_hash))
@test !isdir(artifact_path(disengaged_hash))
end
p = HostPlatform()
p["flooblecrank"] = "engaged"
add_this_pkg(; platform=p)
@test isdir(artifact_path(engaged_hash))
@test !isdir(artifact_path(disengaged_hash))
end

# Also run a test of "cross-installation" use `Pkg.API.instantiate(;platform)`
Expand All @@ -487,18 +496,21 @@ end
@test !isdir(artifact_path(engaged_hash))
@test !isdir(artifact_path(disengaged_hash))

# Instantiate with the environment variable set, but with an explicit
# tag set in the platform object, which overrides.
withenv("FLOOBLECRANK" => "disengaged") do
add_this_pkg()
# Set the flooblecrank via its preference
set_preferences!(
joinpath(ap_path, "LocalPreferences.toml"),
"AugmentedPlatform",
"flooblecrank" => "disengaged",
)

p = HostPlatform()
p["flooblecrank"] = "engaged"
Pkg.API.instantiate(; platform=p)
add_this_pkg()

@test isdir(artifact_path(engaged_hash))
@test isdir(artifact_path(disengaged_hash))
end
p = HostPlatform()
p["flooblecrank"] = "engaged"
Pkg.API.instantiate(; platform=p)

@test isdir(artifact_path(engaged_hash))
@test isdir(artifact_path(disengaged_hash))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ function augment_platform!(p::Platform)
return p
end

# If the tag is not set, autodetect through magic (in this case, checking environment variables)
flooblecrank_status = get(ENV, "FLOOBLECRANK", "disengaged")
# If the tag is not set, autodetect through magic (in this case, checking preferences)
ap_uuid = Base.UUID("4d5b37cf-bcfd-af76-759b-4d98ee7f9293")
flooblecrank_status = get(Base.get_preferences(ap_uuid), "flooblecrank", "disengaged")
if flooblecrank_status == "engaged"
p["flooblecrank"] = "engaged"
else
Expand Down

0 comments on commit 9e770ea

Please sign in to comment.