diff options
author | Charlie Davies <charles.davies@whitetree.xyz> | 2021-02-18 20:52:17 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-03-15 14:36:51 +0000 |
commit | 3752782cb77749ef11d947a26cfa7e4905662339 (patch) | |
tree | 30fa8e7fd7b7ed42869d94d1d854dc8ec61b38ed | |
parent | 70f90dcfd7401e9f6942d163579ef575a43721fc (diff) | |
download | poky-3752782cb77749ef11d947a26cfa7e4905662339.tar.gz |
bitbake: bitbake: providers: introduce logic for REQUIRED_VERSION variable
This commit adds checks during the findPreferredProvider function for a
new variable REQUIRED_VERSION. This can be set, in exactly the same
manner as PREFERRED_VERSION, on a per package basis to enforce the use
of a particular version of a package.
REQUIRED_VERSION is similar in behaviour to PREFERRED_VERSION except if
the version specified by REQUIRED_VERSION is not found an error occurs
and the execution of Bitbake stops.
Fixes [YOCTO #10096]
(Bitbake rev: 5cbf6d95fc1009e78e7d0745a49e0bf418b37abb)
Signed-off-by: Charlie Davies <charles.davies@whitetree.xyz>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/providers.py | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/bitbake/lib/bb/providers.py b/bitbake/lib/bb/providers.py index e8241d90c0..09e5701f2e 100644 --- a/bitbake/lib/bb/providers.py +++ b/bitbake/lib/bb/providers.py | |||
@@ -85,6 +85,21 @@ def sortPriorities(pn, dataCache, pkg_pn = None): | |||
85 | 85 | ||
86 | return tmp_pn | 86 | return tmp_pn |
87 | 87 | ||
88 | def versionVariableMatch(cfgData, keyword, pn): | ||
89 | """ | ||
90 | Return the value of the <keyword>_VERSION variable if set. | ||
91 | """ | ||
92 | |||
93 | # pn can contain '_', e.g. gcc-cross-x86_64 and an override cannot | ||
94 | # hence we do this manually rather than use OVERRIDES | ||
95 | ver = cfgData.getVar("%s_VERSION_pn-%s" % (keyword, pn)) | ||
96 | if not ver: | ||
97 | ver = cfgData.getVar("%s_VERSION_%s" % (keyword, pn)) | ||
98 | if not ver: | ||
99 | ver = cfgData.getVar("%s_VERSION" % keyword) | ||
100 | |||
101 | return ver | ||
102 | |||
88 | def preferredVersionMatch(pe, pv, pr, preferred_e, preferred_v, preferred_r): | 103 | def preferredVersionMatch(pe, pv, pr, preferred_e, preferred_v, preferred_r): |
89 | """ | 104 | """ |
90 | Check if the version pe,pv,pr is the preferred one. | 105 | Check if the version pe,pv,pr is the preferred one. |
@@ -100,19 +115,28 @@ def preferredVersionMatch(pe, pv, pr, preferred_e, preferred_v, preferred_r): | |||
100 | 115 | ||
101 | def findPreferredProvider(pn, cfgData, dataCache, pkg_pn = None, item = None): | 116 | def findPreferredProvider(pn, cfgData, dataCache, pkg_pn = None, item = None): |
102 | """ | 117 | """ |
103 | Find the first provider in pkg_pn with a PREFERRED_VERSION set. | 118 | Find the first provider in pkg_pn with REQUIRED_VERSION or PREFERRED_VERSION set. |
104 | """ | 119 | """ |
105 | 120 | ||
106 | preferred_file = None | 121 | preferred_file = None |
107 | preferred_ver = None | 122 | preferred_ver = None |
123 | required = False | ||
108 | 124 | ||
109 | # pn can contain '_', e.g. gcc-cross-x86_64 and an override cannot | 125 | required_v = versionVariableMatch(cfgData, "REQUIRED", pn) |
110 | # hence we do this manually rather than use OVERRIDES | 126 | preferred_v = versionVariableMatch(cfgData, "PREFERRED", pn) |
111 | preferred_v = cfgData.getVar("PREFERRED_VERSION_pn-%s" % pn) | 127 | |
112 | if not preferred_v: | 128 | itemstr = "" |
113 | preferred_v = cfgData.getVar("PREFERRED_VERSION_%s" % pn) | 129 | if item: |
114 | if not preferred_v: | 130 | itemstr = " (for item %s)" % item |
115 | preferred_v = cfgData.getVar("PREFERRED_VERSION") | 131 | |
132 | if required_v is not None: | ||
133 | if preferred_v is not None: | ||
134 | logger.warn("REQUIRED_VERSION and PREFERRED_VERSION for package %s%s are both set using REQUIRED_VERSION %s", pn, itemstr, required_v) | ||
135 | else: | ||
136 | logger.debug("REQUIRED_VERSION is set for package %s%s", pn, itemstr) | ||
137 | # REQUIRED_VERSION always takes precedence over PREFERRED_VERSION | ||
138 | preferred_v = required_v | ||
139 | required = True | ||
116 | 140 | ||
117 | if preferred_v: | 141 | if preferred_v: |
118 | m = re.match(r'(\d+:)*(.*)(_.*)*', preferred_v) | 142 | m = re.match(r'(\d+:)*(.*)(_.*)*', preferred_v) |
@@ -145,11 +169,9 @@ def findPreferredProvider(pn, cfgData, dataCache, pkg_pn = None, item = None): | |||
145 | pv_str = preferred_v | 169 | pv_str = preferred_v |
146 | if not (preferred_e is None): | 170 | if not (preferred_e is None): |
147 | pv_str = '%s:%s' % (preferred_e, pv_str) | 171 | pv_str = '%s:%s' % (preferred_e, pv_str) |
148 | itemstr = "" | ||
149 | if item: | ||
150 | itemstr = " (for item %s)" % item | ||
151 | if preferred_file is None: | 172 | if preferred_file is None: |
152 | logger.warn("preferred version %s of %s not available%s", pv_str, pn, itemstr) | 173 | if not required: |
174 | logger.warn("preferred version %s of %s not available%s", pv_str, pn, itemstr) | ||
153 | available_vers = [] | 175 | available_vers = [] |
154 | for file_set in pkg_pn: | 176 | for file_set in pkg_pn: |
155 | for f in file_set: | 177 | for f in file_set: |
@@ -162,11 +184,15 @@ def findPreferredProvider(pn, cfgData, dataCache, pkg_pn = None, item = None): | |||
162 | if available_vers: | 184 | if available_vers: |
163 | available_vers.sort() | 185 | available_vers.sort() |
164 | logger.warn("versions of %s available: %s", pn, ' '.join(available_vers)) | 186 | logger.warn("versions of %s available: %s", pn, ' '.join(available_vers)) |
187 | if required: | ||
188 | logger.error("required version %s of %s not available%s", pv_str, pn, itemstr) | ||
165 | else: | 189 | else: |
166 | logger.debug("selecting %s as PREFERRED_VERSION %s of package %s%s", preferred_file, pv_str, pn, itemstr) | 190 | if required: |
167 | 191 | logger.debug("selecting %s as REQUIRED_VERSION %s of package %s%s", preferred_file, pv_str, pn, itemstr) | |
168 | return (preferred_ver, preferred_file) | 192 | else: |
193 | logger.debug("selecting %s as PREFERRED_VERSION %s of package %s%s", preferred_file, pv_str, pn, itemstr) | ||
169 | 194 | ||
195 | return (preferred_ver, preferred_file, required) | ||
170 | 196 | ||
171 | def findLatestProvider(pn, cfgData, dataCache, file_set): | 197 | def findLatestProvider(pn, cfgData, dataCache, file_set): |
172 | """ | 198 | """ |