Skip to content

Commit cb090a1

Browse files
Precompile: Add precomp to Pkg.test (#2335) (#2343)
* add option for `Pkg.test` to allow `Pkg.precompile` in test sandbox * fix access to _auto_precompile * restore IO after devnull * make ENV read safe * remove kwarg and move precomp to after status * rm kwarg from docstring (cherry picked from commit fe759b2)
1 parent 21f5217 commit cb090a1

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/API.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status)
7171
function $f(pkgs::Vector{PackageSpec}; kwargs...)
7272
ctx = Context()
7373
ret = $f(ctx, pkgs; kwargs...)
74-
$(f in (:add, :up, :pin, :free, :build)) && _auto_precompile(ctx)
74+
$(f in (:add, :up, :pin, :free, :build)) && Pkg._auto_precompile(ctx)
7575
return ret
7676
end
7777
$f(ctx::Context; kwargs...) = $f(ctx, PackageSpec[]; kwargs...)
@@ -897,12 +897,6 @@ function _is_stale(paths::Vector{String}, sourcepath::String)
897897
return true
898898
end
899899

900-
function _auto_precompile(ctx::Context)
901-
if parse(Int, get(ENV, "JULIA_PKG_PRECOMPILE_AUTO", "1")) == 1
902-
Pkg.precompile(ctx; internal_call=true)
903-
end
904-
end
905-
906900
function make_pkgspec(man, uuid)
907901
pkgent = man[uuid]
908902
# If we have an unusual situation such as an un-versioned package (like an stdlib that
@@ -1303,7 +1297,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
13031297
Operations.download_artifacts(ctx, [dirname(ctx.env.manifest_file)]; platform=platform, verbose=verbose)
13041298
# check if all source code and artifacts are downloaded to exit early
13051299
if Operations.is_instantiated(ctx)
1306-
allow_autoprecomp && _auto_precompile(ctx)
1300+
allow_autoprecomp && Pkg._auto_precompile(ctx)
13071301
return
13081302
end
13091303

@@ -1358,7 +1352,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
13581352
# Run build scripts
13591353
Operations.build_versions(ctx, union(UUID[pkg.uuid for pkg in new_apply], new_git); verbose=verbose)
13601354

1361-
allow_autoprecomp && _auto_precompile(ctx; kwargs...)
1355+
allow_autoprecomp && Pkg._auto_precompile(ctx; kwargs...)
13621356
end
13631357

13641358

src/Operations.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ testfile(source_path::String) = joinpath(testdir(source_path), "runtests.jl")
16061606
function test(ctx::Context, pkgs::Vector{PackageSpec};
16071607
coverage=false, julia_args::Cmd=``, test_args::Cmd=``,
16081608
test_fn=nothing)
1609-
Pkg.instantiate(ctx; allow_autoprecomp = false)
1609+
Pkg.instantiate(ctx; allow_autoprecomp = false) # do precomp later within sandbox
16101610

16111611
# load manifest data
16121612
for pkg in pkgs
@@ -1643,7 +1643,9 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
16431643
printpkgstyle(ctx, :Testing, pkg.name)
16441644
sandbox(ctx, pkg, source_path, testdir(source_path), test_project_override) do
16451645
test_fn !== nothing && test_fn()
1646-
status(Context(); mode=PKGMODE_COMBINED)
1646+
sandbox_ctx = Context()
1647+
status(sandbox_ctx; mode=PKGMODE_COMBINED)
1648+
Pkg._auto_precompile(sandbox_ctx)
16471649
printpkgstyle(ctx, :Testing, "Running tests...")
16481650
flush(stdout)
16491651
cmd = gen_test_code(testfile(source_path); coverage=coverage, julia_args=julia_args, test_args=test_args)

src/Pkg.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,12 @@ end
585585
# Precompilation #
586586
##################
587587

588+
function _auto_precompile(ctx::Types.Context)
589+
if tryparse(Int, get(ENV, "JULIA_PKG_PRECOMPILE_AUTO", "1")) == 1
590+
Pkg.precompile(ctx; internal_call=true)
591+
end
592+
end
593+
588594
using LibGit2: LibGit2
589595
function _run_precompilation_script_setup()
590596
tmp = mktempdir()

0 commit comments

Comments
 (0)