diff options
Diffstat (limited to 'meta/classes/staging.bbclass')
-rw-r--r-- | meta/classes/staging.bbclass | 625 |
1 files changed, 0 insertions, 625 deletions
diff --git a/meta/classes/staging.bbclass b/meta/classes/staging.bbclass deleted file mode 100644 index 806a85773a..0000000000 --- a/meta/classes/staging.bbclass +++ /dev/null | |||
@@ -1,625 +0,0 @@ | |||
1 | # These directories will be staged in the sysroot | ||
2 | SYSROOT_DIRS = " \ | ||
3 | ${includedir} \ | ||
4 | ${libdir} \ | ||
5 | ${base_libdir} \ | ||
6 | ${nonarch_base_libdir} \ | ||
7 | ${datadir} \ | ||
8 | /sysroot-only \ | ||
9 | " | ||
10 | |||
11 | # These directories are also staged in the sysroot when they contain files that | ||
12 | # are usable on the build system | ||
13 | SYSROOT_DIRS_NATIVE = " \ | ||
14 | ${bindir} \ | ||
15 | ${sbindir} \ | ||
16 | ${base_bindir} \ | ||
17 | ${base_sbindir} \ | ||
18 | ${libexecdir} \ | ||
19 | ${sysconfdir} \ | ||
20 | ${localstatedir} \ | ||
21 | " | ||
22 | SYSROOT_DIRS_append_class-native = " ${SYSROOT_DIRS_NATIVE}" | ||
23 | SYSROOT_DIRS_append_class-cross = " ${SYSROOT_DIRS_NATIVE}" | ||
24 | SYSROOT_DIRS_append_class-crosssdk = " ${SYSROOT_DIRS_NATIVE}" | ||
25 | |||
26 | # These directories will not be staged in the sysroot | ||
27 | SYSROOT_DIRS_BLACKLIST = " \ | ||
28 | ${mandir} \ | ||
29 | ${docdir} \ | ||
30 | ${infodir} \ | ||
31 | ${datadir}/X11/locale \ | ||
32 | ${datadir}/applications \ | ||
33 | ${datadir}/bash-completion \ | ||
34 | ${datadir}/fonts \ | ||
35 | ${datadir}/gtk-doc/html \ | ||
36 | ${datadir}/installed-tests \ | ||
37 | ${datadir}/locale \ | ||
38 | ${datadir}/pixmaps \ | ||
39 | ${datadir}/terminfo \ | ||
40 | ${libdir}/${BPN}/ptest \ | ||
41 | " | ||
42 | |||
43 | sysroot_stage_dir() { | ||
44 | src="$1" | ||
45 | dest="$2" | ||
46 | # if the src doesn't exist don't do anything | ||
47 | if [ ! -d "$src" ]; then | ||
48 | return | ||
49 | fi | ||
50 | |||
51 | mkdir -p "$dest" | ||
52 | ( | ||
53 | cd $src | ||
54 | find . -print0 | cpio --null -pdlu $dest | ||
55 | ) | ||
56 | } | ||
57 | |||
58 | sysroot_stage_dirs() { | ||
59 | from="$1" | ||
60 | to="$2" | ||
61 | |||
62 | for dir in ${SYSROOT_DIRS}; do | ||
63 | sysroot_stage_dir "$from$dir" "$to$dir" | ||
64 | done | ||
65 | |||
66 | # Remove directories we do not care about | ||
67 | for dir in ${SYSROOT_DIRS_BLACKLIST}; do | ||
68 | rm -rf "$to$dir" | ||
69 | done | ||
70 | } | ||
71 | |||
72 | sysroot_stage_all() { | ||
73 | sysroot_stage_dirs ${D} ${SYSROOT_DESTDIR} | ||
74 | } | ||
75 | |||
76 | python sysroot_strip () { | ||
77 | inhibit_sysroot = d.getVar('INHIBIT_SYSROOT_STRIP') | ||
78 | if inhibit_sysroot and oe.types.boolean(inhibit_sysroot): | ||
79 | return | ||
80 | |||
81 | dstdir = d.getVar('SYSROOT_DESTDIR') | ||
82 | pn = d.getVar('PN') | ||
83 | libdir = d.getVar("libdir") | ||
84 | base_libdir = d.getVar("base_libdir") | ||
85 | qa_already_stripped = 'already-stripped' in (d.getVar('INSANE_SKIP_' + pn) or "").split() | ||
86 | strip_cmd = d.getVar("STRIP") | ||
87 | |||
88 | oe.package.strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, d, | ||
89 | qa_already_stripped=qa_already_stripped) | ||
90 | } | ||
91 | |||
92 | do_populate_sysroot[dirs] = "${SYSROOT_DESTDIR}" | ||
93 | |||
94 | addtask populate_sysroot after do_install | ||
95 | |||
96 | SYSROOT_PREPROCESS_FUNCS ?= "" | ||
97 | SYSROOT_DESTDIR = "${WORKDIR}/sysroot-destdir" | ||
98 | |||
99 | python do_populate_sysroot () { | ||
100 | # SYSROOT 'version' 2 | ||
101 | bb.build.exec_func("sysroot_stage_all", d) | ||
102 | bb.build.exec_func("sysroot_strip", d) | ||
103 | for f in (d.getVar('SYSROOT_PREPROCESS_FUNCS') or '').split(): | ||
104 | bb.build.exec_func(f, d) | ||
105 | pn = d.getVar("PN") | ||
106 | multiprov = d.getVar("MULTI_PROVIDER_WHITELIST").split() | ||
107 | provdir = d.expand("${SYSROOT_DESTDIR}${base_prefix}/sysroot-providers/") | ||
108 | bb.utils.mkdirhier(provdir) | ||
109 | for p in d.getVar("PROVIDES").split(): | ||
110 | if p in multiprov: | ||
111 | continue | ||
112 | p = p.replace("/", "_") | ||
113 | with open(provdir + p, "w") as f: | ||
114 | f.write(pn) | ||
115 | } | ||
116 | |||
117 | do_populate_sysroot[vardeps] += "${SYSROOT_PREPROCESS_FUNCS}" | ||
118 | do_populate_sysroot[vardepsexclude] += "MULTI_PROVIDER_WHITELIST" | ||
119 | |||
120 | POPULATESYSROOTDEPS = "" | ||
121 | POPULATESYSROOTDEPS_class-target = "virtual/${MLPREFIX}${TARGET_PREFIX}binutils:do_populate_sysroot" | ||
122 | POPULATESYSROOTDEPS_class-nativesdk = "virtual/${TARGET_PREFIX}binutils-crosssdk:do_populate_sysroot" | ||
123 | do_populate_sysroot[depends] += "${POPULATESYSROOTDEPS}" | ||
124 | |||
125 | SSTATETASKS += "do_populate_sysroot" | ||
126 | do_populate_sysroot[cleandirs] = "${SYSROOT_DESTDIR}" | ||
127 | do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}" | ||
128 | do_populate_sysroot[sstate-outputdirs] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}" | ||
129 | do_populate_sysroot[sstate-fixmedir] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}" | ||
130 | |||
131 | python do_populate_sysroot_setscene () { | ||
132 | sstate_setscene(d) | ||
133 | } | ||
134 | addtask do_populate_sysroot_setscene | ||
135 | |||
136 | def staging_copyfile(c, target, dest, postinsts, seendirs): | ||
137 | import errno | ||
138 | |||
139 | destdir = os.path.dirname(dest) | ||
140 | if destdir not in seendirs: | ||
141 | bb.utils.mkdirhier(destdir) | ||
142 | seendirs.add(destdir) | ||
143 | if "/usr/bin/postinst-" in c: | ||
144 | postinsts.append(dest) | ||
145 | if os.path.islink(c): | ||
146 | linkto = os.readlink(c) | ||
147 | if os.path.lexists(dest): | ||
148 | if not os.path.islink(dest): | ||
149 | raise OSError(errno.EEXIST, "Link %s already exists as a file" % dest, dest) | ||
150 | if os.readlink(dest) == linkto: | ||
151 | return dest | ||
152 | raise OSError(errno.EEXIST, "Link %s already exists to a different location? (%s vs %s)" % (dest, os.readlink(dest), linkto), dest) | ||
153 | os.symlink(linkto, dest) | ||
154 | #bb.warn(c) | ||
155 | else: | ||
156 | try: | ||
157 | os.link(c, dest) | ||
158 | except OSError as err: | ||
159 | if err.errno == errno.EXDEV: | ||
160 | bb.utils.copyfile(c, dest) | ||
161 | else: | ||
162 | raise | ||
163 | return dest | ||
164 | |||
165 | def staging_copydir(c, target, dest, seendirs): | ||
166 | if dest not in seendirs: | ||
167 | bb.utils.mkdirhier(dest) | ||
168 | seendirs.add(dest) | ||
169 | |||
170 | def staging_processfixme(fixme, target, recipesysroot, recipesysrootnative, d): | ||
171 | import subprocess | ||
172 | |||
173 | if not fixme: | ||
174 | return | ||
175 | cmd = "sed -e 's:^[^/]*/:%s/:g' %s | xargs sed -i -e 's:FIXMESTAGINGDIRTARGET:%s:g; s:FIXMESTAGINGDIRHOST:%s:g'" % (target, " ".join(fixme), recipesysroot, recipesysrootnative) | ||
176 | for fixmevar in ['PSEUDO_SYSROOT', 'HOSTTOOLS_DIR', 'PKGDATA_DIR', 'PSEUDO_LOCALSTATEDIR', 'LOGFIFO']: | ||
177 | fixme_path = d.getVar(fixmevar) | ||
178 | cmd += " -e 's:FIXME_%s:%s:g'" % (fixmevar, fixme_path) | ||
179 | bb.debug(2, cmd) | ||
180 | subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) | ||
181 | |||
182 | |||
183 | def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d): | ||
184 | import glob | ||
185 | import subprocess | ||
186 | import errno | ||
187 | |||
188 | fixme = [] | ||
189 | postinsts = [] | ||
190 | seendirs = set() | ||
191 | stagingdir = d.getVar("STAGING_DIR") | ||
192 | if native: | ||
193 | pkgarchs = ['${BUILD_ARCH}', '${BUILD_ARCH}_*'] | ||
194 | targetdir = nativesysroot | ||
195 | else: | ||
196 | pkgarchs = ['${MACHINE_ARCH}'] | ||
197 | pkgarchs = pkgarchs + list(reversed(d.getVar("PACKAGE_EXTRA_ARCHS").split())) | ||
198 | pkgarchs.append('allarch') | ||
199 | targetdir = targetsysroot | ||
200 | |||
201 | bb.utils.mkdirhier(targetdir) | ||
202 | for pkgarch in pkgarchs: | ||
203 | for manifest in glob.glob(d.expand("${SSTATE_MANIFESTS}/manifest-%s-*.populate_sysroot" % pkgarch)): | ||
204 | if manifest.endswith("-initial.populate_sysroot"): | ||
205 | # skip libgcc-initial due to file overlap | ||
206 | continue | ||
207 | if not native and (manifest.endswith("-native.populate_sysroot") or "nativesdk-" in manifest): | ||
208 | continue | ||
209 | if native and not (manifest.endswith("-native.populate_sysroot") or manifest.endswith("-cross.populate_sysroot") or "-cross-" in manifest): | ||
210 | continue | ||
211 | tmanifest = targetdir + "/" + os.path.basename(manifest) | ||
212 | if os.path.exists(tmanifest): | ||
213 | continue | ||
214 | try: | ||
215 | os.link(manifest, tmanifest) | ||
216 | except OSError as err: | ||
217 | if err.errno == errno.EXDEV: | ||
218 | bb.utils.copyfile(manifest, tmanifest) | ||
219 | else: | ||
220 | raise | ||
221 | with open(manifest, "r") as f: | ||
222 | for l in f: | ||
223 | l = l.strip() | ||
224 | if l.endswith("/fixmepath"): | ||
225 | fixme.append(l) | ||
226 | continue | ||
227 | if l.endswith("/fixmepath.cmd"): | ||
228 | continue | ||
229 | dest = l.replace(stagingdir, "") | ||
230 | dest = targetdir + "/" + "/".join(dest.split("/")[3:]) | ||
231 | if l.endswith("/"): | ||
232 | staging_copydir(l, targetdir, dest, seendirs) | ||
233 | continue | ||
234 | try: | ||
235 | staging_copyfile(l, targetdir, dest, postinsts, seendirs) | ||
236 | except FileExistsError: | ||
237 | continue | ||
238 | |||
239 | staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot, d) | ||
240 | for p in postinsts: | ||
241 | subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT) | ||
242 | |||
243 | # | ||
244 | # Manifests here are complicated. The main sysroot area has the unpacked sstate | ||
245 | # which us unrelocated and tracked by the main sstate manifests. Each recipe | ||
246 | # specific sysroot has manifests for each dependency that is installed there. | ||
247 | # The task hash is used to tell whether the data needs to be reinstalled. We | ||
248 | # use a symlink to point to the currently installed hash. There is also a | ||
249 | # "complete" stamp file which is used to mark if installation completed. If | ||
250 | # something fails (e.g. a postinst), this won't get written and we would | ||
251 | # remove and reinstall the dependency. This also means partially installed | ||
252 | # dependencies should get cleaned up correctly. | ||
253 | # | ||
254 | |||
255 | python extend_recipe_sysroot() { | ||
256 | import copy | ||
257 | import subprocess | ||
258 | import errno | ||
259 | import collections | ||
260 | import glob | ||
261 | |||
262 | taskdepdata = d.getVar("BB_TASKDEPDATA", False) | ||
263 | mytaskname = d.getVar("BB_RUNTASK") | ||
264 | if mytaskname.endswith("_setscene"): | ||
265 | mytaskname = mytaskname.replace("_setscene", "") | ||
266 | workdir = d.getVar("WORKDIR") | ||
267 | #bb.warn(str(taskdepdata)) | ||
268 | pn = d.getVar("PN") | ||
269 | stagingdir = d.getVar("STAGING_DIR") | ||
270 | sharedmanifests = d.getVar("COMPONENTS_DIR") + "/manifests" | ||
271 | recipesysroot = d.getVar("RECIPE_SYSROOT") | ||
272 | recipesysrootnative = d.getVar("RECIPE_SYSROOT_NATIVE") | ||
273 | |||
274 | # Detect bitbake -b usage | ||
275 | nodeps = d.getVar("BB_LIMITEDDEPS") or False | ||
276 | if nodeps: | ||
277 | lock = bb.utils.lockfile(recipesysroot + "/sysroot.lock") | ||
278 | staging_populate_sysroot_dir(recipesysroot, recipesysrootnative, True, d) | ||
279 | staging_populate_sysroot_dir(recipesysroot, recipesysrootnative, False, d) | ||
280 | bb.utils.unlockfile(lock) | ||
281 | return | ||
282 | |||
283 | start = None | ||
284 | configuredeps = [] | ||
285 | owntaskdeps = [] | ||
286 | for dep in taskdepdata: | ||
287 | data = taskdepdata[dep] | ||
288 | if data[1] == mytaskname and data[0] == pn: | ||
289 | start = dep | ||
290 | elif data[0] == pn: | ||
291 | owntaskdeps.append(data[1]) | ||
292 | if start is None: | ||
293 | bb.fatal("Couldn't find ourself in BB_TASKDEPDATA?") | ||
294 | |||
295 | # We need to figure out which sysroot files we need to expose to this task. | ||
296 | # This needs to match what would get restored from sstate, which is controlled | ||
297 | # ultimately by calls from bitbake to setscene_depvalid(). | ||
298 | # That function expects a setscene dependency tree. We build a dependency tree | ||
299 | # condensed to inter-sstate task dependencies, similar to that used by setscene | ||
300 | # tasks. We can then call into setscene_depvalid() and decide | ||
301 | # which dependencies we can "see" and should expose in the recipe specific sysroot. | ||
302 | setscenedeps = copy.deepcopy(taskdepdata) | ||
303 | |||
304 | start = set([start]) | ||
305 | |||
306 | sstatetasks = d.getVar("SSTATETASKS").split() | ||
307 | # Add recipe specific tasks referenced by setscene_depvalid() | ||
308 | sstatetasks.append("do_stash_locale") | ||
309 | |||
310 | def print_dep_tree(deptree): | ||
311 | data = "" | ||
312 | for dep in deptree: | ||
313 | deps = " " + "\n ".join(deptree[dep][3]) + "\n" | ||
314 | data = data + "%s:\n %s\n %s\n%s %s\n %s\n" % (deptree[dep][0], deptree[dep][1], deptree[dep][2], deps, deptree[dep][4], deptree[dep][5]) | ||
315 | return data | ||
316 | |||
317 | #bb.note("Full dep tree is:\n%s" % print_dep_tree(taskdepdata)) | ||
318 | |||
319 | #bb.note(" start2 is %s" % str(start)) | ||
320 | |||
321 | # If start is an sstate task (like do_package) we need to add in its direct dependencies | ||
322 | # else the code below won't recurse into them. | ||
323 | for dep in set(start): | ||
324 | for dep2 in setscenedeps[dep][3]: | ||
325 | start.add(dep2) | ||
326 | start.remove(dep) | ||
327 | |||
328 | #bb.note(" start3 is %s" % str(start)) | ||
329 | |||
330 | # Create collapsed do_populate_sysroot -> do_populate_sysroot tree | ||
331 | for dep in taskdepdata: | ||
332 | data = setscenedeps[dep] | ||
333 | if data[1] not in sstatetasks: | ||
334 | for dep2 in setscenedeps: | ||
335 | data2 = setscenedeps[dep2] | ||
336 | if dep in data2[3]: | ||
337 | data2[3].update(setscenedeps[dep][3]) | ||
338 | data2[3].remove(dep) | ||
339 | if dep in start: | ||
340 | start.update(setscenedeps[dep][3]) | ||
341 | start.remove(dep) | ||
342 | del setscenedeps[dep] | ||
343 | |||
344 | # Remove circular references | ||
345 | for dep in setscenedeps: | ||
346 | if dep in setscenedeps[dep][3]: | ||
347 | setscenedeps[dep][3].remove(dep) | ||
348 | |||
349 | #bb.note("Computed dep tree is:\n%s" % print_dep_tree(setscenedeps)) | ||
350 | #bb.note(" start is %s" % str(start)) | ||
351 | |||
352 | # Direct dependencies should be present and can be depended upon | ||
353 | for dep in set(start): | ||
354 | if setscenedeps[dep][1] == "do_populate_sysroot": | ||
355 | if dep not in configuredeps: | ||
356 | configuredeps.append(dep) | ||
357 | bb.note("Direct dependencies are %s" % str(configuredeps)) | ||
358 | #bb.note(" or %s" % str(start)) | ||
359 | |||
360 | msgbuf = [] | ||
361 | # Call into setscene_depvalid for each sub-dependency and only copy sysroot files | ||
362 | # for ones that would be restored from sstate. | ||
363 | done = list(start) | ||
364 | next = list(start) | ||
365 | while next: | ||
366 | new = [] | ||
367 | for dep in next: | ||
368 | data = setscenedeps[dep] | ||
369 | for datadep in data[3]: | ||
370 | if datadep in done: | ||
371 | continue | ||
372 | taskdeps = {} | ||
373 | taskdeps[dep] = setscenedeps[dep][:2] | ||
374 | taskdeps[datadep] = setscenedeps[datadep][:2] | ||
375 | retval = setscene_depvalid(datadep, taskdeps, [], d, msgbuf) | ||
376 | if retval: | ||
377 | msgbuf.append("Skipping setscene dependency %s for installation into the sysroot" % datadep) | ||
378 | continue | ||
379 | done.append(datadep) | ||
380 | new.append(datadep) | ||
381 | if datadep not in configuredeps and setscenedeps[datadep][1] == "do_populate_sysroot": | ||
382 | configuredeps.append(datadep) | ||
383 | msgbuf.append("Adding dependency on %s" % setscenedeps[datadep][0]) | ||
384 | else: | ||
385 | msgbuf.append("Following dependency on %s" % setscenedeps[datadep][0]) | ||
386 | next = new | ||
387 | |||
388 | # This logging is too verbose for day to day use sadly | ||
389 | #bb.debug(2, "\n".join(msgbuf)) | ||
390 | |||
391 | depdir = recipesysrootnative + "/installeddeps" | ||
392 | bb.utils.mkdirhier(depdir) | ||
393 | bb.utils.mkdirhier(sharedmanifests) | ||
394 | |||
395 | lock = bb.utils.lockfile(recipesysroot + "/sysroot.lock") | ||
396 | |||
397 | fixme = {} | ||
398 | seendirs = set() | ||
399 | postinsts = [] | ||
400 | multilibs = {} | ||
401 | manifests = {} | ||
402 | # All files that we're going to be installing, to find conflicts. | ||
403 | fileset = {} | ||
404 | |||
405 | for f in os.listdir(depdir): | ||
406 | if not f.endswith(".complete"): | ||
407 | continue | ||
408 | f = depdir + "/" + f | ||
409 | if os.path.islink(f) and not os.path.exists(f): | ||
410 | bb.note("%s no longer exists, removing from sysroot" % f) | ||
411 | lnk = os.readlink(f.replace(".complete", "")) | ||
412 | sstate_clean_manifest(depdir + "/" + lnk, d, workdir) | ||
413 | os.unlink(f) | ||
414 | os.unlink(f.replace(".complete", "")) | ||
415 | |||
416 | installed = [] | ||
417 | for dep in configuredeps: | ||
418 | c = setscenedeps[dep][0] | ||
419 | if mytaskname in ["do_sdk_depends", "do_populate_sdk_ext"] and c.endswith("-initial"): | ||
420 | bb.note("Skipping initial setscene dependency %s for installation into the sysroot" % c) | ||
421 | continue | ||
422 | installed.append(c) | ||
423 | |||
424 | # We want to remove anything which this task previously installed but is no longer a dependency | ||
425 | taskindex = depdir + "/" + "index." + mytaskname | ||
426 | if os.path.exists(taskindex): | ||
427 | potential = [] | ||
428 | with open(taskindex, "r") as f: | ||
429 | for l in f: | ||
430 | l = l.strip() | ||
431 | if l not in installed: | ||
432 | fl = depdir + "/" + l | ||
433 | if not os.path.exists(fl): | ||
434 | # Was likely already uninstalled | ||
435 | continue | ||
436 | potential.append(l) | ||
437 | # We need to ensure no other task needs this dependency. We hold the sysroot | ||
438 | # lock so we ca search the indexes to check | ||
439 | if potential: | ||
440 | for i in glob.glob(depdir + "/index.*"): | ||
441 | if i.endswith("." + mytaskname): | ||
442 | continue | ||
443 | with open(i, "r") as f: | ||
444 | for l in f: | ||
445 | if l.startswith("TaskDeps:"): | ||
446 | prevtasks = l.split()[1:] | ||
447 | if mytaskname in prevtasks: | ||
448 | # We're a dependency of this task so we can clear items out the sysroot | ||
449 | break | ||
450 | l = l.strip() | ||
451 | if l in potential: | ||
452 | potential.remove(l) | ||
453 | for l in potential: | ||
454 | fl = depdir + "/" + l | ||
455 | bb.note("Task %s no longer depends on %s, removing from sysroot" % (mytaskname, l)) | ||
456 | lnk = os.readlink(fl) | ||
457 | sstate_clean_manifest(depdir + "/" + lnk, d, workdir) | ||
458 | os.unlink(fl) | ||
459 | os.unlink(fl + ".complete") | ||
460 | |||
461 | msg_exists = [] | ||
462 | msg_adding = [] | ||
463 | |||
464 | # Handle all removals first since files may move between recipes | ||
465 | for dep in configuredeps: | ||
466 | c = setscenedeps[dep][0] | ||
467 | if c not in installed: | ||
468 | continue | ||
469 | taskhash = setscenedeps[dep][5] | ||
470 | taskmanifest = depdir + "/" + c + "." + taskhash | ||
471 | |||
472 | if os.path.exists(depdir + "/" + c): | ||
473 | lnk = os.readlink(depdir + "/" + c) | ||
474 | if lnk == c + "." + taskhash and os.path.exists(depdir + "/" + c + ".complete"): | ||
475 | continue | ||
476 | else: | ||
477 | bb.note("%s exists in sysroot, but is stale (%s vs. %s), removing." % (c, lnk, c + "." + taskhash)) | ||
478 | sstate_clean_manifest(depdir + "/" + lnk, d, workdir) | ||
479 | os.unlink(depdir + "/" + c) | ||
480 | if os.path.lexists(depdir + "/" + c + ".complete"): | ||
481 | os.unlink(depdir + "/" + c + ".complete") | ||
482 | elif os.path.lexists(depdir + "/" + c): | ||
483 | os.unlink(depdir + "/" + c) | ||
484 | |||
485 | binfiles = {} | ||
486 | # Now handle installs | ||
487 | for dep in configuredeps: | ||
488 | c = setscenedeps[dep][0] | ||
489 | if c not in installed: | ||
490 | continue | ||
491 | taskhash = setscenedeps[dep][5] | ||
492 | taskmanifest = depdir + "/" + c + "." + taskhash | ||
493 | |||
494 | if os.path.exists(depdir + "/" + c): | ||
495 | lnk = os.readlink(depdir + "/" + c) | ||
496 | if lnk == c + "." + taskhash and os.path.exists(depdir + "/" + c + ".complete"): | ||
497 | msg_exists.append(c) | ||
498 | continue | ||
499 | |||
500 | msg_adding.append(c) | ||
501 | |||
502 | os.symlink(c + "." + taskhash, depdir + "/" + c) | ||
503 | |||
504 | manifest, d2 = oe.sstatesig.find_sstate_manifest(c, setscenedeps[dep][2], "populate_sysroot", d, multilibs) | ||
505 | if d2 is not d: | ||
506 | # If we don't do this, the recipe sysroot will be placed in the wrong WORKDIR for multilibs | ||
507 | # We need a consistent WORKDIR for the image | ||
508 | d2.setVar("WORKDIR", d.getVar("WORKDIR")) | ||
509 | destsysroot = d2.getVar("RECIPE_SYSROOT") | ||
510 | # We put allarch recipes into the default sysroot | ||
511 | if manifest and "allarch" in manifest: | ||
512 | destsysroot = d.getVar("RECIPE_SYSROOT") | ||
513 | |||
514 | native = False | ||
515 | if c.endswith("-native") or "-cross-" in c or "-crosssdk" in c: | ||
516 | native = True | ||
517 | |||
518 | if manifest: | ||
519 | newmanifest = collections.OrderedDict() | ||
520 | targetdir = destsysroot | ||
521 | if native: | ||
522 | targetdir = recipesysrootnative | ||
523 | if targetdir not in fixme: | ||
524 | fixme[targetdir] = [] | ||
525 | fm = fixme[targetdir] | ||
526 | |||
527 | with open(manifest, "r") as f: | ||
528 | manifests[dep] = manifest | ||
529 | for l in f: | ||
530 | l = l.strip() | ||
531 | if l.endswith("/fixmepath"): | ||
532 | fm.append(l) | ||
533 | continue | ||
534 | if l.endswith("/fixmepath.cmd"): | ||
535 | continue | ||
536 | dest = l.replace(stagingdir, "") | ||
537 | dest = "/" + "/".join(dest.split("/")[3:]) | ||
538 | newmanifest[l] = targetdir + dest | ||
539 | |||
540 | # Check if files have already been installed by another | ||
541 | # recipe and abort if they have, explaining what recipes are | ||
542 | # conflicting. | ||
543 | hashname = targetdir + dest | ||
544 | if not hashname.endswith("/"): | ||
545 | if hashname in fileset: | ||
546 | bb.fatal("The file %s is installed by both %s and %s, aborting" % (dest, c, fileset[hashname])) | ||
547 | else: | ||
548 | fileset[hashname] = c | ||
549 | |||
550 | # Having multiple identical manifests in each sysroot eats diskspace so | ||
551 | # create a shared pool of them and hardlink if we can. | ||
552 | # We create the manifest in advance so that if something fails during installation, | ||
553 | # or the build is interrupted, subsequent exeuction can cleanup. | ||
554 | sharedm = sharedmanifests + "/" + os.path.basename(taskmanifest) | ||
555 | if not os.path.exists(sharedm): | ||
556 | smlock = bb.utils.lockfile(sharedm + ".lock") | ||
557 | # Can race here. You'd think it just means we may not end up with all copies hardlinked to each other | ||
558 | # but python can lose file handles so we need to do this under a lock. | ||
559 | if not os.path.exists(sharedm): | ||
560 | with open(sharedm, 'w') as m: | ||
561 | for l in newmanifest: | ||
562 | dest = newmanifest[l] | ||
563 | m.write(dest.replace(workdir + "/", "") + "\n") | ||
564 | bb.utils.unlockfile(smlock) | ||
565 | try: | ||
566 | os.link(sharedm, taskmanifest) | ||
567 | except OSError as err: | ||
568 | if err.errno == errno.EXDEV: | ||
569 | bb.utils.copyfile(sharedm, taskmanifest) | ||
570 | else: | ||
571 | raise | ||
572 | # Finally actually install the files | ||
573 | for l in newmanifest: | ||
574 | dest = newmanifest[l] | ||
575 | if l.endswith("/"): | ||
576 | staging_copydir(l, targetdir, dest, seendirs) | ||
577 | continue | ||
578 | if "/bin/" in l or "/sbin/" in l: | ||
579 | # defer /*bin/* files until last in case they need libs | ||
580 | binfiles[l] = (targetdir, dest) | ||
581 | else: | ||
582 | staging_copyfile(l, targetdir, dest, postinsts, seendirs) | ||
583 | |||
584 | # Handle deferred binfiles | ||
585 | for l in binfiles: | ||
586 | (targetdir, dest) = binfiles[l] | ||
587 | staging_copyfile(l, targetdir, dest, postinsts, seendirs) | ||
588 | |||
589 | bb.note("Installed into sysroot: %s" % str(msg_adding)) | ||
590 | bb.note("Skipping as already exists in sysroot: %s" % str(msg_exists)) | ||
591 | |||
592 | for f in fixme: | ||
593 | staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d) | ||
594 | |||
595 | for p in postinsts: | ||
596 | subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT) | ||
597 | |||
598 | for dep in manifests: | ||
599 | c = setscenedeps[dep][0] | ||
600 | os.symlink(manifests[dep], depdir + "/" + c + ".complete") | ||
601 | |||
602 | with open(taskindex, "w") as f: | ||
603 | f.write("TaskDeps: " + " ".join(owntaskdeps) + "\n") | ||
604 | for l in sorted(installed): | ||
605 | f.write(l + "\n") | ||
606 | |||
607 | bb.utils.unlockfile(lock) | ||
608 | } | ||
609 | extend_recipe_sysroot[vardepsexclude] += "MACHINE_ARCH PACKAGE_EXTRA_ARCHS SDK_ARCH BUILD_ARCH SDK_OS BB_TASKDEPDATA" | ||
610 | |||
611 | do_prepare_recipe_sysroot[deptask] = "do_populate_sysroot" | ||
612 | python do_prepare_recipe_sysroot () { | ||
613 | bb.build.exec_func("extend_recipe_sysroot", d) | ||
614 | } | ||
615 | addtask do_prepare_recipe_sysroot before do_configure after do_fetch | ||
616 | |||
617 | python staging_taskhandler() { | ||
618 | bbtasks = e.tasklist | ||
619 | for task in bbtasks: | ||
620 | deps = d.getVarFlag(task, "depends") | ||
621 | if task == "do_configure" or (deps and "populate_sysroot" in deps): | ||
622 | d.appendVarFlag(task, "prefuncs", " extend_recipe_sysroot") | ||
623 | } | ||
624 | staging_taskhandler[eventmask] = "bb.event.RecipeTaskPreProcess" | ||
625 | addhandler staging_taskhandler | ||