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