Skip to content

Commit 4a18886

Browse files
authored
More helpful error message for empty cpu_target in Base.julia_cmd (#52217)
Fix #52209.
1 parent 08d89eb commit 4a18886

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

base/util.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ See also [`print`](@ref), [`println`](@ref), [`show`](@ref).
144144
printstyled(stdout, msg...; bold=bold, italic=italic, underline=underline, blink=blink, reverse=reverse, hidden=hidden, color=color)
145145

146146
"""
147-
Base.julia_cmd(juliapath=joinpath(Sys.BINDIR, julia_exename()); cpu_target)
147+
Base.julia_cmd(juliapath=joinpath(Sys.BINDIR, julia_exename()); cpu_target::Union{Nothing,String}=nothing)
148148
149149
Return a julia command similar to the one of the running process.
150150
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.
154154
155155
Among others, `--math-mode`, `--warn-overwrite`, and `--trace-compile` are notably not propagated currently.
156156
157+
Unless set to `nothing`, the `cpu_target` keyword argument can be used to override the CPU target set for the running process.
158+
157159
To get the julia command without propagated command line arguments, `julia_cmd()[1]` can be used.
158160
159161
!!! compat "Julia 1.1"
@@ -243,7 +245,7 @@ function julia_cmd(julia=joinpath(Sys.BINDIR, julia_exename()); cpu_target::Unio
243245
if opts.use_pkgimages == 0
244246
push!(addflags, "--pkgimages=no")
245247
end
246-
return `$julia -C$cpu_target -J$image_file $addflags`
248+
return `$julia -C $cpu_target -J$image_file $addflags`
247249
end
248250

249251
function julia_exename()

test/cmdlineargs.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ end
7777
opts = Base.JLOptions()
7878

7979
for (arg, default) in (
80-
("-C$(unsafe_string(opts.cpu_target))", false),
80+
# Use a Cmd to handle space nicely when
81+
# interpolating inside another Cmd.
82+
(`-C $(unsafe_string(opts.cpu_target))`, false),
8183

8284
("-J$(unsafe_string(opts.image_file))", false),
8385

@@ -134,13 +136,21 @@ end
134136
("--pkgimages=no", false),
135137
)
136138
@testset "$arg" begin
139+
str = arg isa Cmd ? join(arg.exec, ' ') : arg
137140
if default
138-
@test !occursin(arg, get_julia_cmd(arg))
141+
@test !occursin(str, get_julia_cmd(arg))
139142
else
140-
@test occursin(arg, get_julia_cmd(arg))
143+
@test occursin(str, get_julia_cmd(arg))
141144
end
142145
end
143146
end
147+
148+
# Test empty `cpu_target` gives a helpful error message, issue #52209.
149+
io = IOBuffer()
150+
p = run(pipeline(`$(Base.julia_cmd(; cpu_target="")) --startup-file=no -e ''`; stderr=io); wait=false)
151+
wait(p)
152+
@test p.exitcode == 1
153+
@test occursin("empty CPU name", String(take!(io)))
144154
end
145155

146156
let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`

0 commit comments

Comments
 (0)