blob: 5b04f88b2d8419eaf2cf59514dd51c228c1acb05 [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} \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060030 ${datadir}/applications \
31 ${datadir}/fonts \
Brad Bishopc342db32019-05-15 21:57:59 -040032 ${datadir}/gtk-doc/html \
33 ${datadir}/locale \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060034 ${datadir}/pixmaps \
Andrew Geissler82c905d2020-04-13 13:39:40 -050035 ${libdir}/${BPN}/ptest \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060036"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
38sysroot_stage_dir() {
39 src="$1"
40 dest="$2"
41 # if the src doesn't exist don't do anything
42 if [ ! -d "$src" ]; then
43 return
44 fi
45
46 mkdir -p "$dest"
47 (
48 cd $src
49 find . -print0 | cpio --null -pdlu $dest
50 )
51}
52
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053sysroot_stage_dirs() {
54 from="$1"
55 to="$2"
56
Patrick Williamsc0f7c042017-02-23 20:41:17 -060057 for dir in ${SYSROOT_DIRS}; do
58 sysroot_stage_dir "$from$dir" "$to$dir"
59 done
60
61 # Remove directories we do not care about
62 for dir in ${SYSROOT_DIRS_BLACKLIST}; do
63 rm -rf "$to$dir"
64 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065}
66
67sysroot_stage_all() {
68 sysroot_stage_dirs ${D} ${SYSROOT_DESTDIR}
69}
70
71python sysroot_strip () {
Brad Bishopd7bf8c12018-02-25 22:55:05 -050072 inhibit_sysroot = d.getVar('INHIBIT_SYSROOT_STRIP')
73 if inhibit_sysroot and oe.types.boolean(inhibit_sysroot):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080074 return
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075
Brad Bishopd7bf8c12018-02-25 22:55:05 -050076 dstdir = d.getVar('SYSROOT_DESTDIR')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050077 pn = d.getVar('PN')
Andrew Geissler82c905d2020-04-13 13:39:40 -050078 libdir = d.getVar("libdir")
79 base_libdir = d.getVar("base_libdir")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050080 qa_already_stripped = 'already-stripped' in (d.getVar('INSANE_SKIP_' + pn) or "").split()
81 strip_cmd = d.getVar("STRIP")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080083 oe.package.strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, d,
Brad Bishopd7bf8c12018-02-25 22:55:05 -050084 qa_already_stripped=qa_already_stripped)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085}
86
87do_populate_sysroot[dirs] = "${SYSROOT_DESTDIR}"
88do_populate_sysroot[umask] = "022"
89
90addtask populate_sysroot after do_install
91
92SYSROOT_PREPROCESS_FUNCS ?= ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050093SYSROOT_DESTDIR = "${WORKDIR}/sysroot-destdir"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050094
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095python do_populate_sysroot () {
96 bb.build.exec_func("sysroot_stage_all", d)
97 bb.build.exec_func("sysroot_strip", d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 for f in (d.getVar('SYSROOT_PREPROCESS_FUNCS') or '').split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -050099 bb.build.exec_func(f, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500100 pn = d.getVar("PN")
101 multiprov = d.getVar("MULTI_PROVIDER_WHITELIST").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102 provdir = d.expand("${SYSROOT_DESTDIR}${base_prefix}/sysroot-providers/")
103 bb.utils.mkdirhier(provdir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500104 for p in d.getVar("PROVIDES").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105 if p in multiprov:
106 continue
107 p = p.replace("/", "_")
108 with open(provdir + p, "w") as f:
109 f.write(pn)
110}
111
112do_populate_sysroot[vardeps] += "${SYSROOT_PREPROCESS_FUNCS}"
113do_populate_sysroot[vardepsexclude] += "MULTI_PROVIDER_WHITELIST"
114
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500115POPULATESYSROOTDEPS = ""
116POPULATESYSROOTDEPS_class-target = "virtual/${MLPREFIX}${TARGET_PREFIX}binutils:do_populate_sysroot"
117POPULATESYSROOTDEPS_class-nativesdk = "virtual/${TARGET_PREFIX}binutils-crosssdk:do_populate_sysroot"
118do_populate_sysroot[depends] += "${POPULATESYSROOTDEPS}"
119
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120SSTATETASKS += "do_populate_sysroot"
121do_populate_sysroot[cleandirs] = "${SYSROOT_DESTDIR}"
122do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500123do_populate_sysroot[sstate-outputdirs] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}"
124do_populate_sysroot[sstate-fixmedir] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125
126python do_populate_sysroot_setscene () {
127 sstate_setscene(d)
128}
129addtask do_populate_sysroot_setscene
130
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500131def staging_copyfile(c, target, dest, postinsts, seendirs):
132 import errno
133
134 destdir = os.path.dirname(dest)
135 if destdir not in seendirs:
136 bb.utils.mkdirhier(destdir)
137 seendirs.add(destdir)
138 if "/usr/bin/postinst-" in c:
139 postinsts.append(dest)
140 if os.path.islink(c):
141 linkto = os.readlink(c)
142 if os.path.lexists(dest):
143 if not os.path.islink(dest):
144 raise OSError(errno.EEXIST, "Link %s already exists as a file" % dest, dest)
145 if os.readlink(dest) == linkto:
146 return dest
147 raise OSError(errno.EEXIST, "Link %s already exists to a different location? (%s vs %s)" % (dest, os.readlink(dest), linkto), dest)
148 os.symlink(linkto, dest)
149 #bb.warn(c)
150 else:
151 try:
152 os.link(c, dest)
153 except OSError as err:
154 if err.errno == errno.EXDEV:
155 bb.utils.copyfile(c, dest)
156 else:
157 raise
158 return dest
159
160def staging_copydir(c, target, dest, seendirs):
161 if dest not in seendirs:
162 bb.utils.mkdirhier(dest)
163 seendirs.add(dest)
164
165def staging_processfixme(fixme, target, recipesysroot, recipesysrootnative, d):
166 import subprocess
167
168 if not fixme:
169 return
170 cmd = "sed -e 's:^[^/]*/:%s/:g' %s | xargs sed -i -e 's:FIXMESTAGINGDIRTARGET:%s:g; s:FIXMESTAGINGDIRHOST:%s:g'" % (target, " ".join(fixme), recipesysroot, recipesysrootnative)
Brad Bishop15ae2502019-06-18 21:44:24 -0400171 for fixmevar in ['PSEUDO_SYSROOT', 'HOSTTOOLS_DIR', 'PKGDATA_DIR', 'PSEUDO_LOCALSTATEDIR', 'LOGFIFO']:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500172 fixme_path = d.getVar(fixmevar)
173 cmd += " -e 's:FIXME_%s:%s:g'" % (fixmevar, fixme_path)
174 bb.debug(2, cmd)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400175 subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500176
177
178def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d):
179 import glob
180 import subprocess
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500181 import errno
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500182
183 fixme = []
184 postinsts = []
185 seendirs = set()
186 stagingdir = d.getVar("STAGING_DIR")
187 if native:
188 pkgarchs = ['${BUILD_ARCH}', '${BUILD_ARCH}_*']
189 targetdir = nativesysroot
190 else:
191 pkgarchs = ['${MACHINE_ARCH}']
192 pkgarchs = pkgarchs + list(reversed(d.getVar("PACKAGE_EXTRA_ARCHS").split()))
193 pkgarchs.append('allarch')
194 targetdir = targetsysroot
195
196 bb.utils.mkdirhier(targetdir)
197 for pkgarch in pkgarchs:
198 for manifest in glob.glob(d.expand("${SSTATE_MANIFESTS}/manifest-%s-*.populate_sysroot" % pkgarch)):
199 if manifest.endswith("-initial.populate_sysroot"):
Brad Bishop79641f22019-09-10 07:20:22 -0400200 # skip libgcc-initial due to file overlap
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500201 continue
Brad Bishop19323692019-04-05 15:28:33 -0400202 if not native and (manifest.endswith("-native.populate_sysroot") or "nativesdk-" in manifest):
203 continue
204 if native and not (manifest.endswith("-native.populate_sysroot") or manifest.endswith("-cross.populate_sysroot") or "-cross-" in manifest):
205 continue
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500206 tmanifest = targetdir + "/" + os.path.basename(manifest)
207 if os.path.exists(tmanifest):
208 continue
209 try:
210 os.link(manifest, tmanifest)
211 except OSError as err:
212 if err.errno == errno.EXDEV:
213 bb.utils.copyfile(manifest, tmanifest)
214 else:
215 raise
216 with open(manifest, "r") as f:
217 for l in f:
218 l = l.strip()
219 if l.endswith("/fixmepath"):
220 fixme.append(l)
221 continue
222 if l.endswith("/fixmepath.cmd"):
223 continue
224 dest = l.replace(stagingdir, "")
225 dest = targetdir + "/" + "/".join(dest.split("/")[3:])
226 if l.endswith("/"):
227 staging_copydir(l, targetdir, dest, seendirs)
228 continue
229 try:
230 staging_copyfile(l, targetdir, dest, postinsts, seendirs)
231 except FileExistsError:
232 continue
233
234 staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot, d)
235 for p in postinsts:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400236 subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500237
238#
239# Manifests here are complicated. The main sysroot area has the unpacked sstate
240# which us unrelocated and tracked by the main sstate manifests. Each recipe
241# specific sysroot has manifests for each dependency that is installed there.
242# The task hash is used to tell whether the data needs to be reinstalled. We
243# use a symlink to point to the currently installed hash. There is also a
244# "complete" stamp file which is used to mark if installation completed. If
245# something fails (e.g. a postinst), this won't get written and we would
246# remove and reinstall the dependency. This also means partially installed
247# dependencies should get cleaned up correctly.
248#
249
250python extend_recipe_sysroot() {
251 import copy
252 import subprocess
253 import errno
254 import collections
255 import glob
256
257 taskdepdata = d.getVar("BB_TASKDEPDATA", False)
258 mytaskname = d.getVar("BB_RUNTASK")
259 if mytaskname.endswith("_setscene"):
260 mytaskname = mytaskname.replace("_setscene", "")
261 workdir = d.getVar("WORKDIR")
262 #bb.warn(str(taskdepdata))
263 pn = d.getVar("PN")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500264 stagingdir = d.getVar("STAGING_DIR")
265 sharedmanifests = d.getVar("COMPONENTS_DIR") + "/manifests"
266 recipesysroot = d.getVar("RECIPE_SYSROOT")
267 recipesysrootnative = d.getVar("RECIPE_SYSROOT_NATIVE")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500268
269 # Detect bitbake -b usage
270 nodeps = d.getVar("BB_LIMITEDDEPS") or False
271 if nodeps:
272 lock = bb.utils.lockfile(recipesysroot + "/sysroot.lock")
273 staging_populate_sysroot_dir(recipesysroot, recipesysrootnative, True, d)
274 staging_populate_sysroot_dir(recipesysroot, recipesysrootnative, False, d)
275 bb.utils.unlockfile(lock)
276 return
277
278 start = None
279 configuredeps = []
Andrew Geissler82c905d2020-04-13 13:39:40 -0500280 owntaskdeps = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500281 for dep in taskdepdata:
282 data = taskdepdata[dep]
283 if data[1] == mytaskname and data[0] == pn:
284 start = dep
Andrew Geissler82c905d2020-04-13 13:39:40 -0500285 elif data[0] == pn:
286 owntaskdeps.append(data[1])
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500287 if start is None:
288 bb.fatal("Couldn't find ourself in BB_TASKDEPDATA?")
289
290 # We need to figure out which sysroot files we need to expose to this task.
291 # This needs to match what would get restored from sstate, which is controlled
292 # ultimately by calls from bitbake to setscene_depvalid().
293 # That function expects a setscene dependency tree. We build a dependency tree
294 # condensed to inter-sstate task dependencies, similar to that used by setscene
295 # tasks. We can then call into setscene_depvalid() and decide
296 # which dependencies we can "see" and should expose in the recipe specific sysroot.
297 setscenedeps = copy.deepcopy(taskdepdata)
298
299 start = set([start])
300
301 sstatetasks = d.getVar("SSTATETASKS").split()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800302 # Add recipe specific tasks referenced by setscene_depvalid()
303 sstatetasks.append("do_stash_locale")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500304
305 def print_dep_tree(deptree):
306 data = ""
307 for dep in deptree:
308 deps = " " + "\n ".join(deptree[dep][3]) + "\n"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800309 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])
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500310 return data
311
312 #bb.note("Full dep tree is:\n%s" % print_dep_tree(taskdepdata))
313
314 #bb.note(" start2 is %s" % str(start))
315
316 # If start is an sstate task (like do_package) we need to add in its direct dependencies
317 # else the code below won't recurse into them.
318 for dep in set(start):
319 for dep2 in setscenedeps[dep][3]:
320 start.add(dep2)
321 start.remove(dep)
322
323 #bb.note(" start3 is %s" % str(start))
324
325 # Create collapsed do_populate_sysroot -> do_populate_sysroot tree
326 for dep in taskdepdata:
327 data = setscenedeps[dep]
328 if data[1] not in sstatetasks:
329 for dep2 in setscenedeps:
330 data2 = setscenedeps[dep2]
331 if dep in data2[3]:
332 data2[3].update(setscenedeps[dep][3])
333 data2[3].remove(dep)
334 if dep in start:
335 start.update(setscenedeps[dep][3])
336 start.remove(dep)
337 del setscenedeps[dep]
338
339 # Remove circular references
340 for dep in setscenedeps:
341 if dep in setscenedeps[dep][3]:
342 setscenedeps[dep][3].remove(dep)
343
344 #bb.note("Computed dep tree is:\n%s" % print_dep_tree(setscenedeps))
345 #bb.note(" start is %s" % str(start))
346
347 # Direct dependencies should be present and can be depended upon
348 for dep in set(start):
349 if setscenedeps[dep][1] == "do_populate_sysroot":
350 if dep not in configuredeps:
351 configuredeps.append(dep)
352 bb.note("Direct dependencies are %s" % str(configuredeps))
353 #bb.note(" or %s" % str(start))
354
355 msgbuf = []
356 # Call into setscene_depvalid for each sub-dependency and only copy sysroot files
357 # for ones that would be restored from sstate.
358 done = list(start)
359 next = list(start)
360 while next:
361 new = []
362 for dep in next:
363 data = setscenedeps[dep]
364 for datadep in data[3]:
365 if datadep in done:
366 continue
367 taskdeps = {}
368 taskdeps[dep] = setscenedeps[dep][:2]
369 taskdeps[datadep] = setscenedeps[datadep][:2]
370 retval = setscene_depvalid(datadep, taskdeps, [], d, msgbuf)
371 if retval:
372 msgbuf.append("Skipping setscene dependency %s for installation into the sysroot" % datadep)
373 continue
374 done.append(datadep)
375 new.append(datadep)
376 if datadep not in configuredeps and setscenedeps[datadep][1] == "do_populate_sysroot":
377 configuredeps.append(datadep)
378 msgbuf.append("Adding dependency on %s" % setscenedeps[datadep][0])
379 else:
380 msgbuf.append("Following dependency on %s" % setscenedeps[datadep][0])
381 next = new
382
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500383 # This logging is too verbose for day to day use sadly
384 #bb.debug(2, "\n".join(msgbuf))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500385
386 depdir = recipesysrootnative + "/installeddeps"
387 bb.utils.mkdirhier(depdir)
388 bb.utils.mkdirhier(sharedmanifests)
389
390 lock = bb.utils.lockfile(recipesysroot + "/sysroot.lock")
391
392 fixme = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500393 seendirs = set()
394 postinsts = []
395 multilibs = {}
396 manifests = {}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500397 # All files that we're going to be installing, to find conflicts.
398 fileset = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500399
400 for f in os.listdir(depdir):
401 if not f.endswith(".complete"):
402 continue
403 f = depdir + "/" + f
404 if os.path.islink(f) and not os.path.exists(f):
405 bb.note("%s no longer exists, removing from sysroot" % f)
406 lnk = os.readlink(f.replace(".complete", ""))
407 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
408 os.unlink(f)
409 os.unlink(f.replace(".complete", ""))
410
411 installed = []
412 for dep in configuredeps:
413 c = setscenedeps[dep][0]
414 if mytaskname in ["do_sdk_depends", "do_populate_sdk_ext"] and c.endswith("-initial"):
415 bb.note("Skipping initial setscene dependency %s for installation into the sysroot" % c)
416 continue
417 installed.append(c)
418
419 # We want to remove anything which this task previously installed but is no longer a dependency
420 taskindex = depdir + "/" + "index." + mytaskname
421 if os.path.exists(taskindex):
422 potential = []
423 with open(taskindex, "r") as f:
424 for l in f:
425 l = l.strip()
426 if l not in installed:
427 fl = depdir + "/" + l
428 if not os.path.exists(fl):
429 # Was likely already uninstalled
430 continue
431 potential.append(l)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500432 # We need to ensure no other task needs this dependency. We hold the sysroot
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500433 # lock so we ca search the indexes to check
434 if potential:
435 for i in glob.glob(depdir + "/index.*"):
436 if i.endswith("." + mytaskname):
437 continue
438 with open(i, "r") as f:
439 for l in f:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500440 if l.startswith("TaskDeps:"):
441 prevtasks = l.split()[1:]
442 if mytaskname in prevtasks:
443 # We're a dependency of this task so we can clear items out the sysroot
444 break
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500445 l = l.strip()
446 if l in potential:
447 potential.remove(l)
448 for l in potential:
449 fl = depdir + "/" + l
450 bb.note("Task %s no longer depends on %s, removing from sysroot" % (mytaskname, l))
451 lnk = os.readlink(fl)
452 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
453 os.unlink(fl)
454 os.unlink(fl + ".complete")
455
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500456 msg_exists = []
457 msg_adding = []
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800458
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500459 # Handle all removals first since files may move between recipes
460 for dep in configuredeps:
461 c = setscenedeps[dep][0]
462 if c not in installed:
463 continue
464 taskhash = setscenedeps[dep][5]
465 taskmanifest = depdir + "/" + c + "." + taskhash
466
467 if os.path.exists(depdir + "/" + c):
468 lnk = os.readlink(depdir + "/" + c)
469 if lnk == c + "." + taskhash and os.path.exists(depdir + "/" + c + ".complete"):
470 continue
471 else:
472 bb.note("%s exists in sysroot, but is stale (%s vs. %s), removing." % (c, lnk, c + "." + taskhash))
473 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
474 os.unlink(depdir + "/" + c)
475 if os.path.lexists(depdir + "/" + c + ".complete"):
476 os.unlink(depdir + "/" + c + ".complete")
477 elif os.path.lexists(depdir + "/" + c):
478 os.unlink(depdir + "/" + c)
479
Andrew Geissler82c905d2020-04-13 13:39:40 -0500480 binfiles = {}
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500481 # Now handle installs
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500482 for dep in configuredeps:
483 c = setscenedeps[dep][0]
484 if c not in installed:
485 continue
486 taskhash = setscenedeps[dep][5]
487 taskmanifest = depdir + "/" + c + "." + taskhash
488
489 if os.path.exists(depdir + "/" + c):
490 lnk = os.readlink(depdir + "/" + c)
491 if lnk == c + "." + taskhash and os.path.exists(depdir + "/" + c + ".complete"):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500492 msg_exists.append(c)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500493 continue
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500494
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500495 msg_adding.append(c)
496
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500497 os.symlink(c + "." + taskhash, depdir + "/" + c)
498
Brad Bishop316dfdd2018-06-25 12:45:53 -0400499 manifest, d2 = oe.sstatesig.find_sstate_manifest(c, setscenedeps[dep][2], "populate_sysroot", d, multilibs)
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700500 if d2 is not d:
501 # If we don't do this, the recipe sysroot will be placed in the wrong WORKDIR for multilibs
502 # We need a consistent WORKDIR for the image
503 d2.setVar("WORKDIR", d.getVar("WORKDIR"))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400504 destsysroot = d2.getVar("RECIPE_SYSROOT")
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700505 # We put allarch recipes into the default sysroot
506 if manifest and "allarch" in manifest:
507 destsysroot = d.getVar("RECIPE_SYSROOT")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500508
509 native = False
Brad Bishop316dfdd2018-06-25 12:45:53 -0400510 if c.endswith("-native") or "-cross-" in c or "-crosssdk" in c:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500511 native = True
Brad Bishop316dfdd2018-06-25 12:45:53 -0400512
513 if manifest:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500514 newmanifest = collections.OrderedDict()
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700515 targetdir = destsysroot
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500516 if native:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500517 targetdir = recipesysrootnative
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700518 if targetdir not in fixme:
519 fixme[targetdir] = []
520 fm = fixme[targetdir]
521
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500522 with open(manifest, "r") as f:
523 manifests[dep] = manifest
524 for l in f:
525 l = l.strip()
526 if l.endswith("/fixmepath"):
527 fm.append(l)
528 continue
529 if l.endswith("/fixmepath.cmd"):
530 continue
531 dest = l.replace(stagingdir, "")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500532 dest = "/" + "/".join(dest.split("/")[3:])
533 newmanifest[l] = targetdir + dest
534
535 # Check if files have already been installed by another
536 # recipe and abort if they have, explaining what recipes are
537 # conflicting.
538 hashname = targetdir + dest
539 if not hashname.endswith("/"):
540 if hashname in fileset:
541 bb.fatal("The file %s is installed by both %s and %s, aborting" % (dest, c, fileset[hashname]))
542 else:
543 fileset[hashname] = c
544
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500545 # Having multiple identical manifests in each sysroot eats diskspace so
546 # create a shared pool of them and hardlink if we can.
547 # We create the manifest in advance so that if something fails during installation,
548 # or the build is interrupted, subsequent exeuction can cleanup.
549 sharedm = sharedmanifests + "/" + os.path.basename(taskmanifest)
550 if not os.path.exists(sharedm):
551 smlock = bb.utils.lockfile(sharedm + ".lock")
552 # Can race here. You'd think it just means we may not end up with all copies hardlinked to each other
553 # but python can lose file handles so we need to do this under a lock.
554 if not os.path.exists(sharedm):
555 with open(sharedm, 'w') as m:
556 for l in newmanifest:
557 dest = newmanifest[l]
558 m.write(dest.replace(workdir + "/", "") + "\n")
559 bb.utils.unlockfile(smlock)
560 try:
561 os.link(sharedm, taskmanifest)
562 except OSError as err:
563 if err.errno == errno.EXDEV:
564 bb.utils.copyfile(sharedm, taskmanifest)
565 else:
566 raise
567 # Finally actually install the files
568 for l in newmanifest:
569 dest = newmanifest[l]
570 if l.endswith("/"):
571 staging_copydir(l, targetdir, dest, seendirs)
572 continue
Andrew Geissler82c905d2020-04-13 13:39:40 -0500573 if "/bin/" in l or "/sbin/" in l:
574 # defer /*bin/* files until last in case they need libs
575 binfiles[l] = (targetdir, dest)
576 else:
577 staging_copyfile(l, targetdir, dest, postinsts, seendirs)
578
579 # Handle deferred binfiles
580 for l in binfiles:
581 (targetdir, dest) = binfiles[l]
582 staging_copyfile(l, targetdir, dest, postinsts, seendirs)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500583
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500584 bb.note("Installed into sysroot: %s" % str(msg_adding))
585 bb.note("Skipping as already exists in sysroot: %s" % str(msg_exists))
586
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500587 for f in fixme:
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700588 staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500589
590 for p in postinsts:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400591 subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500592
593 for dep in manifests:
594 c = setscenedeps[dep][0]
595 os.symlink(manifests[dep], depdir + "/" + c + ".complete")
596
597 with open(taskindex, "w") as f:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500598 f.write("TaskDeps: " + " ".join(owntaskdeps) + "\n")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500599 for l in sorted(installed):
600 f.write(l + "\n")
601
602 bb.utils.unlockfile(lock)
603}
604extend_recipe_sysroot[vardepsexclude] += "MACHINE_ARCH PACKAGE_EXTRA_ARCHS SDK_ARCH BUILD_ARCH SDK_OS BB_TASKDEPDATA"
605
Brad Bishop19323692019-04-05 15:28:33 -0400606do_prepare_recipe_sysroot[deptask] = "do_populate_sysroot"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500607python do_prepare_recipe_sysroot () {
608 bb.build.exec_func("extend_recipe_sysroot", d)
609}
610addtask do_prepare_recipe_sysroot before do_configure after do_fetch
611
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500612python staging_taskhandler() {
613 bbtasks = e.tasklist
614 for task in bbtasks:
615 deps = d.getVarFlag(task, "depends")
616 if deps and "populate_sysroot" in deps:
617 d.appendVarFlag(task, "prefuncs", " extend_recipe_sysroot")
618}
619staging_taskhandler[eventmask] = "bb.event.RecipeTaskPreProcess"
620addhandler staging_taskhandler