Skip to content

Commit 11ddbff

Browse files
authored
Merge pull request #27 from JuliaPackaging/sf/preferences
2 parents 4eaa196 + c2bec03 commit 11ddbff

24 files changed

+171
-45
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
/Manifest.toml
33
/dev/
4+
.vscode/

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
name = "JLLWrappers"
22
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
33
authors = ["Mosè Giordano", "Elliot Saba"]
4-
version = "1.2.0"
4+
version = "1.3.0"
55

66
[compat]
77
julia = "1.0.0"
88

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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,27 @@ function declare_new_executable_product(product_name)
4949
end
5050

5151
macro declare_executable_product(product_name)
52+
path_name = string(product_name, "_path")
5253
return excat(
5354
# We will continue to support `withenv`-style for as long as we must
5455
declare_old_executable_product(product_name),
5556
# We will, however, urge users to move to the thread-safe `addenv`-style on Julia 1.6+
5657
declare_new_executable_product(product_name),
58+
# Perform a compile-time load of a path preference override
59+
:($(Symbol(path_name)) = $(emit_preference_path_load(path_name))),
5760
)
5861
end
5962

6063
macro init_executable_product(product_name, product_path)
6164
path_name = Symbol(string(product_name, "_path"))
6265
return esc(quote
66+
global $(path_name)
6367
# Locate the executable on-disk, store into $(path_name)
64-
global $(path_name) = joinpath(artifact_dir, $(product_path))
68+
if $(path_name) === nothing
69+
$(path_name) = joinpath(artifact_dir, $(product_path))
70+
end
6571

6672
# Add this executable's directory onto the list of PATH's that we'll need to expose to dependents
67-
push!(PATH_list, joinpath(artifact_dir, $(dirname(product_path))))
73+
push!(PATH_list, dirname($(path_name)))
6874
end)
6975
end

src/products/file_generators.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ macro declare_file_product(product_name)
33
path_name = Symbol(string(product_name, "_path"))
44
return esc(quote
55
# These will be filled in by init_file_product().
6-
$(path_name) = ""
6+
$(path_name) = $(emit_preference_path_load(string(product_name, "_path")))
77
$(product_name) = ""
88
function $(get_path_name)()
99
return $(path_name)::String
@@ -14,8 +14,11 @@ end
1414
macro init_file_product(product_name, product_path)
1515
path_name = Symbol(string(product_name, "_path"))
1616
return esc(quote
17+
global $(path_name)
1718
# FileProducts are very simple, and we maintain the `_path` suffix version for consistency
18-
global $(path_name) = joinpath(artifact_dir, $(product_path))
19+
if $(path_name) === nothing
20+
$(path_name) = joinpath(artifact_dir, $(product_path))
21+
end
1922
global $(product_name) = $(path_name)
2023
end)
2124
end

src/products/library_generators.jl

Lines changed: 8 additions & 17 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"))
@@ -31,7 +18,7 @@ macro declare_library_product(product_name, product_soname)
3118
quote
3219
# These will be filled in by init_library_product()
3320
$(handle_name) = C_NULL
34-
$(path_name) = ""
21+
$(path_name) = $(emit_preference_path_load(string(product_name, "_path")))
3522
function $(get_path_name)()
3623
return $(path_name)::String
3724
end
@@ -53,15 +40,19 @@ end
5340

5441
macro init_library_product(product_name, product_path, dlopen_flags)
5542
handle_name = Symbol(string(product_name, "_handle"))
56-
path_name = Symbol(string(product_name, "_path"))
43+
preference_name = string(product_name, "_path")
44+
path_name = Symbol(preference_name)
5745
return excat(quote
58-
global $(path_name) = joinpath(artifact_dir, $(product_path))
46+
global $(path_name)
47+
if $(path_name) === nothing
48+
$(path_name) = joinpath(artifact_dir, $(product_path))
49+
end
5950
# Manually `dlopen()` this right now so that future invocations
6051
# of `ccall` with its path/SONAME will find this path immediately.
6152
# dlopen_flags === nothing means to not dlopen the library.
6253
if $(dlopen_flags) !== nothing
6354
global $(handle_name) = dlopen($(path_name), $(dlopen_flags))
64-
push!(LIBPATH_list, joinpath(artifact_dir, $(dirname(product_path))))
55+
push!(LIBPATH_list, dirname($(path_name)))
6556
end
6657
end,
6758
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

src/wrapper_generators.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,23 @@ macro generate_init_footer()
4949
LIBPATH[] = join(vcat(LIBPATH_list, Base.invokelatest(JLLWrappers.get_julia_libpaths))::Vector{String}, $(pathsep))
5050
end)
5151
end
52+
53+
54+
"""
55+
emit_preference_path_load(pref_name, default_value)
56+
57+
On Julia 1.6+, emits a `load_preference()` call for the given preference name,
58+
returning `nothing` if it is not loaded. On Julia v1.5-, always returns `nothing`.
59+
"""
60+
function emit_preference_path_load(pref_name)
61+
# Can't use `Preferences.jl` on older Julias, just always use the default value in that case
62+
@static if VERSION < v"1.6.0-DEV"
63+
return quote
64+
nothing
65+
end
66+
else
67+
return quote
68+
@load_preference($(pref_name), nothing)
69+
end
70+
end
71+
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__()

0 commit comments

Comments
 (0)