Skip to content

Request: Add an API for configuring julia_cmd #30065

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ function __init__()
# Base library init
reinit_stdio()
Multimedia.reinit_displays() # since Multimedia.displays uses stdout as fallback
set_julia_basecmd()
# initialize loading
init_depot_path()
init_load_path()
Expand Down
40 changes: 39 additions & 1 deletion base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,18 @@ printstyled(io::IO, msg...; bold::Bool=false, color::Union{Int,Symbol}=:normal)
printstyled(msg...; bold::Bool=false, color::Union{Int,Symbol}=:normal) =
printstyled(stdout, msg...; bold=bold, color=color)

function julia_cmd(julia=joinpath(Sys.BINDIR::String, julia_exename()))
"""
julia_cmd([julia]) -> Cmd

Return a [`Cmd`](@ref) that can be used to launch a `julia` program
that inherits the command line options of the current executing
process. An optional argument can be passed to specify the `julia`
program to be used instead of [`julia_basecmd`](@ref). Note that
package load path settings are not automatically reflected in the
launched process. Use [`Base.load_path_setup_code`](@ref) to
replicate the load paths.
"""
function julia_cmd(julia=julia_basecmd())
opts = JLOptions()
cpu_target = unsafe_string(opts.cpu_target)
image_file = unsafe_string(opts.image_file)
Expand Down Expand Up @@ -436,6 +447,33 @@ function julia_exename()
end
end

"""
default_julia_basecmd() -> Cmd

Default `julia` executable and options.
"""
default_julia_basecmd() = `$(joinpath(Sys.BINDIR::String, julia_exename()))`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the type assert on Sys.BINDIR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it from how julia_cmd determines the path to julia in the current master:

function julia_cmd(julia=joinpath(Sys.BINDIR::String, julia_exename()))

My guess was this is because Sys.BINDIR is a global and may be set to non-String object.

I also noticed Sys.__init__ had the same type assertion:

global BINDIR = ccall(:jl_get_julia_bindir, Any, ())::String


const _julia_basecmd = Ref(``)

"""
julia_basecmd() -> Cmd

Julia executable which is used by [`julia_cmd`](@ref). It may be
changed by [`set_julia_basecmd`](@ref).
"""
julia_basecmd() = _julia_basecmd[]

"""
set_julia_basecmd([path::Cmd])

Set the Julia executable used by [`julia_cmd`](@ref). Reset to default
when no argument is given.
"""
function set_julia_basecmd(cmd::Cmd = default_julia_basecmd())
_julia_basecmd[] = cmd
end

"""
securezero!(o)

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/Distributed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Base: getindex, wait, put!, take!, fetch, isready, push!, length,

# imports for use
using Base: Process, Semaphore, JLOptions, AnyDict, buffer_writes, wait_connected,
VERSION_STRING, binding_module, notify_error, atexit, julia_exename,
VERSION_STRING, binding_module, notify_error, atexit, julia_basecmd,
julia_cmd, AsyncGenerator, acquire, release, invokelatest,
shell_escape_posixly, uv_error, something, notnothing

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ end
default_addprocs_params() = AnyDict(
:topology => :all_to_all,
:dir => pwd(),
:exename => joinpath(Sys.BINDIR, julia_exename()),
:exename => julia_basecmd(),
:exeflags => ``,
:enable_threaded_blas => false,
:lazy => true)
Expand Down