From e78f791e048ed5192d6cb3166fe089207e2e994d Mon Sep 17 00:00:00 2001 From: nixo Date: Thu, 13 Feb 2020 19:23:13 +0100 Subject: [PATCH] no more interactive --- contrib/generate_precompile.jl | 121 ++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 56 deletions(-) diff --git a/contrib/generate_precompile.jl b/contrib/generate_precompile.jl index a5b85d87bd6f7..f250f01c4b8ce 100644 --- a/contrib/generate_precompile.jl +++ b/contrib/generate_precompile.jl @@ -85,71 +85,80 @@ function generate_precompile_statements() print("Generating precompile statements...") precompile_file = "/tmp/jl_precompile_file" open(precompile_file, "w+") do precompile_file_h - # Run a repl process and replay our script - pty_slave, pty_master = open_fake_pty() + # # Run a repl process and replay our script + # pty_slave, pty_master = open_fake_pty() blackhole = Sys.isunix() ? "/dev/null" : "nul" + # # if have_repl + # # cmdargs = ```--color=yes + # # -e 'import REPL; REPL.Terminals.is_precompiling[] = true' + # # ``` + # # else + # # cmdargs = `-e nothing` + # # end + # cmdargs = `-e nothing` + # p = withenv("JULIA_HISTORY" => blackhole, + # "JULIA_PROJECT" => nothing, # remove from environment + # "JULIA_LOAD_PATH" => Sys.iswindows() ? "@;@stdlib" : "@:@stdlib", + # "TERM" => "") do + # sysimg = Base.unsafe_string(Base.JLOptions().image_file) + # run(```$(julia_exepath()) -O0 --trace-compile=$precompile_file --sysimage $sysimg + # --cpu-target=native --startup-file=no --color=yes + # -i $cmdargs```, + # pty_slave, pty_slave, pty_slave; wait=false) + # end + # Base.close_stdio(pty_slave) + # # Prepare a background process to copy output from process until `pty_slave` is closed + # output_copy = Base.BufferStream() + # tee = @async try + # while !eof(pty_master) + # l = readavailable(pty_master) + # write(debug_output, l) + # Sys.iswindows() && (sleep(0.1); yield(); yield()) # workaround hang - probably a libuv issue? + # write(output_copy, l) + # end + # close(output_copy) + # close(pty_master) + # catch ex + # close(output_copy) + # close(pty_master) + # if !(ex isa Base.IOError && ex.code == Base.UV_EIO) + # rethrow() # ignore EIO on pty_master after pty_slave dies + # end + # end + # # wait for the definitive prompt before start writing to the TTY + # readuntil(output_copy, "julia>") + # sleep(0.1) + # readavailable(output_copy) + # # Input our script # if have_repl - # cmdargs = ```--color=yes - # -e 'import REPL; REPL.Terminals.is_precompiling[] = true' - # ``` - # else - # cmdargs = `-e nothing` + # for l in split(precompile_script, '\n'; keepempty=false) + # sleep(0.1) + # # consume any other output + # bytesavailable(output_copy) > 0 && readavailable(output_copy) + # # push our input + # write(debug_output, "\n#### inputting statement: ####\n$(repr(l))\n####\n") + # write(pty_master, l, "\n") + # readuntil(output_copy, "\n") + # # wait for the next prompt-like to appear + # # NOTE: this is rather innaccurate because the Pkg REPL mode is a special flower + # readuntil(output_copy, "\n") + # readuntil(output_copy, "> ") + # end # end - cmdargs = `-e nothing` + # write(pty_master, "exit()\n") + # wait(tee) + # success(p) || Base.pipeline_error(p) + # close(pty_master) + # write(debug_output, "\n#### FINISHED ####\n") + p = withenv("JULIA_HISTORY" => blackhole, "JULIA_PROJECT" => nothing, # remove from environment "JULIA_LOAD_PATH" => Sys.iswindows() ? "@;@stdlib" : "@:@stdlib", "TERM" => "") do sysimg = Base.unsafe_string(Base.JLOptions().image_file) run(```$(julia_exepath()) -O0 --trace-compile=$precompile_file --sysimage $sysimg - --cpu-target=native --startup-file=no --color=yes - -i $cmdargs```, - pty_slave, pty_slave, pty_slave; wait=false) - end - Base.close_stdio(pty_slave) - # Prepare a background process to copy output from process until `pty_slave` is closed - output_copy = Base.BufferStream() - tee = @async try - while !eof(pty_master) - l = readavailable(pty_master) - write(debug_output, l) - Sys.iswindows() && (sleep(0.1); yield(); yield()) # workaround hang - probably a libuv issue? - write(output_copy, l) - end - close(output_copy) - close(pty_master) - catch ex - close(output_copy) - close(pty_master) - if !(ex isa Base.IOError && ex.code == Base.UV_EIO) - rethrow() # ignore EIO on pty_master after pty_slave dies - end - end - # wait for the definitive prompt before start writing to the TTY - readuntil(output_copy, "julia>") - sleep(0.1) - readavailable(output_copy) - # Input our script - if have_repl - for l in split(precompile_script, '\n'; keepempty=false) - sleep(0.1) - # consume any other output - bytesavailable(output_copy) > 0 && readavailable(output_copy) - # push our input - write(debug_output, "\n#### inputting statement: ####\n$(repr(l))\n####\n") - write(pty_master, l, "\n") - readuntil(output_copy, "\n") - # wait for the next prompt-like to appear - # NOTE: this is rather innaccurate because the Pkg REPL mode is a special flower - readuntil(output_copy, "\n") - readuntil(output_copy, "> ") - end + --cpu-target=native --startup-file=no --color=yes -e 1+1```) end - write(pty_master, "exit()\n") - wait(tee) - success(p) || Base.pipeline_error(p) - close(pty_master) - write(debug_output, "\n#### FINISHED ####\n") # Extract the precompile statements from the precompile file statements = Set{String}() @@ -190,7 +199,7 @@ function generate_precompile_statements() Base.time_print(tot_time * 10^9) print(" (overhead "); Base.time_print((tot_time - include_time) * 10^9); println(")") end - rm(precompile_file) + # rm(precompile_file) return end