Skip to content

Commit 393d670

Browse files
committed
Add Preferences.jl compat shims for Julia v1.3-1.5
1 parent 08dc949 commit 393d670

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

src/products/executable_generators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ macro init_executable_product(product_name, product_path)
6262
path_name = Symbol(string(product_name, "_path"))
6363
return esc(quote
6464
# Locate the executable on-disk, store into $(path_name)
65-
global $(path_name) = @load_preference($(preference_name), joinpath(artifact_dir, $(product_path)))
65+
global $(path_name) = $(emit_preference_path_load(preference_name, product_path))
6666

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

src/products/file_generators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ macro init_file_product(product_name, product_path)
1616
path_name = Symbol(string(product_name, "_path"))
1717
return esc(quote
1818
# FileProducts are very simple, and we maintain the `_path` suffix version for consistency
19-
global $(path_name) = @load_preference($(preference_name), joinpath(artifact_dir, $(product_path)))
19+
global $(path_name) = $(emit_preference_path_load(preference_name, product_path))
2020
global $(product_name) = $(path_name)
2121
end)
2222
end

src/products/library_generators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ macro init_library_product(product_name, product_path, dlopen_flags)
4343
path_name = Symbol(string(product_name, "_path"))
4444
preference_name = string(product_name, "_path")
4545
return excat(quote
46-
global $(path_name) = @load_preference($(preference_name), joinpath(artifact_dir, $(product_path)))
46+
global $(path_name) = $(emit_preference_path_load(preference_name, product_path))
4747
# Manually `dlopen()` this right now so that future invocations
4848
# of `ccall` with its path/SONAME will find this path immediately.
4949
# dlopen_flags === nothing means to not dlopen the library.

src/wrapper_generators.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,22 @@ 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+
with the given default value. On Julia 1.5-, simply emits the default value.
59+
"""
60+
function emit_preference_path_load(pref_name, product_path)
61+
# Can't use `Preferences.jl` on older Julias, just always use the default value in that case
62+
if VERSION < v"1.6.0-DEV"
63+
return quote
64+
joinpath(artifact_dir, $(product_path))
65+
end
66+
end
67+
return quote
68+
@load_preference($(pref_name), joinpath(artifact_dir, $(product_path)))
69+
end
70+
end

test/runtests.jl

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
using JLLWrappers
2-
using Pkg, Preferences
2+
using Pkg
33
using Test
44

5+
@static if VERSION >= v"1.6.0-DEV"
6+
using Preferences
7+
end
8+
59
module TestJLL end
610

711
@testset "JLLWrappers.jl" begin
812
mktempdir() do dir
913
Pkg.activate(dir)
1014

1115
# Prepare some overrides for various products
12-
set_preferences!(joinpath(dir, "LocalPreferences.toml"), "Vulkan_Headers_jll", "vulkan_hpp_path" => "foo")
13-
set_preferences!(joinpath(dir, "LocalPreferences.toml"), "HelloWorldC_jll", "goodbye_world" => "goodbye")
14-
set_preferences!(joinpath(dir, "LocalPreferences.toml"), "OpenLibm_jll", "libnonexisting_path" => "libreallynonexisting")
16+
@static if VERSION >= v"1.6.0-DEV"
17+
set_preferences!(joinpath(dir, "LocalPreferences.toml"), "Vulkan_Headers_jll", "vulkan_hpp_path" => "foo")
18+
set_preferences!(joinpath(dir, "LocalPreferences.toml"), "HelloWorldC_jll", "goodbye_world" => "goodbye")
19+
set_preferences!(joinpath(dir, "LocalPreferences.toml"), "OpenLibm_jll", "libnonexisting_path" => "libreallynonexisting")
20+
end
1521

1622
# Package with a FileProduct
1723
Pkg.develop(PackageSpec(path=joinpath(@__DIR__, "Vulkan_Headers_jll")))
@@ -20,9 +26,15 @@ module TestJLL end
2026
@test isfile(@eval TestJLL vk_xml)
2127
@test isfile(@eval TestJLL Vulkan_Headers_jll.vk_xml_path)
2228
@test isfile(@eval TestJLL Vulkan_Headers_jll.get_vk_xml_path())
23-
@test !isfile(@eval TestJLL vulkan_hpp)
24-
@test !isfile(@eval TestJLL Vulkan_Headers_jll.vulkan_hpp_path)
25-
@test !isfile(@eval TestJLL Vulkan_Headers_jll.get_vulkan_hpp_path())
29+
@static if VERSION >= v"1.6.0-DEV"
30+
@test !isfile(@eval TestJLL vulkan_hpp)
31+
@test !isfile(@eval TestJLL Vulkan_Headers_jll.vulkan_hpp_path)
32+
@test !isfile(@eval TestJLL Vulkan_Headers_jll.get_vulkan_hpp_path())
33+
else
34+
@test isfile(@eval TestJLL vulkan_hpp)
35+
@test isfile(@eval TestJLL Vulkan_Headers_jll.vulkan_hpp_path)
36+
@test isfile(@eval TestJLL Vulkan_Headers_jll.get_vulkan_hpp_path())
37+
end
2638
@test isdir(@eval TestJLL Vulkan_Headers_jll.artifact_dir)
2739
@test isempty(@eval TestJLL Vulkan_Headers_jll.PATH[])
2840
@test occursin(Sys.BINDIR, @eval TestJLL Vulkan_Headers_jll.LIBPATH[])
@@ -42,6 +54,11 @@ module TestJLL end
4254
@test occursin(Sys.BINDIR, @eval TestJLL HelloWorldC_jll.LIBPATH[])
4355
@test !isfile(@eval TestJLL HelloWorldC_jll.goodbye_world_path)
4456
@test !isfile(@eval TestJLL HelloWorldC_jll.get_goodbye_world_path())
57+
@static if VERSION >= v"1.6.0-DEV"
58+
@test basename(@eval TestJLL HelloWorldC_jll.get_goodbye_world_path()) == "goodbye"
59+
else
60+
@test basename(@eval TestJLL HelloWorldC_jll.get_goodbye_world_path()) == "goodbye_world"
61+
end
4562
end
4663

4764
# Package with a LibraryProduct
@@ -55,7 +72,12 @@ module TestJLL end
5572
@test isempty(@eval TestJLL OpenLibm_jll.PATH[])
5673
@test occursin(Sys.BINDIR, @eval TestJLL OpenLibm_jll.LIBPATH[])
5774
@test C_NULL == @eval TestJLL OpenLibm_jll.libnonexisting_handle
58-
@test @eval TestJLL OpenLibm_jll.libnonexisting_path == "libreallynonexisting"
75+
76+
@static if VERSION >= v"1.6.0-DEV"
77+
@test @eval TestJLL OpenLibm_jll.libnonexisting_path == "libreallynonexisting"
78+
else
79+
@test startswith(basename(@eval TestJLL OpenLibm_jll.libnonexisting_path), "libnonexisting")
80+
end
5981

6082
# Issue #20
6183
if Sys.iswindows()

0 commit comments

Comments
 (0)