@@ -1645,6 +1645,8 @@ function CacheFlags(cf::CacheFlags=CacheFlags(ccall(:jl_cache_flags, UInt8, ()))
16451645 opt_level === nothing ? cf. opt_level : opt_level
16461646 )
16471647end
1648+ # reflecting jloptions.c defaults
1649+ const DefaultCacheFlags = CacheFlags (use_pkgimages= true , debug_level= isdebugbuild () ? 2 : 1 , check_bounds= 0 , inline= true , opt_level= 2 )
16481650
16491651function _cacheflag_to_uint8 (cf:: CacheFlags ):: UInt8
16501652 f = UInt8 (0 )
@@ -1656,12 +1658,29 @@ function _cacheflag_to_uint8(cf::CacheFlags)::UInt8
16561658 return f
16571659end
16581660
1661+ function translate_cache_flags (cacheflags:: CacheFlags , defaultflags:: CacheFlags )
1662+ opts = String[]
1663+ cacheflags. use_pkgimages != defaultflags. use_pkgimages && push! (opts, cacheflags. use_pkgimages ? " --pkgimages=yes" : " --pkgimages=no" )
1664+ cacheflags. debug_level != defaultflags. debug_level && push! (opts, " -g$(cacheflags. debug_level) " )
1665+ cacheflags. check_bounds != defaultflags. check_bounds && push! (opts, (" --check-bounds=auto" , " --check-bounds=yes" , " --check-bounds=no" )[cacheflags. check_bounds + 1 ])
1666+ cacheflags. inline != defaultflags. inline && push! (opts, cacheflags. inline ? " --inline=yes" : " --inline=no" )
1667+ cacheflags. opt_level != defaultflags. opt_level && push! (opts, " -O$(cacheflags. opt_level) " )
1668+ return opts
1669+ end
1670+
16591671function show (io:: IO , cf:: CacheFlags )
1660- print (io, " use_pkgimages = " , cf. use_pkgimages)
1661- print (io, " , debug_level = " , cf. debug_level)
1662- print (io, " , check_bounds = " , cf. check_bounds)
1663- print (io, " , inline = " , cf. inline)
1664- print (io, " , opt_level = " , cf. opt_level)
1672+ print (io, " CacheFlags(" )
1673+ print (io, " ; use_pkgimages=" )
1674+ print (io, cf. use_pkgimages)
1675+ print (io, " , debug_level=" )
1676+ print (io, cf. debug_level)
1677+ print (io, " , check_bounds=" )
1678+ print (io, cf. check_bounds)
1679+ print (io, " , inline=" )
1680+ print (io, cf. inline)
1681+ print (io, " , opt_level=" )
1682+ print (io, cf. opt_level)
1683+ print (io, " )" )
16651684end
16661685
16671686struct ImageTarget
@@ -2848,7 +2867,8 @@ end
28482867
28492868const PRECOMPILE_TRACE_COMPILE = Ref {String} ()
28502869function create_expr_cache (pkg:: PkgId , input:: String , output:: String , output_o:: Union{Nothing, String} ,
2851- concrete_deps:: typeof (_concrete_dependencies), flags:: Cmd = ` ` , internal_stderr:: IO = stderr , internal_stdout:: IO = stdout , isext:: Bool = false )
2870+ concrete_deps:: typeof (_concrete_dependencies), flags:: Cmd = ` ` , cacheflags:: CacheFlags = CacheFlags (),
2871+ internal_stderr:: IO = stderr , internal_stdout:: IO = stdout , isext:: Bool = false )
28522872 @nospecialize internal_stderr internal_stdout
28532873 rm (output, force= true ) # Remove file if it exists
28542874 output_o === nothing || rm (output_o, force= true )
@@ -2891,24 +2911,29 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
28912911 deps = deps_eltype * " [" * join (deps_strs, " ," ) * " ]"
28922912 precomp_stack = " Base.PkgId[$(join (map (pkg_str, vcat (Base. precompilation_stack, pkg)), " , " )) ]"
28932913
2914+ if output_o === nothing
2915+ # remove options that make no difference given the other cache options
2916+ cacheflags = CacheFlags (cacheflags, opt_level= 0 )
2917+ end
2918+ opts = translate_cache_flags (cacheflags, CacheFlags ()) # julia_cmd is generated for the running system, and must be fixed if running for precompile instead
28942919 if output_o != = nothing
28952920 @debug " Generating object cache file for $(repr (" text/plain" , pkg)) "
28962921 cpu_target = get (ENV , " JULIA_CPU_TARGET" , nothing )
2897- opts = ` --output-o $( output_o) --output-ji $(output) --output-incremental=yes `
2922+ push! ( opts, " --output-o" , output_o)
28982923 else
28992924 @debug " Generating cache file for $(repr (" text/plain" , pkg)) "
29002925 cpu_target = nothing
2901- opts = ` -O0 --output-ji $(output) --output-incremental=yes`
29022926 end
2927+ push! (opts, " --output-ji" , output)
2928+ isassigned (PRECOMPILE_TRACE_COMPILE) && push! (opts, " --trace-compile=$(PRECOMPILE_TRACE_COMPILE[]) " )
29032929
2904- trace = isassigned (PRECOMPILE_TRACE_COMPILE) ? ` --trace-compile=$(PRECOMPILE_TRACE_COMPILE[]) --trace-compile-timing` : ` `
29052930 io = open (pipeline (addenv (` $(julia_cmd (;cpu_target):: Cmd )
2906- $(flags)
2907- $(opts)
2908- --startup-file=no --history-file=no --warn-overwrite =yes
2909- --color= $(have_color === nothing ? " auto " : have_color ? " yes" : " no " )
2910- $trace
2911- -` ,
2931+ $(flags)
2932+ $(opts)
2933+ --output-incremental =yes
2934+ --startup-file=no --history-file=no --warn-overwrite= yes
2935+ $(have_color === nothing ? " --color=auto " : have_color ? " --color=yes " : " --color=no " )
2936+ -` ,
29122937 " OPENBLAS_NUM_THREADS" => 1 ,
29132938 " JULIA_NUM_THREADS" => 1 ),
29142939 stderr = internal_stderr, stdout = internal_stdout),
@@ -3026,7 +3051,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
30263051 close (tmpio_o)
30273052 close (tmpio_so)
30283053 end
3029- p = create_expr_cache (pkg, path, tmppath, tmppath_o, concrete_deps, flags, internal_stderr, internal_stdout, isext)
3054+ p = create_expr_cache (pkg, path, tmppath, tmppath_o, concrete_deps, flags, cacheflags, internal_stderr, internal_stdout, isext)
30303055
30313056 if success (p)
30323057 if cache_objects
@@ -3997,5 +4022,5 @@ end
39974022
39984023precompile (include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof (_concrete_dependencies), Nothing)) || @assert false
39994024precompile (include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof (_concrete_dependencies), String)) || @assert false
4000- precompile (create_expr_cache, (PkgId, String, String, String, typeof (_concrete_dependencies), Cmd, IO, IO)) || @assert false
4001- precompile (create_expr_cache, (PkgId, String, String, Nothing, typeof (_concrete_dependencies), Cmd, IO, IO)) || @assert false
4025+ precompile (create_expr_cache, (PkgId, String, String, String, typeof (_concrete_dependencies), Cmd, CacheFlags, IO, IO)) || @assert false
4026+ precompile (create_expr_cache, (PkgId, String, String, Nothing, typeof (_concrete_dependencies), Cmd, CacheFlags, IO, IO)) || @assert false
0 commit comments