Skip to content

Commit 4dcf06f

Browse files
committed
Add Preferences overrides for product paths
This adds a `@load_preferences()` lookup that defaults to the artifact-local location for products, but can be overridden to arbitrary paths, including system-wide searches by writing out just the SONAME of the desired library.
1 parent f88b1cf commit 4dcf06f

22 files changed

+114
-41
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ julia = "1.0.0"
99
[extras]
1010
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1111
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
12+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1213

1314
[targets]
14-
test = ["Pkg", "Test"]
15+
test = ["Pkg", "Test", "Preferences"]

src/products/executable_generators.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ macro declare_executable_product(product_name)
5858
end
5959

6060
macro init_executable_product(product_name, product_path)
61+
preference_name = string(product_name, "_path")
6162
path_name = Symbol(string(product_name, "_path"))
6263
return esc(quote
6364
# Locate the executable on-disk, store into $(path_name)
64-
global $(path_name) = joinpath(artifact_dir, $(product_path))
65+
global $(path_name) = @load_preference($(preference_name), joinpath(artifact_dir, $(product_path)))
6566

6667
# Add this executable's directory onto the list of PATH's that we'll need to expose to dependents
6768
push!(PATH_list, joinpath(artifact_dir, $(dirname(product_path))))

src/products/file_generators.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ macro declare_file_product(product_name)
1212
end
1313

1414
macro init_file_product(product_name, product_path)
15+
preference_name = string(product_name, "_path")
1516
path_name = Symbol(string(product_name, "_path"))
1617
return esc(quote
1718
# FileProducts are very simple, and we maintain the `_path` suffix version for consistency
18-
global $(path_name) = joinpath(artifact_dir, $(product_path))
19+
global $(path_name) = @load_preference($(preference_name), joinpath(artifact_dir, $(product_path)))
1920
global $(product_name) = $(path_name)
2021
end)
2122
end

src/products/library_generators.jl

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
2-
function declare_old_library_product(product_name, product_soname)
3-
return esc(quote
4-
5-
end)
6-
end
7-
8-
function declare_new_library_product(product_name)
9-
handle_name = Symbol(string(product_name, "_handle"))
10-
get_path_name = Symbol(string("get_", product_name, "_path"))
11-
path_name = Symbol(string(product_name, "_path"))
12-
end
13-
141
macro declare_library_product(product_name, product_soname)
152
handle_name = Symbol(string(product_name, "_handle"))
163
get_path_name = Symbol(string("get_", product_name, "_path"))
@@ -54,14 +41,15 @@ end
5441
macro init_library_product(product_name, product_path, dlopen_flags)
5542
handle_name = Symbol(string(product_name, "_handle"))
5643
path_name = Symbol(string(product_name, "_path"))
44+
preference_name = string(product_name, "_path")
5745
return excat(quote
58-
global $(path_name) = joinpath(artifact_dir, $(product_path))
46+
global $(path_name) = @load_preference($(preference_name), joinpath(artifact_dir, $(product_path)))
5947
# Manually `dlopen()` this right now so that future invocations
6048
# of `ccall` with its path/SONAME will find this path immediately.
6149
# dlopen_flags === nothing means to not dlopen the library.
6250
if $(dlopen_flags) !== nothing
6351
global $(handle_name) = dlopen($(path_name), $(dlopen_flags))
64-
push!(LIBPATH_list, joinpath(artifact_dir, $(dirname(product_path))))
52+
push!(LIBPATH_list, dirname($(path_name)))
6553
end
6654
end,
6755
init_new_library_product(product_name),

src/toplevel_generators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function generate_imports(src_name)
3333
HostPlatform() = platform_key_abi()
3434
end
3535
else
36-
# Use fast stdlib-based Artifacts
36+
# Use fast stdlib-based Artifacts + Preferences
3737
return quote
38-
using Libdl, Artifacts, Base.BinaryPlatforms
38+
using Libdl, Artifacts, Preferences, Base.BinaryPlatforms
3939
using Artifacts: load_artifacts_toml, unpack_platform
4040
using Base.BinaryPlatforms: triplet, select_platform
4141
end

test/HelloWorldC_jll/Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ uuid = "dca1746e-5efc-54fc-8249-22745bc95a49"
33
version = "1.0.11+1"
44

55
[deps]
6+
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
67
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
7-
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
88
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
9-
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
9+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
10+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1011

1112
[compat]
1213
julia = "1.0"
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Autogenerated wrapper script for HelloWorldC_jll for aarch64-linux-gnu
2-
export hello_world
2+
export hello_world, goodbye_world
33

44
JLLWrappers.@generate_wrapper_header("HelloWorldC")
55
JLLWrappers.@declare_executable_product(hello_world)
6+
JLLWrappers.@declare_executable_product(goodbye_world)
67
function __init__()
78
JLLWrappers.@generate_init_header()
89
JLLWrappers.@init_executable_product(
910
hello_world,
1011
"bin/hello_world",
1112
)
13+
JLLWrappers.@init_executable_product(
14+
goodbye_world,
15+
"bin/goodbye_world",
16+
)
1217

1318
JLLWrappers.@generate_init_footer()
1419
end # __init__()
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Autogenerated wrapper script for HelloWorldC_jll for aarch64-linux-musl
2-
export hello_world
2+
export hello_world, goodbye_world
33

44
JLLWrappers.@generate_wrapper_header("HelloWorldC")
55
JLLWrappers.@declare_executable_product(hello_world)
6+
JLLWrappers.@declare_executable_product(goodbye_world)
67
function __init__()
78
JLLWrappers.@generate_init_header()
89
JLLWrappers.@init_executable_product(
910
hello_world,
1011
"bin/hello_world",
1112
)
13+
JLLWrappers.@init_executable_product(
14+
goodbye_world,
15+
"bin/goodbye_world",
16+
)
1217

1318
JLLWrappers.@generate_init_footer()
1419
end # __init__()
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Autogenerated wrapper script for HelloWorldC_jll for armv7l-linux-gnueabihf
2-
export hello_world
2+
export hello_world, goodbye_world
33

44
JLLWrappers.@generate_wrapper_header("HelloWorldC")
55
JLLWrappers.@declare_executable_product(hello_world)
6+
JLLWrappers.@declare_executable_product(goodbye_world)
67
function __init__()
78
JLLWrappers.@generate_init_header()
89
JLLWrappers.@init_executable_product(
910
hello_world,
1011
"bin/hello_world",
1112
)
13+
JLLWrappers.@init_executable_product(
14+
goodbye_world,
15+
"bin/goodbye_world",
16+
)
1217

1318
JLLWrappers.@generate_init_footer()
1419
end # __init__()
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Autogenerated wrapper script for HelloWorldC_jll for armv7l-linux-musleabihf
2-
export hello_world
2+
export hello_world, goodbye_world
33

44
JLLWrappers.@generate_wrapper_header("HelloWorldC")
55
JLLWrappers.@declare_executable_product(hello_world)
6+
JLLWrappers.@declare_executable_product(goodbye_world)
67
function __init__()
78
JLLWrappers.@generate_init_header()
89
JLLWrappers.@init_executable_product(
910
hello_world,
1011
"bin/hello_world",
1112
)
13+
JLLWrappers.@init_executable_product(
14+
goodbye_world,
15+
"bin/goodbye_world",
16+
)
1217

1318
JLLWrappers.@generate_init_footer()
1419
end # __init__()

0 commit comments

Comments
 (0)