forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixup_precompile.jl
68 lines (62 loc) · 2.37 KB
/
fixup_precompile.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function needs_USE_GPL_LIBS(s::String)
occursin("CHOLMOD", s) && return true
return false
end
const HEADER = """
# This file is a part of Julia. License is MIT: https://julialang.org/license
# Steps to regenerate this file:
# 1. Remove all `precompile` calls
# 2. Rebuild system image
# 3. Enable TRACE_COMPILE in options.h and rebuild
# 4. Run `./julia 2> precompiles.txt` and do various things.
# 5. Run `./julia contrib/fixup_precompile.jl precompiles.txt to overwrite `precompile.jl`
# or ./julia contrib/fixup_precompile.jl --merge precompiles.txt to merge into existing
# `precompile.jl`
"""
function fixup_precompile(new_precompile_file; merge=false)
old_precompile_file = joinpath(Sys.BINDIR, "..", "..", "base", "precompile.jl")
precompile_statements = Set{String}()
for file in [new_precompile_file; merge ? old_precompile_file : []]
for line in eachline(file)
line = strip(line)
# filter out closures, which might have different generated names in different environments
occursin(r"#[0-9]", line) && continue
# Other stuff than precompile statements might have been written to STDERR
startswith(line, "precompile(Tuple{") || continue
# Ok, add the line
push!(precompile_statements, line)
end
end
open(old_precompile_file, "w") do f
println(f, HEADER)
println(f, """
let
PrecompileStagingArea = Module()
for (_pkgid, _mod) in Base.loaded_modules
if !(_pkgid.name in ("Main", "Core", "Base"))
@eval PrecompileStagingArea \$(Symbol(_mod)) = \$_mod
end
end
@eval PrecompileStagingArea begin""")
for statement in sort(collect(precompile_statements))
isgpl = needs_USE_GPL_LIBS(statement)
isgpl && print(f, "if Base.USE_GPL_LIBS\n ")
println(f, statement)
isgpl && println(f, "end")
end
println(f, "end\nend")
end
if merge
"Merged $new_precompile_file into $old_precompile_file"
else
"Overwrite $old_precompile_file with $new_precompile_file"
end
end
if length(ARGS) == 1
fixup_precompile(joinpath(pwd(), ARGS[1]))
elseif length(ARGS) == 2
@assert ARGS[1] == "--merge"
fixup_precompile(joinpath(pwd(), ARGS[2]); merge = true)
else
error("invalid arguments")
end