summaryrefslogtreecommitdiffstats
path: root/meta/classes/update-alternatives.bbclass
diff options
context:
space:
mode:
authorMark Hatle <mark.hatle@windriver.com>2012-05-15 11:06:22 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-05-30 12:04:37 +0100
commit6ac7e9b5981872b22dcd07f0f7171e1f7c10e284 (patch)
tree4e36c4023c1358b108a4546abc60d91fdb425d57 /meta/classes/update-alternatives.bbclass
parentf28209d9d3c67203a2c7a2b25cacfe31643d1bfa (diff)
downloadpoky-6ac7e9b5981872b22dcd07f0f7171e1f7c10e284.tar.gz
update-alternatives.bbclass: Refactor the implementation
Refactor in order to: * Deprecate the old interfaces, but keep them for compatibility * Provide a new, interface -- capable of working with split packages * Each update-alternative will now set proper "per-file" provides Note: this adds a warning message when the older deprecated behavior is used. The older behavior has been fully tested using oe-core. (From OE-Core rev: 309117d26de6a87b16406a44a0cefcbaaf7b5d7a) Signed-off-by: Mark Hatle <mark.hatle@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/update-alternatives.bbclass')
-rw-r--r--meta/classes/update-alternatives.bbclass344
1 files changed, 283 insertions, 61 deletions
diff --git a/meta/classes/update-alternatives.bbclass b/meta/classes/update-alternatives.bbclass
index 7b0518d848..e235299a5b 100644
--- a/meta/classes/update-alternatives.bbclass
+++ b/meta/classes/update-alternatives.bbclass
@@ -3,6 +3,68 @@
3# command directly in your recipe, but in most cases this class simplifies 3# command directly in your recipe, but in most cases this class simplifies
4# that job. 4# that job.
5# 5#
6# To use this class a number of variables should be defined:
7#
8# List all of the alternatives needed by a package:
9# ALTERNATIVE_<pkg> = "name1 name2 name3 ..."
10#
11# i.e. ALTERNATIVE_busybox = "sh sed test bracket"
12#
13# The pathname of the link
14# ALTERNATIVE_LINK_NAME[name] = "target"
15#
16# This is the name of the binary once it's been installed onto the runtime.
17# This name is global to all split packages in this recipe, and should match
18# other recipes with the same functionality.
19# i.e. ALTERNATIVE_LINK_NAME[bracket] = "/usr/bin/["
20#
21# NOTE: If ALTERNATIVE_LINK_NAME is not defined, it defaults to ${bindir}/name
22#
23# The default link to create for all targets
24# ALTERNATIVE_TARGET = "target"
25#
26# This is useful in a multicall binary case
27# i.e. ALTERNATIVE_TARGET = "/bin/busybox"
28#
29# A non-default link to create for a target
30# ALTERNATIVE_TARGET[name] = "target"
31#
32# This is the name of the binary as it's been install by do_install
33# i.e. ALTERNATIVE_TARGET[sh] = "/bin/bash"
34#
35# A package specific link for a target
36# ALTERNATIVE_TARGET_<pkg>[name] = "target"
37#
38# This is useful when a recipe provides multiple alternatives for the
39# same item.
40#
41# NOTE: If ALTERNATIVE_TARGET is not defined, it will inherit the value
42# from ALTERNATIVE_LINK_NAME.
43#
44# NOTE: If the ALTERNATIVE_LINK_NAME and ALTERNATIVE_TARGET are the same,
45# ALTERNATIVE_TARGET will have '.{PN}' appended to it. If the file
46# referenced has not been renamed, it will also be renamed. (This avoids
47# the need to rename alternative files in the do_install step, but still
48# supports it if necessary for some reason.)
49#
50# The default priority for any alternatives
51# ALTERNATIVE_PRIORITY = "priority"
52#
53# i.e. default is ALTERNATIVE_PRIORITY = "10"
54#
55# The non-default priority for a specific target
56# ALTERNATIVE_PRIORITY[name] = "priority"
57#
58# The package priority for a specific target
59# ALTERNATIVE_PRIORITY_<pkg>[name] = "priority"
60#
61#
62# -----
63#
64#
65# The following describes deprecated behavior, using any of the
66# following modes will result in a warning, and eventually an error:
67#
6# There are two basic modes supported: 'single update' and 'batch update' 68# There are two basic modes supported: 'single update' and 'batch update'
7# 69#
8# 'single update' is used for a single alternative command, and you're 70# 'single update' is used for a single alternative command, and you're
@@ -38,79 +100,239 @@
38 100
39# defaults 101# defaults
40ALTERNATIVE_PRIORITY = "10" 102ALTERNATIVE_PRIORITY = "10"
41ALTERNATIVE_LINK = "${bindir}/${ALTERNATIVE_NAME}"
42
43update_alternatives_postinst() {
44update-alternatives --install ${ALTERNATIVE_LINK} ${ALTERNATIVE_NAME} ${ALTERNATIVE_PATH} ${ALTERNATIVE_PRIORITY}
45}
46
47update_alternatives_postrm() {
48update-alternatives --remove ${ALTERNATIVE_NAME} ${ALTERNATIVE_PATH}
49}
50
51# for batch alternatives, we use a simple approach to require only one parameter
52# with the rest of the info deduced implicitly
53update_alternatives_batch_postinst() {
54for link in ${ALTERNATIVE_LINKS}
55do
56 name=`basename ${link}`
57 path=${link}.${PN}
58 update-alternatives --install ${link} ${name} ${path} ${ALTERNATIVE_PRIORITY}
59done
60}
61
62update_alternatives_batch_postrm() {
63for link in ${ALTERNATIVE_LINKS}
64do
65 name=`basename ${link}`
66 path=${link}.${PN}
67 update-alternatives --remove ${name} $path
68done
69}
70
71update_alternatives_batch_doinstall() {
72 for link in ${ALTERNATIVE_LINKS}
73 do
74 mv ${D}${link} ${D}${link}.${PN}
75 done
76}
77 103
104# The following code is deprecated, but included for compatibility with older packages
78def update_alternatives_after_parse(d): 105def update_alternatives_after_parse(d):
79 if bb.data.inherits_class('native', d) or bb.data.inherits_class('nativesdk', d): 106 if bb.data.inherits_class('native', d) or bb.data.inherits_class('nativesdk', d):
80 return 107 return
81 108
109 # The following code is deprecated, but included for compatibility with older packages
110 pn = d.getVar('PN', True)
111
82 if d.getVar('ALTERNATIVE_LINKS') != None: 112 if d.getVar('ALTERNATIVE_LINKS') != None:
83 doinstall = d.getVar('do_install', 0) 113 # Convert old format to new format...
84 doinstall += d.getVar('update_alternatives_batch_doinstall', 0) 114 alt_links = d.getVar('ALTERNATIVE_LINKS', True) or ""
85 d.setVar('do_install', doinstall) 115 for alt_link in alt_links.split():
116 alt_name = os.path.basename(alt_link)
117
118 alternative = d.getVar('ALTERNATIVE_%s' % pn, True) or ""
119 alternative += " " + alt_name
120 d.setVar('ALTERNATIVE_%s' % pn, alternative)
121 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link)
122 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, alt_link)
86 return 123 return
87 124
88 if d.getVar('ALTERNATIVE_NAME') == None: 125 if d.getVar('ALTERNATIVE_NAME') != None or d.getVar('ALTERNATIVE_PATH') != None:
89 raise bb.build.FuncFailed, "%s inherits update-alternatives but doesn't set ALTERNATIVE_NAME" % d.getVar('FILE') 126 # Convert old format to new format...
90 if d.getVar('ALTERNATIVE_PATH') == None: 127 alt_name = d.getVar('ALTERNATIVE_NAME', True)
91 raise bb.build.FuncFailed, "%s inherits update-alternatives but doesn't set ALTERNATIVE_PATH" % d.getVar('FILE') 128 alt_path = d.getVar('ALTERNATIVE_PATH', True)
129 alt_link = d.getVar('ALTERNATIVE_LINK', True) or ("%s/%s" % (d.getVar('bindir', True), alt_name))
130 if alt_name == None:
131 raise bb.build.build.FuncFailed, "%s inherits update-alternatives but doesn't set ALTERNATIVE_NAME" % d.getVar('FILE')
132 if alt_path == None:
133 raise bb.build.build.FuncFailed, "%s inherits update-alternatives but doesn't set ALTERNATIVE_PATH" % d.getVar('FILE')
134
135 alternative = d.getVar('ALTERNATIVE_%s' % pn, True) or ""
136 alternative += " " + alt_name
137
138 # Fix the alt_path if it's relative
139 alt_path = os.path.join(os.path.dirname(alt_link), alt_path)
140
141 d.setVar('ALTERNATIVE_%s' % pn, alternative)
142 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link)
143 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, alt_path)
144
145
146# We need special processing for vardeps because it can not work on
147# modified flag values. So we agregate the flags into a new variable
148# and include that vairable in the set.
149
150UPDALTVARS = "ALTERNATIVE ALTERNATIVE_LINK_NAME ALTERNATIVE_TARGET ALTERNATIVE_PRIORITY"
151
152def gen_updatealternativesvardeps(d):
153 pkgs = (d.getVar("PACKAGES", True) or "").split()
154 vars = (d.getVar("UPDALTVARS", True) or "").split()
155
156 # First compute them for non_pkg versions
157 for v in vars:
158 for flag in (d.getVarFlags(v) or {}):
159 if flag == "doc" or flag == "vardeps" or flag == "vardepsexp":
160 continue
161 d.appendVar('%s_VARDEPS' % (v), ' %s:%s' % (flag, d.getVarFlag(v, flag, False)))
162
163 for p in pkgs:
164 for v in vars:
165 for flag in (d.getVarFlags("%s_%s" % (v,p)) or {}):
166 if flag == "doc" or flag == "vardeps" or flag == "vardepsexp":
167 continue
168 d.appendVar('%s_VARDEPS_%s' % (v,p), ' %s:%s' % (flag, d.getVarFlag('%s_%s' % (v,p), flag, False)))
92 169
93python __anonymous() { 170python __anonymous() {
171 # deprecated stuff...
94 update_alternatives_after_parse(d) 172 update_alternatives_after_parse(d)
173
174 # compute special vardeps
175 gen_updatealternativesvardeps(d)
176}
177
178def gen_updatealternativesvars(d):
179 ret = []
180 pkgs = (d.getVar("PACKAGES", True) or "").split()
181 vars = (d.getVar("UPDALTVARS", True) or "").split()
182
183 for v in vars:
184 ret.append(v + "_VARDEPS")
185
186 for p in pkgs:
187 for v in vars:
188 ret.append(v + "_" + p)
189 ret.append(v + "_VARDEPS_" + p)
190 return " ".join(ret)
191
192# First the deprecated items...
193populate_packages[vardeps] += "ALTERNATIVE_LINKS ALTERNATIVE_NAME ALTERNATIVE_PATH"
194
195# Now the new stuff, we use a custom function to generate the right values
196populate_packages[vardeps] += "${UPDALTVARS} ${@gen_updatealternativesvars(d)}"
197
198# We need to do the rename after the image creation step, but before
199# the split and strip steps.. packagecopy seems to be the earliest reasonable
200# place.
201python perform_packagecopy_append () {
202 # Check for deprecated usage...
203 pn = d.getVar('PN', True)
204 if d.getVar('ALTERNATIVE_LINKS', True) != None:
205 bb.warn('%s: Use of ALTERNATIVE_LINKS is deprecated, see update-alternatives.bbclass for more info.' % pn)
206
207 if d.getVar('ALTERNATIVE_NAME', True) != None or d.getVar('ALTERNATIVE_PATH', True) != None:
208 bb.warn('%s: Use of ALTERNATIVE_NAME is deprecated, see update-alternatives.bbclass for more info.' % pn)
209
210 # Do actual update alternatives processing
211 pkgdest = d.getVar('PKGD', True)
212 for pkg in (d.getVar('PACKAGES', True) or "").split():
213 # If the src == dest, we know we need to rename the dest by appending ${PN}
214 link_rename = {}
215 for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg, True) or "").split():
216 alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name, True)
217 if not alt_link:
218 alt_link = "%s/%s" % (d.getVar('bindir', True), alt_name)
219 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link)
220
221 alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name, True) or d.getVarFlag('ALTERNATIVE_TARGET', alt_name, True)
222 alt_target = alt_target or d.getVar('ALTERNATIVE_TARGET_%s' % pkg, True) or d.getVar('ALTERNATIVE_TARGET', True) or alt_link
223 # Sometimes alt_target is specified as relative to the link name.
224 alt_target = os.path.join(os.path.dirname(alt_link), alt_target)
225
226 # If the link and target are the same name, we need to rename the target.
227 if alt_link == alt_target:
228 src = '%s/%s' % (pkgdest, alt_target)
229 alt_target_rename = '%s.%s' % (alt_target, pn)
230 dest = '%s/%s' % (pkgdest, alt_target_rename)
231 if os.path.lexists(dest):
232 bb.note('%s: Already renamed: %s' % (pn, alt_target_rename))
233 elif os.path.lexists(src):
234 if os.path.islink(src):
235 # Delay rename of links
236 link_rename[alt_target] = alt_target_rename
237 else:
238 bb.note('%s: Rename %s -> %s' % (pn, alt_target, alt_target_rename))
239 os.rename(src, dest)
240 else:
241 bb.warn("%s: alternative target (%s or %s) does not exist, skipping..." % (pn, alt_target, alt_target_rename))
242 continue
243 d.setVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name, alt_target_rename)
244
245 # Process delayed link names
246 # Do these after other renames so we can correct broken links
247 for alt_target in link_rename:
248 src = '%s/%s' % (pkgdest, alt_target)
249 dest = '%s/%s' % (pkgdest, link_rename[alt_target])
250 link_target = os.path.join(os.path.dirname(src), os.readlink(src))
251
252 if os.path.lexists(link_target):
253 # Ok, the link_target exists, we can rename
254 bb.note('%s: Rename (link) %s -> %s' % (pn, alt_target, link_rename[alt_target]))
255 os.rename(src, dest)
256 else:
257 # Try to resolve the broken link to link.${PN}
258 link_maybe = '%s.%s' % (os.readlink(src), pn)
259 if os.path.lexists(os.path.join(os.path.dirname(src), link_maybe)):
260 # Ok, the renamed link target exists.. create a new link, and remove the original
261 bb.note('%s: Creating new link %s -> %s' % (pn, link_rename[alt_target], link_maybe))
262 os.symlink(link_maybe, dest)
263 os.unlink(src)
264 else:
265 bb.warn('%s: Unable to resolve dangling symlink: %s' % (pn, alt_target))
95} 266}
96 267
97python populate_packages_prepend () { 268python populate_packages_prepend () {
98 pkg = d.getVar('PN', True) 269 pn = d.getVar('BPN', True)
99 bb.note('adding update-alternatives calls to postinst/postrm for %s' % pkg) 270
100 postinst = d.getVar('pkg_postinst_%s' % pkg, True) or d.getVar('pkg_postinst', True) 271 # Do actual update alternatives processing
101 if not postinst: 272 pkgdest = d.getVar('PKGD', True)
102 postinst = '#!/bin/sh\n' 273 for pkg in (d.getVar('PACKAGES', True) or "").split():
103 if d.getVar('ALTERNATIVE_LINKS') != None: 274 # Create post install/removal scripts
104 postinst += d.getVar('update_alternatives_batch_postinst', True) 275 alt_setup_links = ""
105 else: 276 alt_remove_links = ""
106 postinst += d.getVar('update_alternatives_postinst', True) 277 for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg, True) or "").split():
107 d.setVar('pkg_postinst_%s' % pkg, postinst) 278 alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name, True)
108 postrm = d.getVar('pkg_postrm_%s' % pkg, True) or d.getVar('pkg_postrm', True) 279 alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name, True) or d.getVarFlag('ALTERNATIVE_TARGET', alt_name, True)
109 if not postrm: 280 alt_target = alt_target or d.getVar('ALTERNATIVE_TARGET_%s' % pkg, True) or d.getVar('ALTERNATIVE_TARGET', True) or alt_link
110 postrm = '#!/bin/sh\n' 281 # Sometimes alt_target is specified as relative to the link name.
111 if d.getVar('ALTERNATIVE_LINKS') != None: 282 alt_target = os.path.join(os.path.dirname(alt_link), alt_target)
112 postrm += d.getVar('update_alternatives_batch_postrm', True) 283
113 else: 284 alt_priority = d.getVarFlag('ALTERNATIVE_PRIORITY_%s' % pkg, alt_name, True) or d.getVarFlag('ALTERNATIVE_PRIORITY', alt_name, True)
114 postrm += d.getVar('update_alternatives_postrm', True) 285 alt_priority = alt_priority or d.getVar('ALTERNATIVE_PRIORITY_%s' % pkg, True) or d.getVar('ALTERNATIVE_PRIORITY', True)
115 d.setVar('pkg_postrm_%s' % pkg, postrm) 286
287 # This shouldn't trigger, as it should have been resolved earlier!
288 if alt_link == alt_target:
289 bb.note('alt_link == alt_target: %s == %s -- correcting, this should not happen!' % (alt_link, alt_target))
290 alt_target = '%s.%s' % (alt_target, pn)
291
292 if not os.path.lexists('%s/%s' % (pkgdest, alt_target)):
293 bb.warn('%s: NOT adding alternative provide %s: %s does not exist' % (pn, alt_link, alt_target))
294 continue
295
296 # Default to generate shell script.. eventually we may want to change this...
297 alt_target = os.path.relpath(alt_target, os.path.dirname(alt_link))
298
299 alt_setup_links += ' update-alternatives --install %s %s %s %s\n' % (alt_link, alt_name, alt_target, alt_priority)
300 alt_remove_links += ' update-alternatives --remove %s %s\n' % (alt_name, alt_target)
301
302 if alt_setup_links:
303 bb.note('adding update-alternatives calls to postinst/postrm for %s' % pkg)
304 bb.note('%s' % alt_setup_links)
305 postinst = (d.getVar('pkg_postinst_%s' % pkg, True) or d.getVar('pkg_postinst', True)) or '#!/bin/sh\n'
306 postinst += alt_setup_links
307 d.setVar('pkg_postinst_%s' % pkg, postinst)
308
309 bb.note('%s' % alt_remove_links)
310 postrm = (d.getVar('pkg_postrm_%s' % pkg, True) or d.getVar('pkg_postrm', True)) or '#!/bin/sh\n'
311 postrm += alt_remove_links
312 d.setVar('pkg_postrm_%s' % pkg, postrm)
116} 313}
314
315python package_do_filedeps_append () {
316 pn = d.getVar('PN', True)
317 pkgdest = d.getVar('PKGDEST', True)
318
319 for pkg in packages.split():
320 for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg, True) or "").split():
321 alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name, True)
322 alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name, True) or d.getVarFlag('ALTERNATIVE_TARGET', alt_name, True)
323 alt_target = alt_target or d.getVar('ALTERNATIVE_TARGET_%s' % pkg, True) or d.getVar('ALTERNATIVE_TARGET', True) or alt_link
324
325 if alt_link == alt_target:
326 bb.warn('alt_link == alt_target: %s == %s' % (alt_link, alt_target))
327 alt_target = '%s.%s' % (alt_target, pn)
328
329 if not os.path.lexists('%s/%s/%s' % (pkgdest, pkg, alt_target)):
330 continue
331
332 # Add file provide
333 trans_target = file_translate(alt_target)
334 d.appendVar('FILERPROVIDES_%s_%s' % (trans_target, pkg), " " + alt_link)
335 if not trans_target in (d.getVar('FILERPROVIDESFLIST_%s' % pkg, True) or ""):
336 d.appendVar('FILERPROVIDESFLIST_%s' % pkg, " " + trans_target)
337}
338