Skip to content

Commit 152d039

Browse files
vchuravystaticfloat
andcommitted
Propagate preferences to .pkg/select_artifacts.jl
Co-authored-by: Elliot Saba <[email protected]>
1 parent d882b4e commit 152d039

File tree

3 files changed

+45
-29
lines changed

3 files changed

+45
-29
lines changed

src/Operations.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,10 @@ function collect_artifacts(pkg_root::String; platform::AbstractPlatform=HostPlat
596596

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

891-
function gen_build_code(build_file::String)
893+
function gen_build_code(build_file::String; inherit_project::Bool = false)
892894
code = """
893895
$(Base.load_path_setup_code(false))
894896
cd($(repr(dirname(build_file))))
@@ -898,6 +900,7 @@ function gen_build_code(build_file::String)
898900
$(Base.julia_cmd()) -O0 --color=no --history-file=no
899901
--startup-file=$(Base.JLOptions().startupfile == 1 ? "yes" : "no")
900902
--compiled-modules=$(Bool(Base.JLOptions().use_compiled_modules) ? "yes" : "no")
903+
$(inherit_project ? "--project=$(Base.active_project())" : "")
901904
--eval $code
902905
```
903906
end

test/artifacts.jl

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ end
310310
end
311311
end
312312

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

429-
withenv("FLOOBLECRANK" => flooblecrank_status) do
430-
add_this_pkg()
431-
@test isdir(artifact_path(right_hash))
432-
@test !isdir(artifact_path(wrong_hash))
433-
end
430+
# Set the flooblecrank via its preference
431+
set_preferences!(
432+
joinpath(ap_path, "LocalPreferences.toml"),
433+
"AugmentedPlatform",
434+
"flooblecrank" => flooblecrank_status,
435+
)
436+
437+
add_this_pkg()
438+
@test isdir(artifact_path(right_hash))
439+
@test !isdir(artifact_path(wrong_hash))
434440

435441
# Manual test that artifact is installed by instantiate()
436442
artifacts_toml = joinpath(ap_path, "Artifacts.toml")
@@ -465,16 +471,19 @@ end
465471
Pkg.activate(ap_path)
466472
@test !isdir(artifact_path(engaged_hash))
467473
@test !isdir(artifact_path(disengaged_hash))
474+
475+
# Set the flooblecrank via its preference
476+
set_preferences!(
477+
joinpath(ap_path, "LocalPreferences.toml"),
478+
"AugmentedPlatform",
479+
"flooblecrank" => "disengaged",
480+
)
468481

469-
# Instantiate with the environment variable set, but with an explicit
470-
# tag set in the platform object, which overrides.
471-
withenv("FLOOBLECRANK" => "disengaged") do
472-
p = HostPlatform()
473-
p["flooblecrank"] = "engaged"
474-
add_this_pkg(; platform=p)
475-
@test isdir(artifact_path(engaged_hash))
476-
@test !isdir(artifact_path(disengaged_hash))
477-
end
482+
p = HostPlatform()
483+
p["flooblecrank"] = "engaged"
484+
add_this_pkg(; platform=p)
485+
@test isdir(artifact_path(engaged_hash))
486+
@test !isdir(artifact_path(disengaged_hash))
478487
end
479488

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

490-
# Instantiate with the environment variable set, but with an explicit
491-
# tag set in the platform object, which overrides.
492-
withenv("FLOOBLECRANK" => "disengaged") do
493-
add_this_pkg()
499+
# Set the flooblecrank via its preference
500+
set_preferences!(
501+
joinpath(ap_path, "LocalPreferences.toml"),
502+
"AugmentedPlatform",
503+
"flooblecrank" => "disengaged",
504+
)
494505

495-
p = HostPlatform()
496-
p["flooblecrank"] = "engaged"
497-
Pkg.API.instantiate(; platform=p)
506+
add_this_pkg()
498507

499-
@test isdir(artifact_path(engaged_hash))
500-
@test isdir(artifact_path(disengaged_hash))
501-
end
508+
p = HostPlatform()
509+
p["flooblecrank"] = "engaged"
510+
Pkg.API.instantiate(; platform=p)
511+
512+
@test isdir(artifact_path(engaged_hash))
513+
@test isdir(artifact_path(disengaged_hash))
502514
end
503515
end
504516

test/test_packages/AugmentedPlatform/.pkg/platform_augmentation.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ function augment_platform!(p::Platform)
77
return p
88
end
99

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

0 commit comments

Comments
 (0)