Skip to content

Commit aaed1cc

Browse files
authored
allow passing command line flags to compilecache. (#53316)
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
1 parent 90afb7c commit aaed1cc

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

base/loading.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,7 @@ end
24472447

24482448
const PRECOMPILE_TRACE_COMPILE = Ref{String}()
24492449
function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::Union{Nothing, String},
2450-
concrete_deps::typeof(_concrete_dependencies), internal_stderr::IO = stderr, internal_stdout::IO = stdout)
2450+
concrete_deps::typeof(_concrete_dependencies), flags::Cmd=``, internal_stderr::IO = stderr, internal_stdout::IO = stdout)
24512451
@nospecialize internal_stderr internal_stdout
24522452
rm(output, force=true) # Remove file if it exists
24532453
output_o === nothing || rm(output_o, force=true)
@@ -2503,6 +2503,7 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
25032503
io = open(pipeline(addenv(`$(julia_cmd(;cpu_target)::Cmd) $(opts)
25042504
--startup-file=no --history-file=no --warn-overwrite=yes
25052505
--color=$(have_color === nothing ? "auto" : have_color ? "yes" : "no")
2506+
$flags
25062507
$trace
25072508
-`,
25082509
"OPENBLAS_NUM_THREADS" => 1,
@@ -2570,17 +2571,17 @@ This can be used to reduce package load times. Cache files are stored in
25702571
`DEPOT_PATH[1]/compiled`. See [Module initialization and precompilation](@ref)
25712572
for important notes.
25722573
"""
2573-
function compilecache(pkg::PkgId, internal_stderr::IO = stderr, internal_stdout::IO = stdout; reasons::Union{Dict{String,Int},Nothing}=Dict{String,Int}())
2574+
function compilecache(pkg::PkgId, internal_stderr::IO = stderr, internal_stdout::IO = stdout; flags::Cmd=``, reasons::Union{Dict{String,Int},Nothing}=Dict{String,Int}())
25742575
@nospecialize internal_stderr internal_stdout
25752576
path = locate_package(pkg)
25762577
path === nothing && throw(ArgumentError("$(repr("text/plain", pkg)) not found during precompilation"))
2577-
return compilecache(pkg, path, internal_stderr, internal_stdout; reasons)
2578+
return compilecache(pkg, path, internal_stderr, internal_stdout; flags, reasons)
25782579
end
25792580

25802581
const MAX_NUM_PRECOMPILE_FILES = Ref(10)
25812582

25822583
function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, internal_stdout::IO = stdout,
2583-
keep_loaded_modules::Bool = true; reasons::Union{Dict{String,Int},Nothing}=Dict{String,Int}())
2584+
keep_loaded_modules::Bool = true; flags::Cmd=``, reasons::Union{Dict{String,Int},Nothing}=Dict{String,Int}())
25842585

25852586
@nospecialize internal_stderr internal_stdout
25862587
# decide where to put the resulting cache file
@@ -2618,7 +2619,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
26182619
close(tmpio_o)
26192620
close(tmpio_so)
26202621
end
2621-
p = create_expr_cache(pkg, path, tmppath, tmppath_o, concrete_deps, internal_stderr, internal_stdout)
2622+
p = create_expr_cache(pkg, path, tmppath, tmppath_o, concrete_deps, flags, internal_stderr, internal_stdout)
26222623

26232624
if success(p)
26242625
if cache_objects
@@ -3627,5 +3628,5 @@ end
36273628

36283629
precompile(include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof(_concrete_dependencies), Nothing))
36293630
precompile(include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof(_concrete_dependencies), String))
3630-
precompile(create_expr_cache, (PkgId, String, String, String, typeof(_concrete_dependencies), IO, IO))
3631-
precompile(create_expr_cache, (PkgId, String, String, Nothing, typeof(_concrete_dependencies), IO, IO))
3631+
precompile(create_expr_cache, (PkgId, String, String, String, typeof(_concrete_dependencies), IO, IO, Cmd))
3632+
precompile(create_expr_cache, (PkgId, String, String, Nothing, typeof(_concrete_dependencies), IO, IO, Cmd))

test/precompile.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,23 @@ precompile_test_harness("Issue #50538") do load_path
19861986
@test !isdefined(I50538, :undefglobal)
19871987
end
19881988

1989+
precompile_test_harness("Test flags") do load_path
1990+
write(joinpath(load_path, "TestFlags.jl"),
1991+
"""
1992+
module TestFlags
1993+
end
1994+
""")
1995+
ji, ofile = Base.compilecache(Base.PkgId("TestFlags"); flags=`--check-bounds=no -O3`)
1996+
@show ji, ofile
1997+
open(ji, "r") do io
1998+
Base.isvalid_cache_header(io)
1999+
_, _, _, _, _, _, _, flags = Base.parse_cache_header(io, ji)
2000+
cacheflags = Base.CacheFlags(flags)
2001+
@test cacheflags.check_bounds == 2
2002+
@test cacheflags.opt_level == 3
2003+
end
2004+
end
2005+
19892006
empty!(Base.DEPOT_PATH)
19902007
append!(Base.DEPOT_PATH, original_depot_path)
19912008
empty!(Base.LOAD_PATH)

0 commit comments

Comments
 (0)