Skip to content

Commit 6d16f7b

Browse files
add Pkg.precompile(f) do for delayed precompilation
1 parent 36959ee commit 6d16f7b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/API.jl

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

1179+
function precompile(f, args...; kwargs...)
1180+
@with _autoprecompilation_enabled_scoped => false begin
1181+
f()
1182+
Pkg.precompile(args...; kwargs...)
1183+
end
1184+
end
1185+
11791186
function tree_hash(repo::LibGit2.GitRepo, tree_hash::String)
11801187
try
11811188
return LibGit2.GitObject(repo, tree_hash)

src/Pkg.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,21 @@ const add = API.add
204204
Pkg.precompile(; strict::Bool=false, timing::Bool=false)
205205
Pkg.precompile(pkg; strict::Bool=false, timing::Bool=false)
206206
Pkg.precompile(pkgs; strict::Bool=false, timing::Bool=false)
207+
Pkg.precompile(f, args...; kwargs...)
207208
208209
Precompile all or specific dependencies of the project in parallel.
209210
210211
Set `timing=true` to show the duration of the precompilation of each dependency.
211212
213+
To delay autoprecompilation of multiple Pkg actions until the end use.
214+
This may be most efficient while manipulating the environment in various ways.
215+
216+
```julia
217+
Pkg.precompile() do
218+
# Pkg actions here
219+
end
220+
```
221+
212222
!!! note
213223
Errors will only throw when precompiling the top-level dependencies, given that
214224
not all manifest dependencies may be loaded by the top-level dependencies on the given system.

0 commit comments

Comments
 (0)