Skip to content

Commit

Permalink
More helpful error message for empty cpu_target in Base.julia_cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Nov 18, 2023
1 parent e75dd47 commit ce15f83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit ce15f83

Please sign in to comment.