Skip to content

Commit cf7cdd2

Browse files
committed
More helpful error message for empty cpu_target in Base.julia_cmd
1 parent e75dd47 commit cf7cdd2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ end
141141
end
142142
end
143143
end
144+
145+
# Test empty `cpu_target` gives a helpful error message, issue #52209.
146+
io = IOBuffer()
147+
p = run(pipeline(`$(Base.julia_cmd(; cpu_target="")) --startup-file=no -e ''`; stderr=io); wait=false)
148+
wait(p)
149+
@test p.exitcode == 1
150+
@test occursin("empty CPU name", String(take!(io)))
144151
end
145152

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

0 commit comments

Comments
 (0)