Skip to content

Commit 3e53dde

Browse files
authored
[Dependencies] Default build_version to the minimum compatible version (#150)
In a `Dependency` we have to specify two versions numbers: the actual build version and the compat version, which 99.99% of the time are the same. This is annoying and error-prone. With this change the build version defaults to the minimum compatible version specified by `compat`, if any.
1 parent c70cf8f commit 3e53dde

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BinaryBuilderBase"
22
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
33
authors = ["Elliot Saba <staticfloat@gmail.com>"]
4-
version = "0.6.6"
4+
version = "0.6.7"
55

66
[deps]
77
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"

src/Dependencies.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export Dependency, BuildDependency, HostBuildDependency,
66

77
# Pkg.PackageSpec return different types in different Julia versions so...
88
const PkgSpec = typeof(Pkg.PackageSpec(name="dummy"))
9+
const PKG_VERSIONS = Base.VERSION >= v"1.7-" ? Pkg.Versions : Pkg.Types
10+
911

1012
"""
1113
An `AbstractDependency` is a binary dependency of the JLL package. Dependencies
@@ -52,7 +54,7 @@ Return whether `dep` is a runtime dependency or not.
5254
is_runtime_dependency
5355

5456
"""
55-
Dependency(dep::Union{PackageSpec,String})
57+
Dependency(dep::Union{PackageSpec,String}, build_version; compat)
5658
5759
Define a binary dependency that is necessary to build the package and load the
5860
generated JLL package. The argument can be either a string with the name of the
@@ -61,20 +63,28 @@ JLL package or a `Pkg.PackageSpec`.
6163
The optional keyword argument `build_version` can be used to specify the version
6264
of the dependency to be installed when building it.
6365
64-
The optional keyword argument `compat` can be used to specify a string for
65-
use in the `Project.toml` of the generated Julia package.
66+
The optional keyword argument `compat` can be used to specify a string for use
67+
in the `Project.toml` of the generated Julia package. If `compat` is non-empty
68+
and `build_version` is not passed, the latter defaults to the minimum version
69+
compatible with the `compat` specifier.
6670
"""
6771
struct Dependency <: AbstractDependency
6872
pkg::PkgSpec
6973
build_version::Union{VersionNumber,Nothing}
7074
compat::String # semver string for use in Project.toml of the JLL
7175
function Dependency(pkg::PkgSpec, build_version = nothing; compat::String = "")
7276
if length(compat) > 0
73-
spec = Pkg.Types.semver_spec(compat) # verify compat is valid
74-
if build_version !== nothing && !(build_version in spec)
77+
spec = PKG_VERSIONS.semver_spec(compat) # verify compat is valid
78+
if build_version === nothing
79+
# Since we usually want to build against the oldest compatible
80+
# version, if `build_version` isn't set but `compat` is, make it
81+
# default to the minimum compatible version.
82+
build_version = minimum(VersionNumber(rng.lower.t) for rng in spec.ranges)
83+
end
84+
if build_version spec
7585
throw(ArgumentError("build_version and compat for $(pkg) are incompatible"))
7686
end
77-
if pkg.version != Pkg.Types.VersionSpec("*") && !(pkg.version in spec)
87+
if pkg.version != PKG_VERSIONS.VersionSpec("*") && !(pkg.version in spec)
7888
throw(ArgumentError("PackageSpec version and compat for $(pkg) are incompatible"))
7989
end
8090
end

test/dependencies.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ end
4242
@test getpkg(dep_buildver) == PackageSpec(; name = name, version = build_version)
4343
@test getcompat(dep_buildver) == "~1.2"
4444

45+
# the same but only with compat specifier
46+
dep_compat = Dependency(PackageSpec(; name); compat = "2, ~$(build_version)")
47+
@test Dependency(name, build_version) == dep_compat
48+
@test getname(dep_compat) == name
49+
@test getpkg(dep_compat) == PackageSpec(; name, version = build_version)
50+
@test getcompat(dep_compat) == "2, ~$(build_version)"
51+
4552
# if build_version and compat don't match, an error should be thrown
4653
@test_throws ArgumentError Dependency(PackageSpec(; name = name), build_version, compat = "2.0")
4754

0 commit comments

Comments
 (0)