1
1
using UUIDs
2
2
3
3
export Dependency, BuildDependency, HostBuildDependency,
4
- is_host_dependency, is_target_dependency, is_build_dependency, is_runtime_dependency
4
+ is_host_dependency, is_target_dependency, is_build_dependency, is_runtime_dependency,
5
+ filter_platforms
5
6
6
7
7
8
# Pkg.PackageSpec return different types in different Julia versions so...
@@ -54,7 +55,7 @@ Return whether `dep` is a runtime dependency or not.
54
55
is_runtime_dependency
55
56
56
57
"""
57
- Dependency(dep::Union{PackageSpec,String}, build_version; compat)
58
+ Dependency(dep::Union{PackageSpec,String}, build_version; compat, platforms )
58
59
59
60
Define a binary dependency that is necessary to build the package and load the
60
61
generated JLL package. The argument can be either a string with the name of the
@@ -67,12 +68,19 @@ The optional keyword argument `compat` can be used to specify a string for use
67
68
in the `Project.toml` of the generated Julia package. If `compat` is non-empty
68
69
and `build_version` is not passed, the latter defaults to the minimum version
69
70
compatible with the `compat` specifier.
71
+
72
+ The optional keyword argument `platforms` is a vector of `AbstractPlatform`s
73
+ which indicates for which platforms the dependency should be used. By default
74
+ `platforms=[AnyPlatform()]`, to mean that the dependency is compatible with all
75
+ platforms.
70
76
"""
71
77
struct Dependency <: AbstractDependency
72
78
pkg:: PkgSpec
73
79
build_version:: Union{VersionNumber,Nothing}
74
80
compat:: String # semver string for use in Project.toml of the JLL
75
- function Dependency (pkg:: PkgSpec , build_version = nothing ; compat:: String = " " )
81
+ platforms:: Vector{<:AbstractPlatform}
82
+ function Dependency (pkg:: PkgSpec , build_version = nothing ; compat:: String = " " ,
83
+ platforms:: Vector{<:AbstractPlatform} = [AnyPlatform ()])
76
84
if length (compat) > 0
77
85
spec = PKG_VERSIONS. semver_spec (compat) # verify compat is valid
78
86
if build_version === nothing
@@ -88,45 +96,64 @@ struct Dependency <: AbstractDependency
88
96
throw (ArgumentError (" PackageSpec version and compat for $(pkg) are incompatible" ))
89
97
end
90
98
end
91
- new (pkg, build_version, compat)
99
+ new (pkg, build_version, compat, platforms )
92
100
end
93
101
end
94
- function Dependency (dep:: AbstractString , build_version = nothing ; compat:: String = " " )
95
- return Dependency (PackageSpec (; name = dep), build_version, compat = compat)
102
+ function Dependency (dep:: AbstractString , build_version = nothing ;
103
+ compat:: String = " " , platforms:: Vector{<:AbstractPlatform} = [AnyPlatform ()])
104
+ return Dependency (PackageSpec (; name = dep), build_version; compat, platforms)
96
105
end
97
106
is_host_dependency (:: Dependency ) = false
98
107
is_build_dependency (:: Dependency ) = true
99
108
is_runtime_dependency (:: Dependency ) = true
100
109
101
110
"""
102
- BuildDependency(dep::Union{PackageSpec,String})
111
+ BuildDependency(dep::Union{PackageSpec,String}; platforms )
103
112
104
113
Define a binary dependency that is necessary only to build the package. The
105
- argument can be either a string with the name of the JLL package or a
114
+ `dep` argument can be either a string with the name of the JLL package or a
106
115
`Pkg.PackageSpec`.
116
+
117
+ The optional keyword argument `platforms` is a vector of `AbstractPlatform`s
118
+ which indicates for which platforms the dependency should be used. By default
119
+ `platforms=[AnyPlatform()]`, to mean that the dependency is compatible with all
120
+ platforms.
107
121
"""
108
122
struct BuildDependency <: AbstractDependency
109
123
pkg:: PkgSpec
124
+ platforms:: Vector{<:AbstractPlatform}
125
+ BuildDependency (pkg:: PkgSpec ; platforms:: Vector{<:AbstractPlatform} = [AnyPlatform ()]) =
126
+ new (pkg, platforms)
110
127
end
111
- BuildDependency (dep:: AbstractString ) = BuildDependency (PackageSpec (; name = dep))
128
+ BuildDependency (dep:: AbstractString ; platforms:: Vector{<:AbstractPlatform} = [AnyPlatform ()]) =
129
+ BuildDependency (PackageSpec (; name = dep); platforms)
112
130
is_host_dependency (:: BuildDependency ) = false
113
131
is_build_dependency (:: BuildDependency ) = true
114
132
is_runtime_dependency (:: BuildDependency ) = false
115
133
116
134
"""
117
- HostBuildDependency(dep::Union{PackageSpec,String})
135
+ HostBuildDependency(dep::Union{PackageSpec,String}; platforms )
118
136
119
137
Define a binary dependency that is necessary only to build the package.
120
138
Different from the [`BuildDependency`](@ref), the artifact for the host
121
139
platform will be installed, instead of that for the target platform.
122
140
123
- The argument can be either a string with the name of the JLL package or a
141
+ The `dep` argument can be either a string with the name of the JLL package or a
124
142
`Pkg.PackageSpec`.
143
+
144
+ The optional keyword argument `platforms` is a vector of `AbstractPlatform`s
145
+ which indicates for which platforms the dependency should be used. By default
146
+ `platforms=[AnyPlatform()]`, to mean that the dependency is compatible with all
147
+ platforms.
125
148
"""
126
149
struct HostBuildDependency <: AbstractDependency
127
150
pkg:: PkgSpec
151
+ platforms:: Vector{<:AbstractPlatform}
152
+ HostBuildDependency (pkg:: PkgSpec ; platforms:: Vector{<:AbstractPlatform} = [AnyPlatform ()]) =
153
+ new (pkg, platforms)
128
154
end
129
- HostBuildDependency (dep:: AbstractString ) = HostBuildDependency (PackageSpec (; name = dep))
155
+ HostBuildDependency (dep:: AbstractString ; platforms:: Vector{<:AbstractPlatform} = [AnyPlatform ()]) =
156
+ HostBuildDependency (PackageSpec (; name = dep); platforms)
130
157
is_host_dependency (:: HostBuildDependency ) = true
131
158
is_build_dependency (:: HostBuildDependency ) = true
132
159
is_runtime_dependency (:: HostBuildDependency ) = false
@@ -145,12 +172,20 @@ end
145
172
getname (x:: PkgSpec ) = x. name
146
173
getname (x:: AbstractDependency ) = getname (getpkg (x))
147
174
175
+ """
176
+ filter_platforms(deps::AbstractVector{<:AbstractDependency}, p::AbstractPlatform)
177
+
178
+ Filter the dependencies `deps` which are compatible with platform `p`.
179
+ """
180
+ filter_platforms (deps:: AbstractVector{<:AbstractDependency} , p:: AbstractPlatform ) =
181
+ [dep for dep in deps if any (x -> platforms_match (x, p), dep. platforms)]
182
+
148
183
# Wrapper around `Pkg.Types.registry_resolve!` which keeps the type of the
149
184
# dependencies. TODO : improve this
150
185
function registry_resolve! (ctx, dependencies:: Vector{<:AbstractDependency} )
151
186
resolved_dependencies = Pkg. Types. registry_resolve! (ctx, getpkg .(dependencies))
152
187
for idx in eachindex (dependencies)
153
- dependencies[idx] = typeof (dependencies[idx])(resolved_dependencies[idx])
188
+ dependencies[idx] = typeof (dependencies[idx])(resolved_dependencies[idx]; platforms = dependencies[idx] . platforms )
154
189
end
155
190
return dependencies
156
191
end
@@ -222,7 +257,9 @@ for (type, type_descr) in ((Dependency, "dependency"), (BuildDependency, "buildd
222
257
" compat" => getcompat (d),
223
258
" version-major" => major (version (d)),
224
259
" version-minor" => minor (version (d)),
225
- " version-patch" => patch (version (d)))
260
+ " version-patch" => patch (version (d)),
261
+ " platforms" => triplet .(d. platforms),
262
+ )
226
263
end
227
264
228
265
# When deserialiasing the JSON file, the dependencies are in the form of
@@ -235,12 +272,13 @@ function dependencify(d::Dict)
235
272
version = VersionNumber (d[" version-major" ], d[" version-minor" ], d[" version-patch" ])
236
273
version = version == v " 0" ? nothing : version
237
274
spec = PackageSpec (; name = d[" name" ], uuid = uuid, version = version)
275
+ platforms = parse_platform .(d[" platforms" ])
238
276
if d[" type" ] == " dependency"
239
- return Dependency (spec; compat = compat )
277
+ return Dependency (spec; compat, platforms )
240
278
elseif d[" type" ] == " builddependency"
241
- return BuildDependency (spec)
279
+ return BuildDependency (spec; platforms )
242
280
elseif d[" type" ] == " hostdependency"
243
- return HostBuildDependency (spec)
281
+ return HostBuildDependency (spec; platforms )
244
282
end
245
283
end
246
284
error (" Cannot convert to dependency" )
0 commit comments