Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precompile: Add precomp to Pkg.test #2335

Merged
merged 6 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status)
Registry.download_default_registries(DEFAULT_IO[])
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...)
Expand Down Expand Up @@ -967,12 +967,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
Expand Down Expand Up @@ -1372,7 +1366,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
Operations.download_artifacts([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.env)
allow_autoprecomp && _auto_precompile(ctx)
allow_autoprecomp && Pkg._auto_precompile(ctx)
return
end

Expand Down Expand Up @@ -1427,7 +1421,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


Expand Down
6 changes: 4 additions & 2 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,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
Expand Down Expand Up @@ -1570,7 +1570,9 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
printpkgstyle(ctx.io, :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.io, :Testing, "Running tests...")
flush(stdout)
cmd = gen_test_code(testfile(source_path); coverage=coverage, julia_args=julia_args, test_args=test_args)
Expand Down
6 changes: 6 additions & 0 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,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()
Expand Down