Skip to content

Commit 7d5a951

Browse files
committed
only precompile subproject specific dependencies if subproject is a package
1 parent 442bb5b commit 7d5a951

File tree

1 file changed

+60
-54
lines changed

1 file changed

+60
-54
lines changed

base/precompilation.jl

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,29 @@ function ExplicitEnv(envpath::String=Base.active_project())
5252
end
5353
end
5454

55-
base_project_file = base_project(envpath)
56-
if base_project_file !== nothing
57-
base_project_d = parsed_toml(base_project_file)
58-
for (name, _uuid) in get(Dict{String, Any}, base_project_d, "deps")::Dict{String, Any}
59-
uuid = UUID(_uuid)
60-
project_deps[name] = uuid
61-
names[UUID(uuid)] = name
62-
project_uuid_to_name[name] = UUID(uuid)
55+
# This project might be a package, in that case, that is also a "dependency"
56+
# of the project.
57+
proj_name = get(project_d, "name", nothing)::Union{String, Nothing}
58+
_proj_uuid = get(project_d, "uuid", nothing)::Union{String, Nothing}
59+
proj_uuid = _proj_uuid === nothing ? nothing : UUID(_proj_uuid)
60+
61+
project_is_package = proj_name !== nothing && proj_uuid !== nothing
62+
if project_is_package
63+
# TODO: Error on missing uuid?
64+
project_deps[proj_name] = UUID(proj_uuid)
65+
names[UUID(proj_uuid)] = proj_name
66+
end
67+
68+
if !project_is_package
69+
base_project_file = base_project(envpath)
70+
if base_project_file !== nothing
71+
base_project_d = parsed_toml(base_project_file)
72+
for (name, _uuid) in get(Dict{String, Any}, base_project_d, "deps")::Dict{String, Any}
73+
uuid = UUID(_uuid)
74+
project_deps[name] = uuid
75+
names[UUID(uuid)] = name
76+
project_uuid_to_name[name] = UUID(uuid)
77+
end
6378
end
6479
end
6580

@@ -80,18 +95,6 @@ function ExplicitEnv(envpath::String=Base.active_project())
8095
project_extensions[name] = uuids
8196
end
8297

83-
# This project might be a package, in that case, that is also a "dependency"
84-
# of the project.
85-
proj_name = get(project_d, "name", nothing)::Union{String, Nothing}
86-
_proj_uuid = get(project_d, "uuid", nothing)::Union{String, Nothing}
87-
proj_uuid = _proj_uuid === nothing ? nothing : UUID(_proj_uuid)
88-
89-
if proj_name !== nothing && proj_uuid !== nothing
90-
# TODO: Error on missing uuid?
91-
project_deps[proj_name] = UUID(proj_uuid)
92-
names[UUID(proj_uuid)] = proj_name
93-
end
94-
9598
manifest = project_file_manifest_path(envpath)
9699
manifest_d = manifest === nothing ? Dict{String, Any}() : parsed_toml(manifest)
97100

@@ -501,45 +504,48 @@ function precompilepkgs(pkgs::Vector{String}=String[]; internal_call::Bool=false
501504
end
502505
@debug "precompile: circular dep check done" _group=:precompile
503506

504-
# if a list of packages is given, restrict to dependencies of given packages
505-
if !isempty(pkgs)
506-
function collect_all_deps(depsmap, dep, alldeps=Set{Base.PkgId}())
507-
for _dep in depsmap[dep]
508-
if !(_dep in alldeps)
509-
push!(alldeps, _dep)
510-
collect_all_deps(depsmap, _dep, alldeps)
511-
end
512-
end
513-
return alldeps
514-
end
515-
keep = Set{Base.PkgId}()
516-
for dep in depsmap
517-
dep_pkgid = first(dep)
518-
if dep_pkgid.name in pkgs
519-
push!(keep, dep_pkgid)
520-
collect_all_deps(depsmap, dep_pkgid, keep)
507+
if isempty(pkgs)
508+
pkgs = [pkg.name for pkg in direct_deps]
509+
target = "all packages"
510+
else
511+
target = "project..."
512+
end
513+
514+
# restrict to dependencies of given packages
515+
function collect_all_deps(depsmap, dep, alldeps=Set{Base.PkgId}())
516+
for _dep in depsmap[dep]
517+
if !(_dep in alldeps)
518+
push!(alldeps, _dep)
519+
collect_all_deps(depsmap, _dep, alldeps)
521520
end
522521
end
523-
for ext in keys(exts)
524-
if issubset(collect_all_deps(depsmap, ext), keep) # if all extension deps are kept
525-
push!(keep, ext)
526-
end
522+
return alldeps
523+
end
524+
keep = Set{Base.PkgId}()
525+
for dep in depsmap
526+
dep_pkgid = first(dep)
527+
if dep_pkgid.name in pkgs
528+
push!(keep, dep_pkgid)
529+
collect_all_deps(depsmap, dep_pkgid, keep)
527530
end
528-
filter!(d->in(first(d), keep), depsmap)
529-
if isempty(depsmap)
530-
if _from_loading
531-
# if called from loading precompilation it may be a package from another environment stack so
532-
# don't error and allow serial precompilation to try
533-
# TODO: actually handle packages from other envs in the stack
534-
return
535-
else
536-
error("No direct dependencies outside of the sysimage found matching $(repr(pkgs))")
537-
end
531+
end
532+
for ext in keys(exts)
533+
if issubset(collect_all_deps(depsmap, ext), keep) # if all extension deps are kept
534+
push!(keep, ext)
535+
end
536+
end
537+
filter!(d->in(first(d), keep), depsmap)
538+
if isempty(depsmap)
539+
if _from_loading
540+
# if called from loading precompilation it may be a package from another environment stack so
541+
# don't error and allow serial precompilation to try
542+
# TODO: actually handle packages from other envs in the stack
543+
return
544+
else
545+
error("No direct dependencies outside of the sysimage found matching $(repr(pkgs))")
538546
end
539-
target = join(pkgs, ", ")
540-
else
541-
target = "project..."
542547
end
548+
543549
@debug "precompile: packages filtered" _group=:precompile
544550

545551
pkg_queue = Base.PkgId[]

0 commit comments

Comments
 (0)