diff --git a/src/Operations.jl b/src/Operations.jl index 64b19de9cc..47fd80febf 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -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 @@ -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)))) @@ -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 diff --git a/test/artifacts.jl b/test/artifacts.jl index 0ac6b48680..92f2a3c0da 100644 --- a/test/artifacts.jl +++ b/test/artifacts.jl @@ -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 @@ -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") @@ -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)` @@ -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 diff --git a/test/test_packages/AugmentedPlatform/.pkg/platform_augmentation.jl b/test/test_packages/AugmentedPlatform/.pkg/platform_augmentation.jl index 0f11221d49..043eda4a5b 100644 --- a/test/test_packages/AugmentedPlatform/.pkg/platform_augmentation.jl +++ b/test/test_packages/AugmentedPlatform/.pkg/platform_augmentation.jl @@ -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