blob: 939042eb4423a7c1ebc60934ee943164f66c3dd8 [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)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400174 subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500175
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:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400231 subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500232
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 = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500386 seendirs = set()
387 postinsts = []
388 multilibs = {}
389 manifests = {}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500390 # All files that we're going to be installing, to find conflicts.
391 fileset = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500392
393 for f in os.listdir(depdir):
394 if not f.endswith(".complete"):
395 continue
396 f = depdir + "/" + f
397 if os.path.islink(f) and not os.path.exists(f):
398 bb.note("%s no longer exists, removing from sysroot" % f)
399 lnk = os.readlink(f.replace(".complete", ""))
400 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
401 os.unlink(f)
402 os.unlink(f.replace(".complete", ""))
403
404 installed = []
405 for dep in configuredeps:
406 c = setscenedeps[dep][0]
407 if mytaskname in ["do_sdk_depends", "do_populate_sdk_ext"] and c.endswith("-initial"):
408 bb.note("Skipping initial setscene dependency %s for installation into the sysroot" % c)
409 continue
410 installed.append(c)
411
412 # We want to remove anything which this task previously installed but is no longer a dependency
413 taskindex = depdir + "/" + "index." + mytaskname
414 if os.path.exists(taskindex):
415 potential = []
416 with open(taskindex, "r") as f:
417 for l in f:
418 l = l.strip()
419 if l not in installed:
420 fl = depdir + "/" + l
421 if not os.path.exists(fl):
422 # Was likely already uninstalled
423 continue
424 potential.append(l)
425 # We need to ensure not other task needs this dependency. We hold the sysroot
426 # lock so we ca search the indexes to check
427 if potential:
428 for i in glob.glob(depdir + "/index.*"):
429 if i.endswith("." + mytaskname):
430 continue
431 with open(i, "r") as f:
432 for l in f:
433 l = l.strip()
434 if l in potential:
435 potential.remove(l)
436 for l in potential:
437 fl = depdir + "/" + l
438 bb.note("Task %s no longer depends on %s, removing from sysroot" % (mytaskname, l))
439 lnk = os.readlink(fl)
440 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
441 os.unlink(fl)
442 os.unlink(fl + ".complete")
443
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500444 msg_exists = []
445 msg_adding = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500446 for dep in configuredeps:
447 c = setscenedeps[dep][0]
448 if c not in installed:
449 continue
450 taskhash = setscenedeps[dep][5]
451 taskmanifest = depdir + "/" + c + "." + taskhash
452
453 if os.path.exists(depdir + "/" + c):
454 lnk = os.readlink(depdir + "/" + c)
455 if lnk == c + "." + taskhash and os.path.exists(depdir + "/" + c + ".complete"):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500456 msg_exists.append(c)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500457 continue
458 else:
459 bb.note("%s exists in sysroot, but is stale (%s vs. %s), removing." % (c, lnk, c + "." + taskhash))
460 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
461 os.unlink(depdir + "/" + c)
462 if os.path.lexists(depdir + "/" + c + ".complete"):
463 os.unlink(depdir + "/" + c + ".complete")
464 elif os.path.lexists(depdir + "/" + c):
465 os.unlink(depdir + "/" + c)
466
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500467 msg_adding.append(c)
468
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500469 os.symlink(c + "." + taskhash, depdir + "/" + c)
470
Brad Bishop316dfdd2018-06-25 12:45:53 -0400471 manifest, d2 = oe.sstatesig.find_sstate_manifest(c, setscenedeps[dep][2], "populate_sysroot", d, multilibs)
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700472 if d2 is not d:
473 # If we don't do this, the recipe sysroot will be placed in the wrong WORKDIR for multilibs
474 # We need a consistent WORKDIR for the image
475 d2.setVar("WORKDIR", d.getVar("WORKDIR"))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400476 destsysroot = d2.getVar("RECIPE_SYSROOT")
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700477 # We put allarch recipes into the default sysroot
478 if manifest and "allarch" in manifest:
479 destsysroot = d.getVar("RECIPE_SYSROOT")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500480
481 native = False
Brad Bishop316dfdd2018-06-25 12:45:53 -0400482 if c.endswith("-native") or "-cross-" in c or "-crosssdk" in c:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500483 native = True
Brad Bishop316dfdd2018-06-25 12:45:53 -0400484
485 if manifest:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500486 newmanifest = collections.OrderedDict()
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700487 targetdir = destsysroot
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500488 if native:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500489 targetdir = recipesysrootnative
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700490 if targetdir not in fixme:
491 fixme[targetdir] = []
492 fm = fixme[targetdir]
493
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500494 with open(manifest, "r") as f:
495 manifests[dep] = manifest
496 for l in f:
497 l = l.strip()
498 if l.endswith("/fixmepath"):
499 fm.append(l)
500 continue
501 if l.endswith("/fixmepath.cmd"):
502 continue
503 dest = l.replace(stagingdir, "")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500504 dest = "/" + "/".join(dest.split("/")[3:])
505 newmanifest[l] = targetdir + dest
506
507 # Check if files have already been installed by another
508 # recipe and abort if they have, explaining what recipes are
509 # conflicting.
510 hashname = targetdir + dest
511 if not hashname.endswith("/"):
512 if hashname in fileset:
513 bb.fatal("The file %s is installed by both %s and %s, aborting" % (dest, c, fileset[hashname]))
514 else:
515 fileset[hashname] = c
516
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500517 # Having multiple identical manifests in each sysroot eats diskspace so
518 # create a shared pool of them and hardlink if we can.
519 # We create the manifest in advance so that if something fails during installation,
520 # or the build is interrupted, subsequent exeuction can cleanup.
521 sharedm = sharedmanifests + "/" + os.path.basename(taskmanifest)
522 if not os.path.exists(sharedm):
523 smlock = bb.utils.lockfile(sharedm + ".lock")
524 # Can race here. You'd think it just means we may not end up with all copies hardlinked to each other
525 # but python can lose file handles so we need to do this under a lock.
526 if not os.path.exists(sharedm):
527 with open(sharedm, 'w') as m:
528 for l in newmanifest:
529 dest = newmanifest[l]
530 m.write(dest.replace(workdir + "/", "") + "\n")
531 bb.utils.unlockfile(smlock)
532 try:
533 os.link(sharedm, taskmanifest)
534 except OSError as err:
535 if err.errno == errno.EXDEV:
536 bb.utils.copyfile(sharedm, taskmanifest)
537 else:
538 raise
539 # Finally actually install the files
540 for l in newmanifest:
541 dest = newmanifest[l]
542 if l.endswith("/"):
543 staging_copydir(l, targetdir, dest, seendirs)
544 continue
545 staging_copyfile(l, targetdir, dest, postinsts, seendirs)
546
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500547 bb.note("Installed into sysroot: %s" % str(msg_adding))
548 bb.note("Skipping as already exists in sysroot: %s" % str(msg_exists))
549
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500550 for f in fixme:
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700551 staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500552
553 for p in postinsts:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400554 subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500555
556 for dep in manifests:
557 c = setscenedeps[dep][0]
558 os.symlink(manifests[dep], depdir + "/" + c + ".complete")
559
560 with open(taskindex, "w") as f:
561 for l in sorted(installed):
562 f.write(l + "\n")
563
564 bb.utils.unlockfile(lock)
565}
566extend_recipe_sysroot[vardepsexclude] += "MACHINE_ARCH PACKAGE_EXTRA_ARCHS SDK_ARCH BUILD_ARCH SDK_OS BB_TASKDEPDATA"
567
568python do_prepare_recipe_sysroot () {
569 bb.build.exec_func("extend_recipe_sysroot", d)
570}
571addtask do_prepare_recipe_sysroot before do_configure after do_fetch
572
573# Clean out the recipe specific sysroots before do_fetch
574# (use a prefunc so we can order before extend_recipe_sysroot if it gets added)
575python clean_recipe_sysroot() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500576 # We remove these stamps since we're removing any content they'd have added with
577 # cleandirs. This removes the sigdata too, likely not a big deal,
578 oe.path.remove(d.getVar("STAMP") + "*addto_recipe_sysroot*")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500579 return
580}
581clean_recipe_sysroot[cleandirs] += "${RECIPE_SYSROOT} ${RECIPE_SYSROOT_NATIVE}"
582do_fetch[prefuncs] += "clean_recipe_sysroot"
583
584python staging_taskhandler() {
585 bbtasks = e.tasklist
586 for task in bbtasks:
587 deps = d.getVarFlag(task, "depends")
588 if deps and "populate_sysroot" in deps:
589 d.appendVarFlag(task, "prefuncs", " extend_recipe_sysroot")
590}
591staging_taskhandler[eventmask] = "bb.event.RecipeTaskPreProcess"
592addhandler staging_taskhandler