diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2015-02-10 18:13:25 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-02-16 09:10:42 +0000 |
commit | c4da9b949a09f6fcf4091f247a05cea78175571a (patch) | |
tree | 3e79639e36e69caaf5ebb37ba206eb0bcf823d7b /bitbake | |
parent | 758dc92abd8a9af00e3f2b20cba9ca4c7cfca3e0 (diff) | |
download | poky-c4da9b949a09f6fcf4091f247a05cea78175571a.tar.gz |
bitbake: cooker: rework LAYERDEPENDS versioning so that it is actually useful
We've had versioned dependency support in LAYERDEPENDS for quite a long
time, but I can say with pretty good certainty that almost nobody has
used it up to now because it was too strict - the specified version had
to exactly match the version in your configuration or you would get an
error; there was no "greater than or equal" option, which is usually
what you will want given that LAYERVERSION does get bumped from time to
time.
However, users mismatching layer branches and then having their builds
fail later on with some incomprehensible error is still a pretty common
problem. We can't simply use the git branch because not everyone is
always on a branch and the branch names don't always match up (and
that's not an issue). To provide a practical means to address branch
mismatching, I have reworked LAYERDEPENDS version specifications to use
the more familiar "dependency (>= version)" syntax as used with package
dependencies, support non-integer versions, and clarified the error
message a little. If we then take care to bump the version on every
breaking change, it is at least possible to have layers depend on these
changes when they update to match; we can now even support a major.minor
scheme to allow retrospectively adding a version limiter to old branches
when a new branch is created and yet still allow the old branch minor
version to be bumped if needed.
Fixes [YOCTO #5991].
(Bitbake rev: 408be9cdf2b1e32e64ea488d8051a546fb54c144)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/cooker.py | 40 | ||||
-rw-r--r-- | bitbake/lib/bb/tests/utils.py | 33 | ||||
-rw-r--r-- | bitbake/lib/bb/utils.py | 22 |
3 files changed, 69 insertions, 26 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index f77c6c0532..0bbbc09c33 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py | |||
@@ -1096,42 +1096,30 @@ class BBCooker: | |||
1096 | # Check dependencies and store information for priority calculation | 1096 | # Check dependencies and store information for priority calculation |
1097 | deps = self.data.getVar("LAYERDEPENDS_%s" % c, True) | 1097 | deps = self.data.getVar("LAYERDEPENDS_%s" % c, True) |
1098 | if deps: | 1098 | if deps: |
1099 | depnamelist = [] | 1099 | try: |
1100 | deplist = deps.split() | 1100 | deplist = bb.utils.explode_dep_versions2(deps) |
1101 | for dep in deplist: | 1101 | except bb.utils.VersionStringException as vse: |
1102 | depsplit = dep.split(':') | 1102 | bb.fatal('Error parsing LAYERDEPENDS_%s: %s' % (c, str(vse))) |
1103 | if len(depsplit) > 1: | 1103 | for dep, oplist in deplist.iteritems(): |
1104 | try: | ||
1105 | depver = int(depsplit[1]) | ||
1106 | except ValueError: | ||
1107 | parselog.error("invalid version value in LAYERDEPENDS_%s: \"%s\"", c, dep) | ||
1108 | errors = True | ||
1109 | continue | ||
1110 | else: | ||
1111 | depver = None | ||
1112 | dep = depsplit[0] | ||
1113 | depnamelist.append(dep) | ||
1114 | |||
1115 | if dep in collection_list: | 1104 | if dep in collection_list: |
1116 | if depver: | 1105 | for opstr in oplist: |
1117 | layerver = self.data.getVar("LAYERVERSION_%s" % dep, True) | 1106 | layerver = self.data.getVar("LAYERVERSION_%s" % dep, True) |
1107 | (op, depver) = opstr.split() | ||
1118 | if layerver: | 1108 | if layerver: |
1119 | try: | 1109 | try: |
1120 | lver = int(layerver) | 1110 | res = bb.utils.vercmp_string_op(layerver, depver, op) |
1121 | except ValueError: | 1111 | except bb.utils.VersionStringException as vse: |
1122 | parselog.error("invalid value for LAYERVERSION_%s: \"%s\"", c, layerver) | 1112 | bb.fatal('Error parsing LAYERDEPENDS_%s: %s' % (c, str(vse))) |
1123 | errors = True | 1113 | if not res: |
1124 | continue | 1114 | parselog.error("Layer '%s' depends on version %s of layer '%s', but version %s is currently enabled in your configuration. Check that you are using the correct matching versions/branches of these two layers.", c, opstr, dep, layerver) |
1125 | if lver != depver: | ||
1126 | parselog.error("Layer '%s' depends on version %d of layer '%s', but version %d is enabled in your configuration", c, depver, dep, lver) | ||
1127 | errors = True | 1115 | errors = True |
1128 | else: | 1116 | else: |
1129 | parselog.error("Layer '%s' depends on version %d of layer '%s', which exists in your configuration but does not specify a version", c, depver, dep) | 1117 | parselog.error("Layer '%s' depends on version %s of layer '%s', which exists in your configuration but does not specify a version. Check that you are using the correct matching versions/branches of these two layers.", c, opstr, dep) |
1130 | errors = True | 1118 | errors = True |
1131 | else: | 1119 | else: |
1132 | parselog.error("Layer '%s' depends on layer '%s', but this layer is not enabled in your configuration", c, dep) | 1120 | parselog.error("Layer '%s' depends on layer '%s', but this layer is not enabled in your configuration", c, dep) |
1133 | errors = True | 1121 | errors = True |
1134 | collection_depends[c] = depnamelist | 1122 | collection_depends[c] = deplist.keys() |
1135 | else: | 1123 | else: |
1136 | collection_depends[c] = [] | 1124 | collection_depends[c] = [] |
1137 | 1125 | ||
diff --git a/bitbake/lib/bb/tests/utils.py b/bitbake/lib/bb/tests/utils.py index cf145f0d7a..507de2de3c 100644 --- a/bitbake/lib/bb/tests/utils.py +++ b/bitbake/lib/bb/tests/utils.py | |||
@@ -55,3 +55,36 @@ class VerCmpString(unittest.TestCase): | |||
55 | result = bb.utils.explode_dep_versions2("foo ( =1.10 )") | 55 | result = bb.utils.explode_dep_versions2("foo ( =1.10 )") |
56 | self.assertEqual(result, correctresult) | 56 | self.assertEqual(result, correctresult) |
57 | 57 | ||
58 | def test_vercmp_string_op(self): | ||
59 | compareops = [('1', '1', '=', True), | ||
60 | ('1', '1', '==', True), | ||
61 | ('1', '1', '!=', False), | ||
62 | ('1', '1', '>', False), | ||
63 | ('1', '1', '<', False), | ||
64 | ('1', '1', '>=', True), | ||
65 | ('1', '1', '<=', True), | ||
66 | ('1', '0', '=', False), | ||
67 | ('1', '0', '==', False), | ||
68 | ('1', '0', '!=', True), | ||
69 | ('1', '0', '>', True), | ||
70 | ('1', '0', '<', False), | ||
71 | ('1', '0', '>>', True), | ||
72 | ('1', '0', '<<', False), | ||
73 | ('1', '0', '>=', True), | ||
74 | ('1', '0', '<=', False), | ||
75 | ('0', '1', '=', False), | ||
76 | ('0', '1', '==', False), | ||
77 | ('0', '1', '!=', True), | ||
78 | ('0', '1', '>', False), | ||
79 | ('0', '1', '<', True), | ||
80 | ('0', '1', '>>', False), | ||
81 | ('0', '1', '<<', True), | ||
82 | ('0', '1', '>=', False), | ||
83 | ('0', '1', '<=', True)] | ||
84 | |||
85 | for arg1, arg2, op, correctresult in compareops: | ||
86 | result = bb.utils.vercmp_string_op(arg1, arg2, op) | ||
87 | self.assertEqual(result, correctresult, 'vercmp_string_op("%s", "%s", "%s") != %s' % (arg1, arg2, op, correctresult)) | ||
88 | |||
89 | # Check that clearly invalid operator raises an exception | ||
90 | self.assertRaises(bb.utils.VersionStringException, bb.utils.vercmp_string_op, '0', '0', '$') | ||
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 7ba1234578..5ac9bcfbd4 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -131,6 +131,28 @@ def vercmp_string(a, b): | |||
131 | tb = split_version(b) | 131 | tb = split_version(b) |
132 | return vercmp(ta, tb) | 132 | return vercmp(ta, tb) |
133 | 133 | ||
134 | def vercmp_string_op(a, b, op): | ||
135 | """ | ||
136 | Compare two versions and check if the specified comparison operator matches the result of the comparison. | ||
137 | This function is fairly liberal about what operators it will accept since there are a variety of styles | ||
138 | depending on the context. | ||
139 | """ | ||
140 | res = vercmp_string(a, b) | ||
141 | if op in ('=', '=='): | ||
142 | return res == 0 | ||
143 | elif op == '<=': | ||
144 | return res <= 0 | ||
145 | elif op == '>=': | ||
146 | return res >= 0 | ||
147 | elif op in ('>', '>>'): | ||
148 | return res > 0 | ||
149 | elif op in ('<', '<<'): | ||
150 | return res < 0 | ||
151 | elif op == '!=': | ||
152 | return res != 0 | ||
153 | else: | ||
154 | raise VersionStringException('Unsupported comparison operator "%s"' % op) | ||
155 | |||
134 | def explode_deps(s): | 156 | def explode_deps(s): |
135 | """ | 157 | """ |
136 | Take an RDEPENDS style string of format: | 158 | Take an RDEPENDS style string of format: |