-
Notifications
You must be signed in to change notification settings - Fork 32
/
dependencies.jl
287 lines (255 loc) · 13.9 KB
/
dependencies.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using Test
using Pkg, Base.BinaryPlatforms
using BinaryBuilderBase
using BinaryBuilderBase: getname, getpkg, dependencify, destdir, PKG_VERSIONS, get_addable_spec, cached_git_clone
using JSON
using LibGit2
# Define equality between dependencies, in order to carry out the tests below
Base.:(==)(a::AbstractDependency, b::AbstractDependency) = getpkg(a) == getpkg(b)
function with_temp_project(f::Function)
mktempdir() do dir
Pkg.activate(dir) do
f(dir)
end
end
end
@testset "Dependencies" begin
name = "Foo_jll"
dep = Dependency(PackageSpec(; name = name); platforms=supported_platforms(; experimental=true, exclude=!Sys.isapple))
@test Dependency(name) == dep
@test !is_host_dependency(dep)
@test is_target_dependency(dep)
@test is_build_dependency(dep)
@test is_runtime_dependency(dep)
@test getname(dep) == name
@test getname(PackageSpec(; name = name)) == name
@test getpkg(dep) == PackageSpec(; name = name)
@test getcompat(dep) == ""
build_version = v"1.2.3"
dep_buildver = Dependency(PackageSpec(; name = name), build_version)
@test Dependency(name, build_version) == dep_buildver
@test getname(dep_buildver) == name
@test getpkg(dep_buildver) == PackageSpec(; name = name, version = PKG_VERSIONS.VersionSpec(build_version))
@test getcompat(dep_buildver) == ""
# the same but with compat info
dep_buildver = Dependency(PackageSpec(; name = name), build_version; compat = "~1.2", platforms=[Platform("x86_64", "linux"; cxxstring_abi="cxx11")])
@test Dependency(name, build_version) == dep_buildver
@test getname(dep_buildver) == name
@test getpkg(dep_buildver) == PackageSpec(; name = name, version = PKG_VERSIONS.VersionSpec(build_version))
@test getcompat(dep_buildver) == "~1.2"
# the same but only with compat specifier
dep_compat = Dependency(PackageSpec(; name); compat = "2, ~$(build_version)")
@test Dependency(name, build_version) == dep_compat
@test getname(dep_compat) == name
@test getpkg(dep_compat) == PackageSpec(; name, version = PKG_VERSIONS.VersionSpec(build_version))
@test getcompat(dep_compat) == "2, ~$(build_version)"
# if build_version and compat don't match, an error should be thrown
@test_throws ArgumentError Dependency(PackageSpec(; name = name), build_version, compat = "2.0")
build_name = "Foo_headers_jll"
build_dep = BuildDependency(PackageSpec(; name = build_name))
@test BuildDependency(build_name) == build_dep
@test !is_host_dependency(build_dep)
@test is_target_dependency(build_dep)
@test is_build_dependency(build_dep)
@test !is_runtime_dependency(build_dep)
@test getname(build_dep) == build_name
@test getname(PackageSpec(; name = build_name)) == build_name
@test getpkg(build_dep) == PackageSpec(; name = build_name)
host_name = "Patchelf_jll"
host_dep = HostBuildDependency(PackageSpec(; name = host_name))
@test HostBuildDependency(host_name) == host_dep
@test is_host_dependency(host_dep)
@test !is_target_dependency(host_dep)
@test is_build_dependency(host_dep)
@test !is_runtime_dependency(host_dep)
@test getname(host_dep) == host_name
@test getname(PackageSpec(; name = host_name)) == host_name
@test getpkg(host_dep) == PackageSpec(; name = host_name)
@testset "Filter dependencies by platform" begin
@test filter_platforms([dep, dep_buildver, dep_compat], Platform("x86_64", "linux"; cxxstring_abi="cxx03")) == [dep_compat]
@test filter_platforms([dep, dep_buildver, dep_compat], Platform("x86_64", "macos")) == [dep, dep_compat]
end
@testset "JSON (de)serialization" begin
jdep = JSON.lower(dep)
@test jdep == Dict("type" => "dependency", "name" => name, "uuid" => nothing, "compat" => "", "version-major" => 0x0, "version-minor" => 0x0, "version-patch" => 0x0, "platforms" => ["x86_64-apple-darwin", "aarch64-apple-darwin"])
@test dependencify(jdep) == dep
jdep_buildver = JSON.lower(dep_buildver)
@test jdep_buildver == Dict("type" => "dependency", "name" => name, "uuid" => nothing, "compat" => "~1.2", "version-major" => 0x0, "version-minor" => 0x0, "version-patch" => 0x0, "platforms" => ["x86_64-linux-gnu-cxx11"])
# the build_version is currently not serialized, so the following test fails
@test_broken dependencify(jdep_buildver) == dep_buildver
jbuild_dep = JSON.lower(build_dep)
@test jbuild_dep == Dict("type" => "builddependency", "name" => build_name, "uuid" => nothing, "compat" => "", "version-major" => 0x0, "version-minor" => 0x0, "version-patch" => 0x0, "platforms" => ["any"])
@test dependencify(jbuild_dep) == build_dep
jhost_dep = JSON.lower(host_dep)
@test jhost_dep == Dict("type" => "hostdependency", "name" => host_name, "uuid" => nothing, "compat" => "", "version-major" => 0x0, "version-minor" => 0x0, "version-patch" => 0x0, "platforms" => ["any"])
@test dependencify(jhost_dep) == host_dep
full_dep = Dependency(PackageSpec(; name = "Baz_jll", uuid = "00000000-1111-2222-3333-444444444444", version = PKG_VERSIONS.VersionSpec("3.1.4")))
jfull_dep = JSON.lower(full_dep)
@test jfull_dep == Dict("type" => "dependency", "name" => "Baz_jll", "uuid" => "00000000-1111-2222-3333-444444444444", "compat" => "", "version-major" => 0x3, "version-minor" => 0x1, "version-patch" => 0x4, "platforms" => ["any"])
@test dependencify(jfull_dep) == full_dep
@test_throws ErrorException dependencify(Dict("type" => "git"))
end
@testset "Setup" begin
@test BinaryBuilderBase.get_addable_spec("LLVM_jll", v"13.0.0+2") ==
PackageSpec(
name="LLVM_jll",
uuid="86de99a1-58d6-5da7-8064-bd56ce2e322c",
tree_hash=Base.SHA1("83481d62501cf2ef22bed745dbcedc4e75fa6e95"),
version=PKG_VERSIONS.VersionSpec("*"),
repo=Pkg.Types.GitRepo(
source="https://github.com/JuliaBinaryWrappers/LLVM_jll.jl.git",
rev="2772761b330d51146ace3125b26acdad0df4f30f",
),
)
with_temp_project() do dir
prefix = Prefix(dir)
dependencies = [
Dependency("Zlib_jll")
]
platform = HostPlatform()
ap = @test_logs setup_dependencies(prefix, getpkg.(dependencies), platform)
@test "libz." * platform_dlext(platform) in readdir(last(libdirs(Prefix(destdir(dir, platform)))))
@test "zlib.h" in readdir(joinpath(destdir(dir, platform), "include"))
if os(platform) == "macos"
zlib_log_files = ["Zlib.log.gz", "fix_identity_mismatch_libz.1.2.11.dylib.log.gz", "ldid_libz.1.2.11.dylib.log.gz"]
else
zlib_log_files = ["Zlib.log.gz"]
end
@test readdir(joinpath(destdir(dir, platform), "logs")) == zlib_log_files
# Make sure the directories are emptied by `cleanup_dependencies`
@test_nowarn cleanup_dependencies(prefix, ap, platform)
@test readdir(joinpath(destdir(dir, platform), "include")) == []
@test readdir(joinpath(destdir(dir, platform), "logs")) == []
end
# Setup a dependency of a JLL package which is also a standard library
with_temp_project() do dir
prefix = Prefix(dir)
dependencies = [
Dependency("LibCURL_jll")
]
platform = HostPlatform()
ap = @test_logs setup_dependencies(prefix, getpkg.(dependencies), platform)
@test "libcurl." * platform_dlext(platform) in readdir(last(libdirs(Prefix(destdir(dir, platform)))))
@test "curl.h" in readdir(joinpath(destdir(dir, platform), "include", "curl"))
@test "libssh2." * platform_dlext(platform) in readdir(last(libdirs(Prefix(destdir(dir, platform)))))
# Make sure the directories are emptied by `cleanup_dependencies`
@test_nowarn cleanup_dependencies(prefix, ap, platform)
# This shuld be empty, but the `curl/` directory is left here, empty
@test_broken readdir(joinpath(destdir(dir, platform), "include")) == []
@test readdir(joinpath(destdir(dir, platform), "logs")) == []
end
# Setup a dependency that doesn't have a mapping for the given platform
with_temp_project() do dir
prefix = Prefix(dir)
dependencies = [
Dependency("LibOSXUnwind_jll")
]
platform = Platform("i686", "linux"; libc="musl")
@test_logs (:warn, r"Dependency LibOSXUnwind_jll does not have a mapping for artifact LibOSXUnwind for platform i686-linux-musl") begin
setup_dependencies(prefix, getpkg.(dependencies), platform)
end
@test "destdir" ∉ readdir(dirname(destdir(dir, platform)))
end
# Test setup of dependencies that depend on the Julia version
with_temp_project() do dir
prefix = Prefix(dir)
dependencies = [Dependency("GMP_jll")]
platform = Platform("x86_64", "linux"; julia_version=v"1.5")
# Test that a particular version of GMP is installed
@test_logs setup_dependencies(prefix, getpkg.(dependencies), platform)
@test isfile(joinpath(destdir(dir, platform), "lib", "libgmp.so.10.3.2"))
end
# Next, test on Julia v1.6
with_temp_project() do dir
prefix = Prefix(dir)
dependencies = [Dependency("GMP_jll")]
platform = Platform("x86_64", "linux"; julia_version=v"1.6")
# Test that a particular version of GMP is installed
@test_logs setup_dependencies(prefix, getpkg.(dependencies), platform)
@test isfile(joinpath(destdir(dir, platform), "lib", "libgmp.so.10.4.0"))
end
# Next, build a set of dependencies that are not instantiatable as-is:
with_temp_project() do dir
prefix = Prefix(dir)
dependencies = [
Dependency("GMP_jll", v"6.1.2"),
Dependency("MPFR_jll",v"4.1.0"),
]
# Test that this is not instantiatable with either Julia v1.5 or v1.6
platform = Platform("x86_64", "linux"; julia_version=v"1.5")
@test_throws Pkg.Resolve.ResolverError setup_dependencies(prefix, getpkg.(dependencies), platform)
platform = Platform("x86_64", "linux"; julia_version=v"1.6")
@test_throws Pkg.Resolve.ResolverError setup_dependencies(prefix, getpkg.(dependencies), platform)
# If we don't give a `julia_version`, then we are FULLY UNSHACKLED.
platform = Platform("x86_64", "linux")
@test_logs setup_dependencies(prefix, getpkg.(dependencies), platform)
@test isfile(joinpath(destdir(dir, platform), "lib", "libgmp.so.10.3.2"))
@test isfile(joinpath(destdir(dir, platform), "lib", "libmpfr.so.6.1.0"))
end
# Dependency as a local directory
with_temp_project() do dir
mktempdir() do pkgdir
prefix = Prefix(dir)
# Clone if necessary the remote repository and check out its
# working directory in a temporary space.
cache_dir = cached_git_clone("https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl")
LibGit2.with(LibGit2.clone(cache_dir, pkgdir)) do repo
LibGit2.checkout!(repo, "c7f2e95d9c04e218931c14954ecd31ebde72cca5")
end
dependencies = [
PackageSpec(
name="HelloWorldC_jll",
path=pkgdir,
),
]
platform = Platform("x86_64", "linux"; libc="glibc")
@test_logs setup_dependencies(prefix, dependencies, platform)
@test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"]
end
end
# Dependency as a remote repository
with_temp_project() do dir
prefix = Prefix(dir)
dependencies = [
PackageSpec(
name="HelloWorldC_jll",
url="https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl",
rev="c7f2e95d9c04e218931c14954ecd31ebde72cca5",
),
]
platform = Platform("x86_64", "linux"; libc="glibc")
@test_logs setup_dependencies(prefix, dependencies, platform)
@test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"]
end
end
end
@testset "resolve_jlls" begin
# Deps given by name::String
dependencies = ["OpenSSL_jll",]
@test_logs (:warn, r"use Dependency instead") begin
truefalse, resolved_deps = resolve_jlls(dependencies)
@test truefalse
@test all(x->getpkg(x).uuid !== nothing, resolved_deps)
end
# Deps given by name::PackageSpec
@test_logs (:warn, r"use Dependency instead") begin
dependencies = [PackageSpec(name="OpenSSL_jll"),]
truefalse, resolved_deps = resolve_jlls(dependencies)
@test truefalse
@test all(x->getpkg(x).uuid !== nothing, resolved_deps)
end
# Deps given by (name,uuid)::PackageSpec
dependencies = [Dependency(PackageSpec(name="OpenSSL_jll", uuid="458c3c95-2e84-50aa-8efc-19380b2a3a95")),]
truefalse, resolved_deps = resolve_jlls(dependencies)
@test truefalse
@test all(x->getpkg(x).uuid !== nothing, resolved_deps)
# Deps given by combination of name::String, name::PackageSpec and (name,uuid)::PackageSpec
dependencies = [
Dependency("Zlib_jll"),
Dependency(PackageSpec(name="Bzip2_jll")),
Dependency(PackageSpec(name="OpenSSL_jll", uuid="458c3c95-2e84-50aa-8efc-19380b2a3a95")),
]
truefalse, resolved_deps = resolve_jlls(dependencies)
@test truefalse
@test all(x->getpkg(x).uuid !== nothing, resolved_deps)
end