From 595bc0428e7615dd40822947aacb209491c1ab8e Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 15 Jan 2021 14:38:10 -0500 Subject: [PATCH] Precompile: Add precomp to Pkg.test (#2335) * 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 fe759b2449b3ace291b6a5e43bd7ecff1767ff91) --- src/API.jl | 12 +++--------- src/Operations.jl | 6 ++++-- src/Pkg.jl | 6 ++++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/API.jl b/src/API.jl index 0402077aa0..64f6ec4e99 100644 --- a/src/API.jl +++ b/src/API.jl @@ -71,7 +71,7 @@ for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status) function $f(pkgs::Vector{PackageSpec}; kwargs...) ctx = Context() ret = $f(ctx, pkgs; kwargs...) - $(f in (:add, :up, :pin, :free, :build)) && _auto_precompile(ctx) + $(f in (:add, :up, :pin, :free, :build)) && Pkg._auto_precompile(ctx) return ret end $f(ctx::Context; kwargs...) = $f(ctx, PackageSpec[]; kwargs...) @@ -897,12 +897,6 @@ function _is_stale(paths::Vector{String}, sourcepath::String) return true end -function _auto_precompile(ctx::Context) - if parse(Int, get(ENV, "JULIA_PKG_PRECOMPILE_AUTO", "1")) == 1 - Pkg.precompile(ctx; internal_call=true) - end -end - function make_pkgspec(man, uuid) pkgent = man[uuid] # 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, Operations.download_artifacts(ctx, [dirname(ctx.env.manifest_file)]; platform=platform, verbose=verbose) # check if all source code and artifacts are downloaded to exit early if Operations.is_instantiated(ctx) - allow_autoprecomp && _auto_precompile(ctx) + allow_autoprecomp && Pkg._auto_precompile(ctx) return end @@ -1358,7 +1352,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing, # Run build scripts Operations.build_versions(ctx, union(UUID[pkg.uuid for pkg in new_apply], new_git); verbose=verbose) - allow_autoprecomp && _auto_precompile(ctx; kwargs...) + allow_autoprecomp && Pkg._auto_precompile(ctx; kwargs...) end diff --git a/src/Operations.jl b/src/Operations.jl index 353aea8c20..dfe595b9dc 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -1606,7 +1606,7 @@ testfile(source_path::String) = joinpath(testdir(source_path), "runtests.jl") function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false, julia_args::Cmd=``, test_args::Cmd=``, test_fn=nothing) - Pkg.instantiate(ctx; allow_autoprecomp = false) + Pkg.instantiate(ctx; allow_autoprecomp = false) # do precomp later within sandbox # load manifest data for pkg in pkgs @@ -1643,7 +1643,9 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; printpkgstyle(ctx, :Testing, pkg.name) sandbox(ctx, pkg, source_path, testdir(source_path), test_project_override) do test_fn !== nothing && test_fn() - status(Context(); mode=PKGMODE_COMBINED) + sandbox_ctx = Context() + status(sandbox_ctx; mode=PKGMODE_COMBINED) + Pkg._auto_precompile(sandbox_ctx) printpkgstyle(ctx, :Testing, "Running tests...") flush(stdout) cmd = gen_test_code(testfile(source_path); coverage=coverage, julia_args=julia_args, test_args=test_args) diff --git a/src/Pkg.jl b/src/Pkg.jl index 923ecdc408..18792adaec 100644 --- a/src/Pkg.jl +++ b/src/Pkg.jl @@ -585,6 +585,12 @@ end # Precompilation # ################## +function _auto_precompile(ctx::Types.Context) + if tryparse(Int, get(ENV, "JULIA_PKG_PRECOMPILE_AUTO", "1")) == 1 + Pkg.precompile(ctx; internal_call=true) + end +end + using LibGit2: LibGit2 function _run_precompilation_script_setup() tmp = mktempdir()