From f51f24cc71a1e89dd598a573d78a8c760dab7fc6 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 16 Feb 2022 06:24:13 -0500 Subject: [PATCH] fix next prompt detector in `generate_precompile_statements` (#44196) (cherry picked from commit c839221d41574f9b496232b1642ac126f9e8586c) --- contrib/generate_precompile.jl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/contrib/generate_precompile.jl b/contrib/generate_precompile.jl index f2d39918ffe0d..e6cf280812685 100644 --- a/contrib/generate_precompile.jl +++ b/contrib/generate_precompile.jl @@ -231,6 +231,11 @@ if Profile !== nothing """ end +const JULIA_PROMPT = "julia> " +const PKG_PROMPT = "pkg> " +const SHELL_PROMPT = "shell> " +const HELP_PROMPT = "help?> " + function generate_precompile_statements() start_time = time_ns() debug_output = devnull # or stdout @@ -311,7 +316,7 @@ function generate_precompile_statements() close(ptm) end # wait for the definitive prompt before start writing to the TTY - readuntil(output_copy, "julia>") + readuntil(output_copy, JULIA_PROMPT) sleep(0.1) readavailable(output_copy) # Input our script @@ -329,9 +334,16 @@ function generate_precompile_statements() write(ptm, l, "\n") readuntil(output_copy, "\n") # wait for the next prompt-like to appear - # NOTE: this is rather inaccurate because the Pkg REPL mode is a special flower readuntil(output_copy, "\n") - readuntil(output_copy, "> ") + strbuf = "" + while true + strbuf *= String(readavailable(output_copy)) + occursin(JULIA_PROMPT, strbuf) && break + occursin(PKG_PROMPT, strbuf) && break + occursin(SHELL_PROMPT, strbuf) && break + occursin(HELP_PROMPT, strbuf) && break + sleep(0.1) + end end println() end