Skip to content

Commit 8e73c60

Browse files
allow passing command line flags to compilecache. (JuliaLang#53316) (#240)
Pkg right now has to start a separate process to run precompilation for the test environment which is annoying for multiple reasons Corresponding Pkg PR: JuliaLang/Pkg.jl#3792 Co-authored-by: Kristoffer Carlsson <[email protected]>
1 parent 3fd26cb commit 8e73c60

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

base/loading.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,7 @@ end
22392239

22402240
const PRECOMPILE_TRACE_COMPILE = Ref{String}()
22412241
function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::Union{Nothing, String},
2242-
concrete_deps::typeof(_concrete_dependencies), internal_stderr::IO = stderr, internal_stdout::IO = stdout)
2242+
concrete_deps::typeof(_concrete_dependencies), flags::Cmd=``, internal_stderr::IO = stderr, internal_stdout::IO = stdout)
22432243
@nospecialize internal_stderr internal_stdout
22442244
rm(output, force=true) # Remove file if it exists
22452245
output_o === nothing || rm(output_o, force=true)
@@ -2281,6 +2281,7 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
22812281
io = open(pipeline(addenv(`$(julia_cmd(;cpu_target)::Cmd) $(opts)
22822282
--startup-file=no --history-file=no --warn-overwrite=yes
22832283
--color=$(have_color === nothing ? "auto" : have_color ? "yes" : "no")
2284+
$flags
22842285
$trace
22852286
-`,
22862287
"OPENBLAS_NUM_THREADS" => 1,
@@ -2335,17 +2336,17 @@ This can be used to reduce package load times. Cache files are stored in
23352336
`DEPOT_PATH[1]/compiled`. See [Module initialization and precompilation](@ref)
23362337
for important notes.
23372338
"""
2338-
function compilecache(pkg::PkgId, internal_stderr::IO = stderr, internal_stdout::IO = stdout)
2339+
function compilecache(pkg::PkgId, internal_stderr::IO = stderr, internal_stdout::IO = stdout; flags::Cmd=``)
23392340
@nospecialize internal_stderr internal_stdout
23402341
path = locate_package(pkg)
2341-
path === nothing && throw(ArgumentError("$pkg not found during precompilation"))
2342-
return compilecache(pkg, path, internal_stderr, internal_stdout)
2342+
path === nothing && throw(ArgumentError("$(repr("text/plain", pkg)) not found during precompilation"))
2343+
return compilecache(pkg, path, internal_stderr, internal_stdout; flags)
23432344
end
23442345

23452346
const MAX_NUM_PRECOMPILE_FILES = Ref(10)
23462347

23472348
function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, internal_stdout::IO = stdout,
2348-
keep_loaded_modules::Bool = true)
2349+
keep_loaded_modules::Bool = true; flags::Cmd=``)
23492350

23502351
@nospecialize internal_stderr internal_stdout
23512352
# decide where to put the resulting cache file
@@ -2383,7 +2384,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
23832384
close(tmpio_o)
23842385
close(tmpio_so)
23852386
end
2386-
p = create_expr_cache(pkg, path, tmppath, tmppath_o, concrete_deps, internal_stderr, internal_stdout)
2387+
p = create_expr_cache(pkg, path, tmppath, tmppath_o, concrete_deps, flags, internal_stderr, internal_stdout)
23872388

23882389
if success(p)
23892390
if cache_objects
@@ -3249,5 +3250,5 @@ end
32493250

32503251
precompile(include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof(_concrete_dependencies), Nothing))
32513252
precompile(include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof(_concrete_dependencies), String))
3252-
precompile(create_expr_cache, (PkgId, String, String, String, typeof(_concrete_dependencies), IO, IO))
3253-
precompile(create_expr_cache, (PkgId, String, String, Nothing, typeof(_concrete_dependencies), IO, IO))
3253+
precompile(create_expr_cache, (PkgId, String, String, String, typeof(_concrete_dependencies), IO, IO, Cmd))
3254+
precompile(create_expr_cache, (PkgId, String, String, Nothing, typeof(_concrete_dependencies), IO, IO, Cmd))

test/precompile.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,22 @@ precompile_test_harness("Issue #50538") do load_path
18121812
@test !isdefined(I50538, :undefglobal)
18131813
end
18141814

1815+
precompile_test_harness("Test flags") do load_path
1816+
write(joinpath(load_path, "TestFlags.jl"),
1817+
"""
1818+
module TestFlags
1819+
end
1820+
""")
1821+
ji, ofile = Base.compilecache(Base.PkgId("TestFlags"); flags=`--check-bounds=no -O3`)
1822+
@show ji, ofile
1823+
open(ji, "r") do io
1824+
Base.isvalid_cache_header(io)
1825+
_, _, _, _, _, _, _, flags = Base.parse_cache_header(io, ji)
1826+
cacheflags = Base.CacheFlags(flags)
1827+
@test cacheflags.check_bounds == 2
1828+
@test cacheflags.opt_level == 3
1829+
end
1830+
end
18151831

18161832
empty!(Base.DEPOT_PATH)
18171833
append!(Base.DEPOT_PATH, original_depot_path)

0 commit comments

Comments
 (0)