Skip to content

Commit

Permalink
follow up JuliaLang#2018:
Browse files Browse the repository at this point in the history
UUIDs are not in `keys` but `values` of `Project.deps`
  • Loading branch information
aviatesk committed Sep 23, 2020
1 parent 5c18022 commit 567ae86
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -895,27 +895,28 @@ end
precompile() = precompile(Context())
function precompile(ctx::Context)
printpkgstyle(ctx, :Precompiling, "project...")

num_tasks = parse(Int, get(ENV, "JULIA_NUM_PRECOMPILE_TASKS", string(Sys.CPU_THREADS + 1)))
parallel_limiter = Base.Semaphore(num_tasks)

man = Pkg.Types.read_manifest(ctx.env.manifest_file)
pkgids = [Base.PkgId(first(dep), last(dep).name) for dep in man if !Pkg.Operations.is_stdlib(first(dep))]
pkg_dep_uuid_lists = [collect(values(last(dep).deps)) for dep in man if !Pkg.Operations.is_stdlib(first(dep))]
filter!.(!is_stdlib, pkg_dep_uuid_lists)


if ctx.env.pkg !== nothing && isfile( joinpath( dirname(ctx.env.project_file), "src", ctx.env.pkg.name * ".jl") )
push!(pkgids, Base.PkgId(ctx.env.pkg.uuid, ctx.env.pkg.name))
push!(pkg_dep_uuid_lists, collect(keys(ctx.env.project.deps)))
end

push!(pkg_dep_uuid_lists, collect(values(ctx.env.project.deps)))
end

filter!.(!is_stdlib, pkg_dep_uuid_lists)

was_processed = Dict{Base.UUID,Base.Event}()
was_recompiled = Dict{Base.UUID,Bool}()
for pkgid in pkgids
was_processed[pkgid.uuid] = Base.Event()
was_recompiled[pkgid.uuid] = false
end

function is_stale(paths, sourcepath)
for path_to_try in paths::Vector{String}
staledeps = Base.stale_cachefile(sourcepath, path_to_try, Base.TOMLCache())
Expand All @@ -924,20 +925,20 @@ function precompile(ctx::Context)
end
return true
end

errored = false
@sync for (i, pkg) in pairs(pkgids)
paths = Base.find_all_in_cache_path(pkg)
sourcepath = Base.locate_package(pkg)
sourcepath === nothing && continue
# Heuristic for when precompilation is disabled
occursin(r"\b__precompile__\(\s*false\s*\)", read(sourcepath, String)) && continue

@async begin
for dep_uuid in pkg_dep_uuid_lists[i] # wait for deps to finish
wait(was_processed[dep_uuid])
end

# skip stale checking and force compilation if any dep was recompiled in this session
any_dep_recompiled = any(map(dep_uuid->was_recompiled[dep_uuid], pkg_dep_uuid_lists[i]))
if !errored && (any_dep_recompiled || is_stale(paths, sourcepath))
Expand All @@ -960,7 +961,7 @@ function precompile(ctx::Context)
else
notify(was_processed[pkg.uuid])
end
end
end
end
nothing
end
Expand Down

0 comments on commit 567ae86

Please sign in to comment.