Skip to content

Commit eb249a6

Browse files
add Pkg.precompile(f) do for delayed precompilation
1 parent 21adc97 commit eb249a6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/API.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,13 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool
11851185
end
11861186
end
11871187

1188+
function precompile(f, args...; kwargs...)
1189+
Base.ScopedValues.@with _autoprecompilation_enabled_scoped => false begin
1190+
f()
1191+
Pkg.precompile(args...; kwargs...)
1192+
end
1193+
end
1194+
11881195
function tree_hash(repo::LibGit2.GitRepo, tree_hash::String)
11891196
try
11901197
return LibGit2.GitObject(repo, tree_hash)

src/Pkg.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ usable_io(io) = (io isa Base.TTY) || (io isa IOContext{IO} && io.io isa Base.TTY
7272
can_fancyprint(io::IO) = (usable_io(io)) && (get(ENV, "CI", nothing) != "true")
7373

7474
_autoprecompilation_enabled::Bool = true
75-
_autoprecompilation_enabled_scoped = ScopedValue{Bool}(true)
75+
_autoprecompilation_enabled_scoped = Base.ScopedValues.ScopedValue{Bool}(true)
7676
autoprecompilation_enabled(state::Bool) = (autoprecompilation_enabled = state)
7777
function should_autoprecompile()
7878
if Base.JLOptions().use_compiled_modules == 1 &&
@@ -219,11 +219,21 @@ const add = API.add
219219
Pkg.precompile(; strict::Bool=false, timing::Bool=false)
220220
Pkg.precompile(pkg; strict::Bool=false, timing::Bool=false)
221221
Pkg.precompile(pkgs; strict::Bool=false, timing::Bool=false)
222+
Pkg.precompile(f, args...; kwargs...)
222223
223224
Precompile all or specific dependencies of the project in parallel.
224225
225226
Set `timing=true` to show the duration of the precompilation of each dependency.
226227
228+
To delay autoprecompilation of multiple Pkg actions until the end use.
229+
This may be most efficient while manipulating the environment in various ways.
230+
231+
```julia
232+
Pkg.precompile() do
233+
# Pkg actions here
234+
end
235+
```
236+
227237
!!! note
228238
Errors will only throw when precompiling the top-level dependencies, given that
229239
not all manifest dependencies may be loaded by the top-level dependencies on the given system.

0 commit comments

Comments
 (0)