1 # ex:ts=4:sw=4:sts=4:et
2 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4 # Copyright (C) 2003, 2004 Chris Larson
5 # Copyright (C) 2003, 2004 Phil Blundell
6 # Copyright (C) 2003 - 2005 Michael 'Mickey' Lauer
7 # Copyright (C) 2005 Holger Hans Peter Freyther
8 # Copyright (C) 2005 ROAD GmbH
9 # Copyright (C) 2006 Richard Purdie
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License version 2 as
13 # published by the Free Software Foundation.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 from bb import data, utils
28 class NoProvider(Exception):
29 """Exception raised when no provider of a build dependency can be found"""
31 class NoRProvider(Exception):
32 """Exception raised when no provider of a runtime dependency can be found"""
34 def findBestProvider(pn, cfgData, dataCache, pkg_pn = None, item = None):
36 If there is a PREFERRED_VERSION, find the highest-priority bbfile
37 providing that version. If not, find the latest version provided by
38 an bbfile in the highest-priority set.
41 pkg_pn = dataCache.pkg_pn
46 priority = dataCache.bbfile_priority[f]
47 if priority not in priorities:
48 priorities[priority] = []
49 priorities[priority].append(f)
50 p_list = priorities.keys()
51 p_list.sort(lambda a, b: a - b)
54 tmp_pn = [priorities[p]] + tmp_pn
58 localdata = data.createCopy(cfgData)
59 bb.data.setVar('OVERRIDES', "%s:%s" % (pn, data.getVar('OVERRIDES', localdata)), localdata)
60 bb.data.update_data(localdata)
62 preferred_v = bb.data.getVar('PREFERRED_VERSION_%s' % pn, localdata, True)
64 m = re.match('(.*)_(.*)', preferred_v)
66 preferred_v = m.group(1)
67 preferred_r = m.group(2)
71 for file_set in tmp_pn:
73 pv,pr = dataCache.pkg_pvpr[f]
74 if preferred_v == pv and (preferred_r == pr or preferred_r == None):
76 preferred_ver = (pv, pr)
81 pv_str = '%s-%s' % (preferred_v, preferred_r)
86 itemstr = " (for item %s)" % item
87 if preferred_file is None:
88 bb.msg.note(1, bb.msg.domain.Provider, "preferred version %s of %s not available%s" % (pv_str, pn, itemstr))
90 bb.msg.debug(1, bb.msg.domain.Provider, "selecting %s as PREFERRED_VERSION %s of package %s%s" % (preferred_file, pv_str, pn, itemstr))
94 # get highest priority file set
99 for file_name in files:
100 pv,pr = dataCache.pkg_pvpr[file_name]
101 dp = dataCache.pkg_dp[file_name]
103 if (latest is None) or ((latest_p == dp) and (utils.vercmp(latest, (pv, pr)) < 0)) or (dp > latest_p):
107 if preferred_file is None:
108 preferred_file = latest_f
109 preferred_ver = latest
111 return (latest,latest_f,preferred_ver, preferred_file)
113 def filterProviders(providers, item, cfgData, dataCache):
115 Take a list of providers and filter/reorder according to the
116 environment variables and previous build results
119 preferred_versions = {}
121 # Collate providers by PN
124 pn = dataCache.pkg_fn[p]
129 bb.msg.debug(1, bb.msg.domain.Provider, "providers for %s are: %s" % (item, pkg_pn.keys()))
131 for pn in pkg_pn.keys():
132 preferred_versions[pn] = bb.providers.findBestProvider(pn, cfgData, dataCache, pkg_pn, item)[2:4]
133 eligible.append(preferred_versions[pn][1])
135 if len(eligible) == 0:
136 bb.msg.error(bb.msg.domain.Provider, "no eligible providers for %s" % item)
140 # If pn == item, give it a slight default preference
141 # This means PREFERRED_PROVIDER_foobar defaults to foobar if available
143 pn = dataCache.pkg_fn[p]
146 (newvers, fn) = preferred_versions[pn]
147 if not fn in eligible:
150 eligible = [fn] + eligible
152 # look to see if one of them is already staged, or marked as preferred.
153 # if so, bump it to the head of the queue
155 pn = dataCache.pkg_fn[p]
156 pv, pr = dataCache.pkg_pvpr[p]
158 stamp = '%s.do_populate_staging' % dataCache.stamp[p]
159 if os.path.exists(stamp):
160 (newvers, fn) = preferred_versions[pn]
161 if not fn in eligible:
162 # package was made ineligible by already-failed check
164 oldver = "%s-%s" % (pv, pr)
165 newver = '-'.join(newvers)
166 if (newver != oldver):
167 extra_chat = "%s (%s) already staged but upgrading to %s to satisfy %s" % (pn, oldver, newver, item)
169 extra_chat = "Selecting already-staged %s (%s) to satisfy %s" % (pn, oldver, item)
171 bb.msg.note(2, bb.msg.domain.Provider, "%s" % extra_chat)
173 eligible = [fn] + eligible
178 def getRuntimeProviders(dataCache, rdepend):
180 Return any providers of runtime dependency
184 if rdepend in dataCache.rproviders:
185 rproviders += dataCache.rproviders[rdepend]
187 if rdepend in dataCache.packages:
188 rproviders += dataCache.packages[rdepend]
193 # Only search dynamic packages if we can't find anything in other variables
194 for pattern in dataCache.packages_dynamic:
195 regexp = re.compile(pattern)
196 if regexp.match(rdepend):
197 rproviders += dataCache.packages_dynamic[pattern]