Skip to content

Commit

Permalink
Handle empty cpu_target in Base.julia_cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Nov 17, 2023
1 parent 20440fd commit 2b3cc15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 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 All @@ -168,7 +170,7 @@ To get the julia command without propagated command line arguments, `julia_cmd()
"""
function julia_cmd(julia=joinpath(Sys.BINDIR, julia_exename()); cpu_target::Union{Nothing,String} = nothing)
opts = JLOptions()
if cpu_target === nothing
if cpu_target === nothing || isempty(cpu_target)
cpu_target = unsafe_string(opts.cpu_target)
end
image_file = unsafe_string(opts.image_file)
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
5 changes: 5 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ end
end
end
end

# Test nothing or empty string `cpu_target`, issue #52209.
for cpu_target in (nothing, "")
@test success(`$(Base.julia_cmd(; cpu_target=$(cpu_target))) --startup-file=no -e ''`)
end
end

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

0 comments on commit 2b3cc15

Please sign in to comment.