Skip to content

Commit e0e0e40

Browse files
committed
Avoid hardcoding paths in Profile and Sys
Current code fails when using custom paths. Save directory where Julia source is stored during build in `SOURCEDIR` instead of assuming it can be computed from `BINDIR` (new name chosen to avoid confusing with `build_dir` which is different). Use `DATAROOTDIR` and `DATAROOT` instead of hardcoding `usr/share/` and `share/`. Fix/continuation of #56601, #56627.
1 parent 78ba3be commit e0e0e40

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

base/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ endif
7171
@printf "%s\n" "const PRIVATE_LIBDIR = "$(call shell_escape,$(call julia_escape,$(call normalize_path,$(private_libdir_rel)))) >> $@
7272
@printf "%s\n" "const PRIVATE_LIBEXECDIR = "$(call shell_escape,$(call julia_escape,$(call normalize_path,$(private_libexecdir_rel)))) >> $@
7373
@printf "%s\n" "const INCLUDEDIR = "$(call shell_escape,$(call julia_escape,$(call normalize_path,$(includedir_rel)))) >> $@
74+
@printf "%s\n" "const SOURCEDIR = "$(call shell_escape,$(call julia_escape,$(call normalize_path,$(JULIAHOME)))) >> $@
7475
ifeq ($(DARWIN_FRAMEWORK), 1)
7576
@printf "%s\n" "const DARWIN_FRAMEWORK = true" >> $@
7677
@printf "%s\n" "const DARWIN_FRAMEWORK_NAME = \"$(FRAMEWORK_NAME)\"" >> $@

base/sysinfo.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export BINDIR,
4141
which,
4242
detectwsl
4343

44-
import ..Base: show
44+
import ..Base: DATAROOTDIR, show
4545

4646
"""
4747
Sys.BINDIR::String
@@ -55,12 +55,10 @@ global BINDIR::String = ccall(:jl_get_julia_bindir, Any, ())::String
5555
5656
A string containing the full path to the directory containing the `stdlib` packages.
5757
"""
58-
global STDLIB::String = "$BINDIR/../share/julia/stdlib/v$(VERSION.major).$(VERSION.minor)" # for bootstrap
58+
global STDLIB::String = "$BINDIR/$DATAROOTDIR/julia/stdlib/v$(VERSION.major).$(VERSION.minor)" # for bootstrap
5959
# In case STDLIB change after julia is built, the variable below can be used
6060
# to update cached method locations to updated ones.
6161
const BUILD_STDLIB_PATH = STDLIB
62-
# Similarly, this is the root of the julia repo directory that julia was built from
63-
const BUILD_ROOT_PATH = "$BINDIR/../.."
6462

6563
# helper to avoid triggering precompile warnings
6664

@@ -179,7 +177,7 @@ end
179177
function __init_build()
180178
global BINDIR = ccall(:jl_get_julia_bindir, Any, ())::String
181179
vers = "v$(string(VERSION.major)).$(string(VERSION.minor))"
182-
global STDLIB = abspath(BINDIR, "..", "share", "julia", "stdlib", vers)
180+
global STDLIB = abspath(BINDIR, DATAROOTDIR, "julia", "stdlib", vers)
183181
nothing
184182
end
185183

stdlib/Profile/src/Profile.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,7 @@ function flatten(data::Vector, lidict::LineInfoDict)
538538
return (newdata, newdict)
539539
end
540540

541-
const SRC_DIR = normpath(joinpath(Sys.BUILD_ROOT_PATH, "src"))
542-
const COMPILER_DIR = "../usr/share/julia/Compiler/"
541+
const SRC_DIR = normpath(Base.SOURCEDIR, "src")
543542

544543
# Take a file-system path and try to form a concise representation of it
545544
# based on the package ecosystem
@@ -548,17 +547,18 @@ function short_path(spath::Symbol, filenamecache::Dict{Symbol, Tuple{String,Stri
548547
return get!(filenamecache, spath) do
549548
path = Base.fixup_stdlib_path(string(spath))
550549
path_norm = normpath(path)
551-
possible_base_path = normpath(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "base", path))
550+
possible_base_path = normpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "base", path)
552551
lib_dir = abspath(Sys.BINDIR, Base.LIBDIR)
552+
compiler_dir = joinpath(Base.DATAROOT, "julia", "Compiler")
553553
if startswith(path_norm, SRC_DIR)
554554
remainder = only(split(path_norm, SRC_DIR, keepempty=false))
555555
return (isfile(path_norm) ? path_norm : ""), "@juliasrc", remainder
556556
elseif startswith(path_norm, lib_dir)
557557
remainder = only(split(path_norm, lib_dir, keepempty=false))
558558
return (isfile(path_norm) ? path_norm : ""), "@julialib", remainder
559-
elseif contains(path, COMPILER_DIR)
560-
remainder = split(path, COMPILER_DIR, keepempty=false)[end]
561-
possible_compiler_path = normpath(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "Compiler", remainder))
559+
elseif startswith(path_norm, compiler_dir)
560+
remainder = split(path, compiler_dir, keepempty=false)[end]
561+
possible_compiler_path = normpath(Sys.BINDIR, Base.DATAROOT, "julia", "Compiler", remainder)
562562
return (isfile(possible_compiler_path) ? possible_compiler_path : ""), "@Compiler", remainder
563563
elseif isabspath(path)
564564
if ispath(path)

test/buildkitetestjson.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ end
8888
# to be able to identify the file. Also convert Windows-style paths to Unix-style paths so tests can
8989
# be grouped by file.
9090
const generalize_file_paths_cache = Dict{AbstractString,AbstractString}()
91-
const norm_build_root_path = normpath(Sys.BUILD_ROOT_PATH)
91+
const norm_sourcedir = normpath(Base.SOURCEDIR)
9292
const bindir_dir = dirname(Sys.BINDIR)
9393
const pathsep = Sys.iswindows() ? '\\' : '/'
9494
function generalize_file_paths(path::AbstractString)
9595
return get!(generalize_file_paths_cache, path) do
9696
path = replace(path,
9797
Sys.STDLIB => "stdlib",
98-
string(norm_build_root_path, pathsep) => "",
98+
string(norm_sourcedir, pathsep) => "",
9999
string(bindir_dir, pathsep) => ""
100100
)
101101
@static if Sys.iswindows()

0 commit comments

Comments
 (0)