From ce15f8330a49a5cd0c435b8912e3377767caeafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Fri, 17 Nov 2023 23:54:52 +0000 Subject: [PATCH] More helpful error message for empty `cpu_target` in `Base.julia_cmd` --- base/util.jl | 6 ++++-- test/cmdlineargs.jl | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/base/util.jl b/base/util.jl index a3771f4ae9dc4..c20a4cfd9bdc0 100644 --- a/base/util.jl +++ b/base/util.jl @@ -144,7 +144,7 @@ See also [`print`](@ref), [`println`](@ref), [`show`](@ref). printstyled(stdout, msg...; bold=bold, italic=italic, underline=underline, blink=blink, reverse=reverse, hidden=hidden, color=color) """ - Base.julia_cmd(juliapath=joinpath(Sys.BINDIR, julia_exename()); cpu_target) + Base.julia_cmd(juliapath=joinpath(Sys.BINDIR, julia_exename()); cpu_target::Union{Nothing,String}=nothing) Return a julia command similar to the one of the running process. Propagates any of the `--cpu-target`, `--sysimage`, `--compile`, `--sysimage-native-code`, @@ -154,6 +154,8 @@ command line arguments that are not at their default values. Among others, `--math-mode`, `--warn-overwrite`, and `--trace-compile` are notably not propagated currently. +Unless set to `nothing` or the empty string, the `cpu_target` keyword argument can be used to override the CPU target set for the running process. + To get the julia command without propagated command line arguments, `julia_cmd()[1]` can be used. !!! compat "Julia 1.1" @@ -243,7 +245,7 @@ function julia_cmd(julia=joinpath(Sys.BINDIR, julia_exename()); cpu_target::Unio if opts.use_pkgimages == 0 push!(addflags, "--pkgimages=no") end - return `$julia -C$cpu_target -J$image_file $addflags` + return `$julia -C $cpu_target -J $image_file $addflags` end function julia_exename() diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index 1c90352af29c9..5378bec2d58e4 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -141,6 +141,13 @@ end end end end + + # Test empty `cpu_target` gives a helpful error message, issue #52209. + io = IOBuffer() + p = run(pipeline(`$(Base.julia_cmd(; cpu_target="")) --startup-file=no -e ''`; stderr=io); wait=false) + wait(p) + @test p.exitcode == 1 + @test occursin("empty CPU name", String(take!(io))) end let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`