Skip to content

Commit

Permalink
Add kwarg succeed_on_precompilable_error (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens authored Apr 9, 2024
1 parent d635d67 commit 231a1d1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- `test_persistent_tasks` now accepts an optional `succeed_on_precompilable_error::Bool=true` to control the behavior on the occurrence of a `PrecompilableError`. ([#285])

### Changed

- The output of `test_ambiguities` now gets printed to stderr instead of stdout. ([#281])
Expand Down
28 changes: 21 additions & 7 deletions src/persistent_tasks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ On Julia version 1.9 and before, this test always succeeds.
- `tmax::Real = 5`: the maximum time (in seconds) to wait after loading the
package before forcibly shutting down the precompilation process (triggering
a test failure).
- `succeed_on_precompilable_error::Bool = true`: If true, the test will pass if
the package has a precompilation error. The intended use is to keep your CI
green even if the case that a new release of a dependency introduces a
method overwrite that breaks precompilation of your package.
- `expr::Expr = quote end`: An expression to run in the precompile package.
!!! note
Expand All @@ -43,10 +47,23 @@ function test_persistent_tasks(package::Module; kwargs...)
test_persistent_tasks(PkgId(package); kwargs...)
end

function has_persistent_tasks(package::PkgId; expr::Expr = quote end, tmax = 10)
root_project_path, found = root_project_toml(package)
found || error("Unable to locate Project.toml")
return !precompile_wrapper(root_project_path, tmax, expr)
function has_persistent_tasks(
package::PkgId;
expr::Expr = quote end,
succeed_on_precompilable_error::Bool = true,
tmax = 10,
)
@static if VERSION < v"1.10.0-"
return false
else
if Base.compilecache(package) isa Base.PrecompilableError
@error "Package $(package.name) has a precompilation error"
return !succeed_on_precompilable_error
end
root_project_path, found = root_project_toml(package)
found || error("Unable to locate Project.toml")
return !precompile_wrapper(root_project_path, tmax, expr)
end
end

"""
Expand Down Expand Up @@ -75,9 +92,6 @@ function find_persistent_tasks_deps(package::Module; kwargs...)
end

function precompile_wrapper(project, tmax, expr)
@static if VERSION < v"1.10.0-"
return true
end
prev_project = Base.active_project()::String
isdefined(Pkg, :respect_sysimage_versions) && Pkg.respect_sysimage_versions(false)
try
Expand Down
2 changes: 2 additions & 0 deletions test/pkgs/PersistentTasks/PrecompilableErrorPkg/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "PrecompilableErrorPkg"
uuid = "e5c298b6-d81d-47aa-a9ed-5ea983e22986"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module PrecompilableErrorPkg

__precompile__(false)

end # module PrecompilableErrorPkg
32 changes: 31 additions & 1 deletion test/test_persistent_tasks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end
result = Aqua.find_persistent_tasks_deps(getid("UsesBoth"))
@test result == ["PersistentTask"]
end
filter!(str -> !occursin("PersistentTasks", str), LOAD_PATH)
end

@testset "test_persistent_tasks(expr)" begin
Expand All @@ -45,4 +44,35 @@ end
end
end

@testset "test_persistent_tasks(expr)" begin
if Base.VERSION >= v"1.10-"
@test !Aqua.has_persistent_tasks(
getid("TransientTask"),
expr = quote
fetch(Threads.@spawn nothing)
end,
)
@test Aqua.has_persistent_tasks(getid("TransientTask"), expr = quote
Threads.@spawn while true
sleep(0.5)
end
end)
end
end

@testset "test_persistent_tasks with precompilable error" begin
if Base.VERSION >= v"1.10-"
println("### Expected output START ###")
@test !Aqua.has_persistent_tasks(
getid("PrecompilableErrorPkg");
succeed_on_precompilable_error = true,
)
@test Aqua.has_persistent_tasks(
getid("PrecompilableErrorPkg");
succeed_on_precompilable_error = false,
)
println("### Expected output END ###")
end
end

end

0 comments on commit 231a1d1

Please sign in to comment.