Skip to content

Commit

Permalink
Base: add new help function isdebugbuild (JuliaLang#47475)
Browse files Browse the repository at this point in the history
* Base: add new help function `isdebugbuild`

* isdebugbuild: replace ccall with new fucntion

* isdebugbuild: fix typo in docstring
  • Loading branch information
inkydragon committed Nov 7, 2022
1 parent 4937986 commit 9182326
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 12 deletions.
11 changes: 10 additions & 1 deletion base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function julia_cmd(julia=joinpath(Sys.BINDIR, julia_exename()))
end

function julia_exename()
if ccall(:jl_is_debugbuild, Cint, ()) == 0
if !Base.isdebugbuild()
return @static Sys.iswindows() ? "julia.exe" : "julia"
else
return @static Sys.iswindows() ? "julia-debug.exe" : "julia-debug"
Expand Down Expand Up @@ -666,3 +666,12 @@ function runtests(tests = ["all"]; ncores::Int = ceil(Int, Sys.CPU_THREADS / 2),
"including error messages above and the output of versioninfo():\n$(read(buf, String))")
end
end

"""
isdebugbuild()
Return `true` if julia is a debug version.
"""
function isdebugbuild()
return ccall(:jl_is_debugbuild, Cint, ()) != 0
end
2 changes: 1 addition & 1 deletion contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ if Artifacts !== nothing
artifacts = Artifacts.load_artifacts_toml(artifacts_toml)
platforms = [Artifacts.unpack_platform(e, "HelloWorldC", artifacts_toml) for e in artifacts["HelloWorldC"]]
best_platform = select_platform(Dict(p => triplet(p) for p in platforms))
dlopen("libjulia$(ccall(:jl_is_debugbuild, Cint, ()) != 0 ? "-debug" : "")", RTLD_LAZY | RTLD_DEEPBIND)
dlopen("libjulia$(Base.isdebugbuild() ? "-debug" : "")", RTLD_LAZY | RTLD_DEEPBIND)
"""
end

Expand Down
6 changes: 3 additions & 3 deletions contrib/julia-config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function shell_escape(str)
end

function libDir()
return if ccall(:jl_is_debugbuild, Cint, ()) != 0
return if Base.isdebugbuild()
if Base.DARWIN_FRAMEWORK
joinpath(dirname(abspath(Libdl.dlpath(Base.DARWIN_FRAMEWORK_NAME * "_debug"))),"lib")
else
Expand All @@ -33,7 +33,7 @@ function libDir()
end

function frameworkDir()
libjulia = ccall(:jl_is_debugbuild, Cint, ()) != 0 ?
libjulia = Base.isdebugbuild() ?
Libdl.dlpath(Base.DARWIN_FRAMEWORK_NAME * "_debug") :
Libdl.dlpath(Base.DARWIN_FRAMEWORK_NAME)
normpath(joinpath(dirname(abspath(libjulia)),"..","..",".."))
Expand Down Expand Up @@ -61,7 +61,7 @@ function ldlibs(doframework)
# If the user wants the debug framework, DYLD_IMAGE_SUFFIX=_debug
# should be used (refer to man 1 dyld).
doframework && return "-framework $(Base.DARWIN_FRAMEWORK_NAME)"
libname = if ccall(:jl_is_debugbuild, Cint, ()) != 0
libname = if Base.isdebugbuild()
"julia-debug"
else
"julia"
Expand Down
2 changes: 1 addition & 1 deletion stdlib/InteractiveUtils/src/InteractiveUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function versioninfo(io::IO=stdout; verbose::Bool=false)
if !isempty(Base.GIT_VERSION_INFO.commit_short)
println(io, "Commit $(Base.GIT_VERSION_INFO.commit_short) ($(Base.GIT_VERSION_INFO.date_string))")
end
if ccall(:jl_is_debugbuild, Cint, ())!=0
if Base.isdebugbuild()
println(io, "DEBUG build")
end
println(io, "Platform Info:")
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Libdl/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ cd(@__DIR__) do
# Find the library directory by finding the path of libjulia-internal (or libjulia-internal-debug,
# as the case may be) to get the private library directory
private_libdir = if Base.DARWIN_FRAMEWORK
if ccall(:jl_is_debugbuild, Cint, ()) != 0
if Base.isdebugbuild()
dirname(abspath(Libdl.dlpath(Base.DARWIN_FRAMEWORK_NAME * "_debug")))
else
joinpath(dirname(abspath(Libdl.dlpath(Base.DARWIN_FRAMEWORK_NAME))),"Frameworks")
end
elseif ccall(:jl_is_debugbuild, Cint, ()) != 0
elseif Base.isdebugbuild()
dirname(abspath(Libdl.dlpath("libjulia-internal-debug")))
else
dirname(abspath(Libdl.dlpath("libjulia-internal")))
Expand Down
4 changes: 2 additions & 2 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,9 @@ end
# to use as a dummy shlib to open
libjulia = if Base.DARWIN_FRAMEWORK
abspath(Libdl.dlpath(Base.DARWIN_FRAMEWORK_NAME *
(ccall(:jl_is_debugbuild, Cint, ()) != 0 ? "_debug" : "")))
(Base.isdebugbuild() ? "_debug" : "")))
else
abspath(Libdl.dlpath((ccall(:jl_is_debugbuild, Cint, ()) != 0) ? "libjulia-debug" : "libjulia"))
abspath(Libdl.dlpath(Base.isdebugbuild() ? "libjulia-debug" : "libjulia"))
end


Expand Down
2 changes: 1 addition & 1 deletion test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const opt_level = Base.JLOptions().opt_level
const coverage = (Base.JLOptions().code_coverage > 0) || (Base.JLOptions().malloc_log > 0)
const Iptr = sizeof(Int) == 8 ? "i64" : "i32"

const is_debug_build = ccall(:jl_is_debugbuild, Cint, ()) != 0
const is_debug_build = Base.isdebugbuild()
function libjulia_codegen_name()
is_debug_build ? "libjulia-codegen-debug" : "libjulia-codegen"
end
Expand Down
2 changes: 1 addition & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ for l in (Threads.SpinLock(), ReentrantLock())
@test get_finalizers_inhibited() == 1
GC.enable_finalizers(true)
@test get_finalizers_inhibited() == 0
if ccall(:jl_is_debugbuild, Cint, ()) != 0
if Base.isdebugbuild()
# Note this warning only exists in debug builds
@test_warn "WARNING: GC finalizers already enabled on this thread." GC.enable_finalizers(true)
end
Expand Down

0 comments on commit 9182326

Please sign in to comment.