-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: generate precompile as part of build process
- Loading branch information
1 parent
a878341
commit 92e187e
Showing
14 changed files
with
234 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
/version_git.jl | ||
/version_git.jl.phony | ||
/userimg.jl | ||
/precompile_local.jl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
tmp = tempname() | ||
if haskey(Base.loaded_modules, Base.PkgId(Base.UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL")) | ||
# Record precompile statements when starting a julia session with a repl | ||
run(pipeline(`$(Base.julia_cmd()) --trace-compile=yes -e ' | ||
@async while true | ||
sleep(0.01) | ||
isdefined(Base, :active_repl) && exit(0) | ||
end' -i`; stderr = tmp)) | ||
# Replay a REPL script | ||
repl_replay = joinpath(@__DIR__, "precompile_replay.jl") | ||
run(pipeline(`$(Base.julia_cmd()) --trace-compile=yes $repl_replay`; stderr=tmp, append=true)) | ||
else | ||
# No REPL, just record the startup | ||
run(pipeline(`$(Base.julia_cmd()) --trace-compile=yes -e 'exit(0)'`; stderr=tmp)) | ||
end | ||
|
||
# Replace the fake terminal with the real terminal and filter out everything we compiled in Main | ||
precompiles = readlines(tmp) | ||
new_precompiles = String[] | ||
for line in precompiles | ||
line = replace(line, "FakeTerminals.FakeTerminal" => "REPL.Terminals.TTYTerminal") | ||
(occursin(r"Main.", line) || occursin(r"FakeTerminals.", line)) && continue | ||
push!(new_precompiles, line) | ||
end | ||
write(tmp, join(new_precompiles, '\n')) | ||
|
||
# Only write the precompile in case it is different | ||
|
||
include("fixup_precompile.jl") | ||
precompile_local = joinpath(@__DIR__, "..", "base/precompile_local.jl") | ||
tmp2 = tempname() | ||
isfile(precompile_local) && cp(precompile_local, tmp2) | ||
fixup_precompile(tmp; merge=true, keep_anonymous=true, header=false, output=tmp2) | ||
# Only update timestamp if different | ||
if !isfile(precompile_local) || (isfile(precompile_local) && (read(tmp2, String) != read(precompile_local, String))) | ||
println("Updatingf...") | ||
mv(tmp2, precompile_local; force=true) | ||
end | ||
rm(tmp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import REPL | ||
include(joinpath(Sys.STDLIB, "REPL", "test", "FakeTerminals.jl")) | ||
import .FakeTerminals.FakeTerminal | ||
include(joinpath(Sys.STDLIB, "REPL", "test", "fake_repl.jl")) | ||
|
||
const CTRL_C = '\x03' | ||
const UP_ARROW = "\e[A" | ||
const DOWN_ARROW = "\e[B" | ||
|
||
# TODO: Have a utility to generate this from a real REPL session? | ||
precompile_script = """ | ||
2+2 | ||
println("Hello") | ||
@time 1+1 | ||
?reinterpret | ||
;ls | ||
using Ra\t$CTRL_C | ||
\\alpha\t$CTRL_C | ||
\e[200~paste here ;)\e[201~"$CTRL_C | ||
$UP_ARROW$DOWN_ARROW | ||
""" | ||
|
||
# Writing ^C to the repl will cause sigint, so let's not die on that | ||
ccall(:jl_exit_on_sigint, Cvoid, (Cint,), 0) | ||
|
||
fake_repl() do stdin_write, stdout_read, repl | ||
repl.specialdisplay = REPL.REPLDisplay(repl) | ||
repl.history_file = false | ||
|
||
repltask = @async begin | ||
REPL.run_repl(repl) | ||
end | ||
|
||
global inc = false | ||
global b = Condition() | ||
global c = Condition() | ||
let cmd = "\"Hello REPL\"" | ||
write(stdin_write, "Main.inc || wait(Main.b); r = $cmd; notify(Main.c); r\r") | ||
end | ||
inc = true | ||
notify(b) | ||
wait(c) | ||
|
||
write(stdin_write, precompile_script) | ||
|
||
s = readavailable(stdout_read) | ||
|
||
# Close REPL ^D | ||
write(stdin_write, '\x04') | ||
Base._wait(repltask) | ||
|
||
nothing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.