Skip to content

Commit 88629b5

Browse files
Disallow precompiling Pkg in Pkg tests (#4176)
1 parent 8a88709 commit 88629b5

File tree

7 files changed

+34
-19
lines changed

7 files changed

+34
-19
lines changed

ext/REPLExt/REPLExt.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module REPLExt
22

3+
if Base.get_bool_env("JULIA_PKG_DISALLOW_PKG_PRECOMPILATION", false) == true
4+
error("Precompililing Pkg extension REPLExt is disallowed. JULIA_PKG_DISALLOW_PKG_PRECOMPILATION=$(ENV["JULIA_PKG_DISALLOW_PKG_PRECOMPILATION"])")
5+
end
6+
37
using Markdown, UUIDs, Dates
48

59
import REPL

src/Pkg.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
module Pkg
44

5+
# In Pkg tests we want to avoid Pkg being re-precompiled by subprocesses, so this is enabled in the test suite
6+
if Base.get_bool_env("JULIA_PKG_DISALLOW_PKG_PRECOMPILATION", false) == true
7+
error("Precompililing Pkg is disallowed. JULIA_PKG_DISALLOW_PKG_PRECOMPILATION=$(ENV["JULIA_PKG_DISALLOW_PKG_PRECOMPILATION"])")
8+
end
9+
510
if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_methods"))
611
@eval Base.Experimental.@max_methods 1
712
end

test/new.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,6 @@ Pkg._auto_gc_enabled[] = false
141141
end
142142
end
143143

144-
function copy_this_pkg_cache(new_depot)
145-
source = joinpath(Base.DEPOT_PATH[1], "compiled", "v$(VERSION.major).$(VERSION.minor)", "Pkg")
146-
isdir(source) || return # doesn't exist if using shipped Pkg (e.g. Julia CI)
147-
dest = joinpath(new_depot, "compiled", "v$(VERSION.major).$(VERSION.minor)", "Pkg")
148-
mkpath(dirname(dest))
149-
cp(source, dest)
150-
end
151-
152144
function kill_with_info(p)
153145
if Sys.islinux()
154146
SIGINFO = 10

test/pkg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ temp_pkg_dir() do project_path
401401
Sys.CPU_THREADS == 1 && error("Cannot test for atomic usage log file interaction effectively with only Sys.CPU_THREADS=1")
402402
# Precompile Pkg given we're in a different depot
403403
# and make sure the General registry is installed
404-
Utils.show_output_if_command_errors(`$(Base.julia_cmd()[1]) --project="$(pkgdir(Pkg))" -e "import Pkg; isempty(Pkg.Registry.reachable_registries()) && Pkg.Registry.add()"`)
404+
Utils.show_output_if_command_errors(`$(Base.julia_cmd()) --project="$(pkgdir(Pkg))" -e "import Pkg; isempty(Pkg.Registry.reachable_registries()) && Pkg.Registry.add()"`)
405405
flag_start_dir = tempdir() # once n=Sys.CPU_THREADS files are in here, the processes can proceed to the concurrent test
406406
flag_end_file = tempname() # use creating this file as a way to stop the processes early if an error happens
407407
for i in 1:Sys.CPU_THREADS
408408
iob = IOBuffer()
409-
t = @async run(pipeline(`$(Base.julia_cmd()[1]) --project="$(pkgdir(Pkg))"
409+
t = @async run(pipeline(`$(Base.julia_cmd()) --project="$(pkgdir(Pkg))"
410410
-e "import Pkg;
411411
Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true;
412412
Pkg.activate(temp = true);

test/repl.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -735,14 +735,16 @@ end
735735
end
736736

737737
@testset "JuliaLang/julia #55850" begin
738-
tmp_55850 = mktempdir()
739-
tmp_sym_link = joinpath(tmp_55850, "sym")
740-
symlink(tmp_55850, tmp_sym_link; dir_target=true)
741-
depot_path = join([tmp_sym_link, Base.DEPOT_PATH...], Sys.iswindows() ? ";" : ":")
742-
# include the symlink in the depot path and include the regular default depot so we don't precompile this Pkg again
743-
withenv("JULIA_DEPOT_PATH" => depot_path, "JULIA_LOAD_PATH" => nothing) do
744-
prompt = readchomp(`$(Base.julia_cmd()[1]) --project=$(dirname(@__DIR__)) --startup-file=no -e "using Pkg, REPL; Pkg.activate(io=devnull); REPLExt = Base.get_extension(Pkg, :REPLExt); print(REPLExt.promptf())"`)
745-
@test prompt == "(@v$(VERSION.major).$(VERSION.minor)) pkg> "
738+
mktempdir() do tmp
739+
copy_this_pkg_cache(tmp)
740+
tmp_sym_link = joinpath(tmp, "sym")
741+
symlink(tmp, tmp_sym_link; dir_target=true)
742+
depot_path = tmp_sym_link * (Sys.iswindows() ? ";" : ":")
743+
# include the symlink in the depot path and include the regular default depot so we don't precompile this Pkg again
744+
withenv("JULIA_DEPOT_PATH" => depot_path, "JULIA_LOAD_PATH" => nothing) do
745+
prompt = readchomp(`$(Base.julia_cmd()) --project=$(dirname(@__DIR__)) --startup-file=no -e "using Pkg, REPL; Pkg.activate(io=devnull); REPLExt = Base.get_extension(Pkg, :REPLExt); print(REPLExt.promptf())"`)
746+
@test prompt == "(@v$(VERSION.major).$(VERSION.minor)) pkg> "
747+
end
746748
end
747749
end
748750

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ if realpath(dirname(dirname(Base.pathof(Pkg)))) != realpath(dirname(@__DIR__))
2020
end
2121

2222
ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0
23+
ENV["JULIA_PKG_DISALLOW_PKG_PRECOMPILATION"]=1
2324

2425
logdir = get(ENV, "JULIA_TEST_VERBOSE_LOGS_DIR", nothing)
2526
### Send all Pkg output to a file called Pkg.log

test/utils.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using UUIDs
1111
export temp_pkg_dir, cd_tempdir, isinstalled, write_build, with_current_env,
1212
with_temp_env, with_pkg_env, git_init_and_commit, copy_test_package,
1313
git_init_package, add_this_pkg, TEST_SIG, TEST_PKG, isolate, LOADED_DEPOT,
14-
list_tarball_files, recursive_rm_cov_files
14+
list_tarball_files, recursive_rm_cov_files, copy_this_pkg_cache
1515

1616
const CACHE_DIRECTORY = realpath(mktempdir(; cleanup = true))
1717

@@ -22,6 +22,17 @@ const REGISTRY_DIR = joinpath(REGISTRY_DEPOT, "registries", "General")
2222

2323
const GENERAL_UUID = UUID("23338594-aafe-5451-b93e-139f81909106")
2424

25+
function copy_this_pkg_cache(new_depot)
26+
for p in ("Pkg", "REPLExt")
27+
subdir = joinpath("compiled", "v$(VERSION.major).$(VERSION.minor)")
28+
source = joinpath(Base.DEPOT_PATH[1], subdir, p)
29+
isdir(source) || continue # doesn't exist if using shipped Pkg (e.g. Julia CI)
30+
dest = joinpath(new_depot, subdir, p)
31+
mkpath(dirname(dest))
32+
cp(source, dest)
33+
end
34+
end
35+
2536
function check_init_reg()
2637
isfile(joinpath(REGISTRY_DIR, "Registry.toml")) && return
2738
mkpath(REGISTRY_DIR)

0 commit comments

Comments
 (0)