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 3 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
14 changes: 9 additions & 5 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ function build_versions(ctx::Context, uuids::Vector{UUID}; verbose=false)

fancyprint && show_progress(ctx.io, bar)

sandbox(ctx, pkg, source_path, builddir(source_path), build_project_override) do
sandbox(ctx, pkg, source_path, builddir(source_path), build_project_override, false) do
flush(stdout)
ok = open(log_file, "w") do log
std = verbose ? ctx.io : log
Expand Down Expand Up @@ -1389,7 +1389,7 @@ end

# ctx + pkg used to compute parent dep graph
function sandbox(fn::Function, ctx::Context, target::PackageSpec, target_path::String,
sandbox_path::String, sandbox_project_override)
sandbox_path::String, sandbox_project_override, allow_autoprecomp::Bool)
active_manifest = manifestfile_path(dirname(ctx.env.project_file))
sandbox_project = projectfile_path(sandbox_path)

Expand Down Expand Up @@ -1429,6 +1429,7 @@ function sandbox(fn::Function, ctx::Context, target::PackageSpec, target_path::S
# sandbox
with_temp_env(tmp) do
temp_ctx = Context()
original_io = ctx.io
temp_ctx.env.project.deps[target.name] = target.uuid

try
Expand All @@ -1451,6 +1452,9 @@ function sandbox(fn::Function, ctx::Context, target::PackageSpec, target_path::S
end
write_env(temp_ctx.env, update_undo = false)

temp_ctx.io = original_io # restore given resolve step suppresses io
allow_autoprecomp && Pkg._auto_precompile(temp_ctx)
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved

# Run sandboxed code
path_sep = Sys.iswindows() ? ';' : ':'
withenv(fn, "JULIA_LOAD_PATH" => "@$(path_sep)$(tmp)", "JULIA_PROJECT" => nothing)
Expand Down Expand Up @@ -1532,8 +1536,8 @@ testdir(source_path::String) = joinpath(source_path, "test")
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)
test_fn=nothing, allow_autoprecomp::Bool=true)
Pkg.instantiate(ctx; allow_autoprecomp = false) # do precomp later within sandbox

# load manifest data
for pkg in pkgs
Expand Down Expand Up @@ -1568,7 +1572,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
gen_target_project(ctx.env, ctx.registries, pkg, source_path, "test")
# now we sandbox
printpkgstyle(ctx.io, :Testing, pkg.name)
sandbox(ctx, pkg, source_path, testdir(source_path), test_project_override) do
sandbox(ctx, pkg, source_path, testdir(source_path), test_project_override, allow_autoprecomp) do
test_fn !== nothing && test_fn()
status(Context(); mode=PKGMODE_COMBINED)
printpkgstyle(ctx.io, :Testing, "Running tests...")
Expand Down
7 changes: 7 additions & 0 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ const update = API.up
- `coverage::Bool=false`: enable or disable generation of coverage statistics.
- `julia_args::Union{Cmd, Vector{String}}`: options to be passed the test process.
- `test_args::Union{Cmd, Vector{String}}`: test arguments (`ARGS`) available in the test process.
- `allow_autoprecomp::Bool=true`: allow auto-precompilation to be done in test environment, if not disabled globally
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved

!!! compat "Julia 1.3"
`julia_args` and `test_args` requires at least Julia 1.3.
Expand Down Expand Up @@ -596,6 +597,12 @@ end
# Precompilation #
##################

function _auto_precompile(ctx::Types.Context)
if parse(Int, get(ENV, "JULIA_PKG_PRECOMPILE_AUTO", "1")) == 1
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
Pkg.precompile(ctx; internal_call=true)
end
end

using LibGit2: LibGit2
function _run_precompilation_script_setup()
tmp = mktempdir()
Expand Down