Skip to content

Commit 1fcfa41

Browse files
committed
tweak how filtering is done for what packages should be precompiled
1 parent a931fbe commit 1fcfa41

File tree

1 file changed

+37
-47
lines changed

1 file changed

+37
-47
lines changed

base/precompilation.jl

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,44 @@ function precompilepkgs(pkgs::Vector{String}=String[];
389389
Base.PkgId(uuid, name)
390390
for (name, uuid) in env.project_deps if !Base.in_sysimage(Base.PkgId(uuid, name))
391391
]
392+
393+
if manifest
394+
keep = Set(keys(env.deps))
395+
target = "manifest"
396+
else
397+
if isempty(pkgs)
398+
pkgs = [pkg.name for pkg in direct_deps]
399+
target = "all packages"
400+
else
401+
target = join(pkgs, ", ")
402+
end
403+
404+
# restrict to dependencies of given packages
405+
function collect_all_deps(pkg::UUID, keep::Set{UUID}, indent = 1)
406+
for _dep in env.deps[pkg]
407+
if !(_dep in keep)
408+
push!(keep, _dep)
409+
collect_all_deps(_dep, keep, indent + 2)
410+
end
411+
end
412+
end
413+
414+
keep = Set{UUID}()
415+
for pkg in pkgs
416+
pkg_uuid = env.project_deps[pkg]
417+
push!(keep, pkg_uuid)
418+
collect_all_deps(pkg_uuid, keep)
419+
end
420+
end
421+
392422
stale_cache = Dict{StaleCacheKey, Bool}()
393423
exts = Dict{Base.PkgId, String}() # ext -> parent
394424
# make a flat map of each dep and its direct deps
395425
depsmap = Dict{Base.PkgId, Vector{Base.PkgId}}()
396426
pkg_exts_map = Dict{Base.PkgId, Vector{Base.PkgId}}()
397427

398428
for (dep, deps) in env.deps
429+
dep in keep || continue
399430
pkg = Base.PkgId(dep, env.names[dep])
400431
Base.in_sysimage(pkg) && continue
401432
deps = [Base.PkgId(x, env.names[x]) for x in deps]
@@ -408,6 +439,10 @@ function precompilepkgs(pkgs::Vector{String}=String[];
408439
push!(ext_deps, pkg) # depends on parent package
409440
all_extdeps_available = true
410441
for extdep_uuid in extdep_uuids
442+
if !(extdep_uuid in keep)
443+
all_extdeps_available = false
444+
break
445+
end
411446
extdep_name = env.names[extdep_uuid]
412447
if extdep_uuid in keys(env.deps) || Base.in_sysimage(Base.PkgId(extdep_uuid, extdep_name))
413448
push!(ext_deps, Base.PkgId(extdep_uuid, extdep_name))
@@ -448,8 +483,8 @@ function precompilepkgs(pkgs::Vector{String}=String[];
448483
end
449484
@debug "precompile: extensions collected"
450485

451-
# return early if no deps
452-
if isempty(depsmap)
486+
# return early if no deps
487+
if isempty(depsmap)
453488
if isempty(pkgs)
454489
return
455490
elseif _from_loading
@@ -517,51 +552,6 @@ function precompilepkgs(pkgs::Vector{String}=String[];
517552
end
518553
@debug "precompile: circular dep check done"
519554

520-
if !manifest
521-
if isempty(pkgs)
522-
pkgs = [pkg.name for pkg in direct_deps]
523-
target = "all packages"
524-
else
525-
target = join(pkgs, ", ")
526-
end
527-
# restrict to dependencies of given packages
528-
function collect_all_deps(depsmap, dep, alldeps=Set{Base.PkgId}())
529-
for _dep in depsmap[dep]
530-
if !(_dep in alldeps)
531-
push!(alldeps, _dep)
532-
collect_all_deps(depsmap, _dep, alldeps)
533-
end
534-
end
535-
return alldeps
536-
end
537-
keep = Set{Base.PkgId}()
538-
for dep in depsmap
539-
dep_pkgid = first(dep)
540-
if dep_pkgid.name in pkgs
541-
push!(keep, dep_pkgid)
542-
collect_all_deps(depsmap, dep_pkgid, keep)
543-
end
544-
end
545-
for ext in keys(exts)
546-
if issubset(collect_all_deps(depsmap, ext), keep) # if all extension deps are kept
547-
push!(keep, ext)
548-
end
549-
end
550-
filter!(d->in(first(d), keep), depsmap)
551-
if isempty(depsmap)
552-
if _from_loading
553-
# if called from loading precompilation it may be a package from another environment stack so
554-
# don't error and allow serial precompilation to try
555-
# TODO: actually handle packages from other envs in the stack
556-
return
557-
else
558-
return
559-
end
560-
end
561-
else
562-
target = "manifest"
563-
end
564-
565555
nconfigs = length(configs)
566556
if nconfigs == 1
567557
if !isempty(only(configs)[1])

0 commit comments

Comments
 (0)