Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ version = "1.0.0-DEV"

[deps]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Pkg = "1.6"
PrecompileTools = "1"
Test = "<0.0.1, 1"
julia = "1.6"

Expand Down
2 changes: 2 additions & 0 deletions src/Aqua.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ function test_all(
end
end

include("precompile.jl")

end # module
18 changes: 14 additions & 4 deletions src/persistent_tasks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ function precompile_wrapper(project, tmax, expr)
isdefined(Pkg, :respect_sysimage_versions) && Pkg.respect_sysimage_versions(false)
try
pkgdir = dirname(project)
pkgname = get(TOML.parsefile(project), "name", nothing)
if isnothing(pkgname)
pkgname = get(TOML.parsefile(project), "name", "")::String
if isempty(pkgname)
Comment on lines +87 to +88

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's to make it type-stable. I could also have changed the type annotation to Union{String, Nothing}, but I felt that sticking with only strings is simpler.

@error "Unable to locate package name in $project"
return false
end
Expand All @@ -111,8 +111,18 @@ end
)
end
# Precompile the wrapper package
cmd = `$(Base.julia_cmd()) --project=$wrapperdir -e 'push!(LOAD_PATH, "@stdlib"); using Pkg; Pkg.precompile(; io = devnull)'`
proc = run(cmd, stdin, stdout, stderr; wait = false)
currently_precompiling = @ccall(jl_generating_output()::Cint) == 1
cmd = if currently_precompiling
# During precompilation we run a dummy command that just touches the
# status file to keep things simple.
code = """touch("$(escape_string(statusfile))")"""
`$(Base.julia_cmd()) -e $code`
else
`$(Base.julia_cmd()) --project=$wrapperdir -e 'push!(LOAD_PATH, "@stdlib"); using Pkg; Pkg.precompile(; io = devnull)'`
end

cmd = pipeline(cmd; stdout, stderr)
proc = run(cmd; wait = false)::Base.Process
while !isfile(statusfile) && process_running(proc)
sleep(0.5)
end
Expand Down
59 changes: 59 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using PrecompileTools: @compile_workload

# Create a minimal fake package to test. Needs to be at the top-level because
# it's a module.
module _FakePackage
export fake_function
fake_function() = 1
end

@compile_workload begin
redirect_stdout(devnull) do
test_all(
_FakePackage;
ambiguities = false,
project_extras = false,
stale_deps = false,
deps_compat = false,
persistent_tasks = false,
)
end

# Explicitly precompile the tests that need a real package module
precompile(test_ambiguities, (Vector{Module},))
precompile(test_project_extras, (Module,))
precompile(test_stale_deps, (Module,))
precompile(test_deps_compat, (Module,))

# Create a fake package directory for testing persistent_tasks. We go to
# some effort to precompile this because it takes the longest due to Pkg
# calls and running precompilation in a subprocess.
mktempdir() do dir
project_file = joinpath(dir, "Project.toml")
write(
project_file,
"""
name = "AquaFakePackage"
uuid = "5a23b2e7-8c45-4b1c-9d3f-7a6b4c8d9e0f"
version = "0.1.0"

[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Test = "1"
julia = "1"
""",
)

srcdir = joinpath(dir, "src")
mkdir(srcdir)
write(joinpath(srcdir, "AquaFakePackage.jl"), "module AquaFakePackage end")

# The meat of the compilation latency comes from this function. Running
# test_persistent_tasks() directly is more difficult because it takes a
# Module and then gets the package directory, and we don't want to load
# the fake package.
precompile_wrapper(project_file, 10, quote end)
end
end
7 changes: 4 additions & 3 deletions src/stale_deps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ function find_stale_deps(pkg::PkgId; ignore::AbstractVector{Symbol} = Symbol[])
found || error("Unable to locate Project.toml")

prj = TOML.parsefile(root_project_path)
deps = PkgId[PkgId(UUID(v), k) for (k, v) in get(prj, "deps", Dict{String,Any}())]
weakdeps =
PkgId[PkgId(UUID(v), k) for (k, v) in get(prj, "weakdeps", Dict{String,Any}())]
deps::Vector{PkgId} =
PkgId[PkgId(UUID(v), k) for (k::String, v::String) in get(prj, "deps", Dict())]
weakdeps::Vector{PkgId} =
PkgId[PkgId(UUID(v), k) for (k::String, v::String) in get(prj, "weakdeps", Dict())]

marker = "_START_MARKER_"
code = """
Expand Down
Loading