1
1
using UUIDs
2
2
3
- export Dependency, BuildDependency, HostBuildDependency,
3
+ export Dependency, RuntimeDependency, BuildDependency, HostBuildDependency,
4
4
is_host_dependency, is_target_dependency, is_build_dependency, is_runtime_dependency,
5
5
filter_platforms
6
6
@@ -18,11 +18,20 @@ Concrete subtypes of `AbstractDependency` are
18
18
19
19
* [`Dependency`](@ref): a JLL package that is necessary for to build the package
20
20
and to load the generated JLL package.
21
+ * [`RuntimeDependency`](@ref): a JLL package that is necessary only at runtime. Its
22
+ artifact will not be installed in the prefix during the build.
21
23
* [`BuildDependency`](@ref): a JLL package that is necessary only to build the
22
24
package. This will not be a dependency of the generated JLL package.
23
25
* [`HostBuildDependency`](@ref): similar to `BuildDependency`, but it will
24
26
install the artifact for the host platform, instead of that for the target
25
27
platform.
28
+
29
+ Subtypes of `AbstractDependency` should define the following traits:
30
+
31
+ * [`is_host_dependency`](@ref)
32
+ * [`is_target_dependency`](@ref)
33
+ * [`is_build_dependency`](@ref)
34
+ * [`is_runtime_dependency`](@ref)
26
35
"""
27
36
abstract type AbstractDependency end
28
37
@@ -81,7 +90,7 @@ struct Dependency <: AbstractDependency
81
90
platforms:: Vector{<:AbstractPlatform}
82
91
function Dependency (pkg:: PkgSpec , build_version = nothing ; compat:: String = " " ,
83
92
platforms:: Vector{<:AbstractPlatform} = [AnyPlatform ()])
84
- if length (compat) > 0
93
+ if ! isempty (compat)
85
94
spec = PKG_VERSIONS. semver_spec (compat) # verify compat is valid
86
95
if build_version === nothing
87
96
# Since we usually want to build against the oldest compatible
@@ -107,6 +116,44 @@ is_host_dependency(::Dependency) = false
107
116
is_build_dependency (:: Dependency ) = true
108
117
is_runtime_dependency (:: Dependency ) = true
109
118
119
+ """
120
+ RuntimeDependency(dep::Union{PackageSpec,String}; compat::String, platforms::Vector{<:AbstractPlatform})
121
+
122
+ Define a binary dependency that is only listed as dependency of the generated JLL package,
123
+ but its artifact is not installed in the prefix during the build. The `dep` argument can be
124
+ either a string with the name of the JLL package or a `Pkg.PackageSpec`.
125
+
126
+ The optional keyword argument `compat` can be used to specify a string for use
127
+ in the `Project.toml` of the generated Julia package.
128
+
129
+ The optional keyword argument `platforms` is a vector of `AbstractPlatform`s which indicates
130
+ for which platforms the dependency should be used. By default `platforms=[AnyPlatform()]`,
131
+ to mean that the dependency is compatible with all platforms.
132
+ """
133
+ struct RuntimeDependency <: AbstractDependency
134
+ pkg:: PkgSpec
135
+ compat:: String # semver string for use in Project.toml of the JLL
136
+ platforms:: Vector{<:AbstractPlatform}
137
+ function RuntimeDependency (pkg:: PkgSpec ; compat:: String = " " ,
138
+ platforms:: Vector{<:AbstractPlatform} = [AnyPlatform ()])
139
+ if ! isempty (compat)
140
+ spec = PKG_VERSIONS. semver_spec (compat) # verify compat is valid
141
+ if pkg. version != PKG_VERSIONS. VersionSpec (" *" ) && ! (pkg. version in spec)
142
+ throw (ArgumentError (" PackageSpec version and compat for $(pkg) are incompatible" ))
143
+ end
144
+ end
145
+ return new (pkg, compat, platforms)
146
+ end
147
+ end
148
+ RuntimeDependency (name:: AbstractString ; compat:: String = " " , platforms:: Vector{<:AbstractPlatform} = [AnyPlatform ()]) =
149
+ RuntimeDependency (PackageSpec (; name); compat, platforms)
150
+ is_host_dependency (:: RuntimeDependency ) = false
151
+ is_build_dependency (:: RuntimeDependency ) = false
152
+ is_runtime_dependency (:: RuntimeDependency ) = true
153
+ # In some cases we may want to automatically convert a `RuntimeDependency` to a `Dependency`
154
+ Base. convert (:: Type{Dependency} , dep:: RuntimeDependency ) =
155
+ Dependency (dep. pkg; compat= dep. compat, platforms= dep. platforms)
156
+
110
157
"""
111
158
BuildDependency(dep::Union{PackageSpec,String}; platforms)
112
159
@@ -250,7 +297,7 @@ version(d::Dependency) = __version(d.pkg.version)
250
297
getcompat (d:: AbstractDependency ) = " "
251
298
getcompat (d:: Dependency ) = d. compat
252
299
253
- for (type, type_descr) in ((Dependency, " dependency" ), (BuildDependency, " builddependency" ), (HostBuildDependency, " hostdependency" ))
300
+ for (type, type_descr) in ((Dependency, " dependency" ), (RuntimeDependency, " runtimedependency " ), ( BuildDependency, " builddependency" ), (HostBuildDependency, " hostdependency" ))
254
301
JSON. lower (d:: type ) = Dict (" type" => type_descr,
255
302
" name" => d. pkg. name,
256
303
" uuid" => string_or_nothing (d. pkg. uuid),
266
313
# dictionaries. This function converts the dictionary back to the appropriate
267
314
# AbstractDependency.
268
315
function dependencify (d:: Dict )
269
- if d[" type" ] in (" dependency" , " builddependency" , " hostdependency" )
316
+ if d[" type" ] in (" dependency" , " runtimedependency " , " builddependency" , " hostdependency" )
270
317
uuid = isnothing (d[" uuid" ]) ? d[" uuid" ] : UUID (d[" uuid" ])
271
318
compat = d[" compat" ]
272
319
version = PKG_VERSIONS. VersionSpec (VersionNumber (d[" version-major" ], d[" version-minor" ], d[" version-patch" ]))
@@ -275,6 +322,8 @@ function dependencify(d::Dict)
275
322
platforms = parse_platform .(d[" platforms" ])
276
323
if d[" type" ] == " dependency"
277
324
return Dependency (spec; compat, platforms)
325
+ elseif d[" type" ] == " runtimedependency"
326
+ return RuntimeDependency (spec; compat, platforms)
278
327
elseif d[" type" ] == " builddependency"
279
328
return BuildDependency (spec; platforms)
280
329
elseif d[" type" ] == " hostdependency"
0 commit comments