Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More helpful error message for empty cpu_target in Base.julia_cmd #52217

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`, 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
16 changes: 13 additions & 3 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ end
opts = Base.JLOptions()

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

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

Expand Down Expand Up @@ -134,13 +136,21 @@ end
("--pkgimages=no", false),
)
@testset "$arg" begin
str = arg isa Cmd ? join(arg.exec, ' ') : arg
if default
@test !occursin(arg, get_julia_cmd(arg))
@test !occursin(str, get_julia_cmd(arg))
else
@test occursin(arg, get_julia_cmd(arg))
@test occursin(str, get_julia_cmd(arg))
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