blob: 920706022283e3e35e4a0b3391b367e34b8dc9e5 [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 \
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035 ${libdir}/${PN}/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')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050078 libdir = os.path.abspath(dstdir + os.sep + d.getVar("libdir"))
79 base_libdir = os.path.abspath(dstdir + os.sep + d.getVar("base_libdir"))
80 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"):
200 # skip glibc-initial and libgcc-initial due to file overlap
201 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 Bishop1a4b7ee2018-12-16 17:11:34 -0800264 mc = d.getVar("BB_CURRENT_MC")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500265 stagingdir = d.getVar("STAGING_DIR")
266 sharedmanifests = d.getVar("COMPONENTS_DIR") + "/manifests"
267 recipesysroot = d.getVar("RECIPE_SYSROOT")
268 recipesysrootnative = d.getVar("RECIPE_SYSROOT_NATIVE")
269 current_variant = d.getVar("BBEXTENDVARIANT")
270
271 # Detect bitbake -b usage
272 nodeps = d.getVar("BB_LIMITEDDEPS") or False
273 if nodeps:
274 lock = bb.utils.lockfile(recipesysroot + "/sysroot.lock")
275 staging_populate_sysroot_dir(recipesysroot, recipesysrootnative, True, d)
276 staging_populate_sysroot_dir(recipesysroot, recipesysrootnative, False, d)
277 bb.utils.unlockfile(lock)
278 return
279
280 start = None
281 configuredeps = []
282 for dep in taskdepdata:
283 data = taskdepdata[dep]
284 if data[1] == mytaskname and data[0] == pn:
285 start = dep
286 break
287 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)
432 # We need to ensure not other task needs this dependency. We hold the sysroot
433 # 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:
440 l = l.strip()
441 if l in potential:
442 potential.remove(l)
443 for l in potential:
444 fl = depdir + "/" + l
445 bb.note("Task %s no longer depends on %s, removing from sysroot" % (mytaskname, l))
446 lnk = os.readlink(fl)
447 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
448 os.unlink(fl)
449 os.unlink(fl + ".complete")
450
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500451 msg_exists = []
452 msg_adding = []
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800453
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500454 for dep in configuredeps:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800455 if mc != 'default':
456 # We should not care about other multiconfigs
457 depmc = dep.split(':')[1]
458 if depmc != mc:
459 continue
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500460 c = setscenedeps[dep][0]
461 if c not in installed:
462 continue
463 taskhash = setscenedeps[dep][5]
464 taskmanifest = depdir + "/" + c + "." + taskhash
465
466 if os.path.exists(depdir + "/" + c):
467 lnk = os.readlink(depdir + "/" + c)
468 if lnk == c + "." + taskhash and os.path.exists(depdir + "/" + c + ".complete"):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500469 msg_exists.append(c)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500470 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
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500480 msg_adding.append(c)
481
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500482 os.symlink(c + "." + taskhash, depdir + "/" + c)
483
Brad Bishop316dfdd2018-06-25 12:45:53 -0400484 manifest, d2 = oe.sstatesig.find_sstate_manifest(c, setscenedeps[dep][2], "populate_sysroot", d, multilibs)
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700485 if d2 is not d:
486 # If we don't do this, the recipe sysroot will be placed in the wrong WORKDIR for multilibs
487 # We need a consistent WORKDIR for the image
488 d2.setVar("WORKDIR", d.getVar("WORKDIR"))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400489 destsysroot = d2.getVar("RECIPE_SYSROOT")
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700490 # We put allarch recipes into the default sysroot
491 if manifest and "allarch" in manifest:
492 destsysroot = d.getVar("RECIPE_SYSROOT")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500493
494 native = False
Brad Bishop316dfdd2018-06-25 12:45:53 -0400495 if c.endswith("-native") or "-cross-" in c or "-crosssdk" in c:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500496 native = True
Brad Bishop316dfdd2018-06-25 12:45:53 -0400497
498 if manifest:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500499 newmanifest = collections.OrderedDict()
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700500 targetdir = destsysroot
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500501 if native:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500502 targetdir = recipesysrootnative
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700503 if targetdir not in fixme:
504 fixme[targetdir] = []
505 fm = fixme[targetdir]
506
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500507 with open(manifest, "r") as f:
508 manifests[dep] = manifest
509 for l in f:
510 l = l.strip()
511 if l.endswith("/fixmepath"):
512 fm.append(l)
513 continue
514 if l.endswith("/fixmepath.cmd"):
515 continue
516 dest = l.replace(stagingdir, "")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500517 dest = "/" + "/".join(dest.split("/")[3:])
518 newmanifest[l] = targetdir + dest
519
520 # Check if files have already been installed by another
521 # recipe and abort if they have, explaining what recipes are
522 # conflicting.
523 hashname = targetdir + dest
524 if not hashname.endswith("/"):
525 if hashname in fileset:
526 bb.fatal("The file %s is installed by both %s and %s, aborting" % (dest, c, fileset[hashname]))
527 else:
528 fileset[hashname] = c
529
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500530 # Having multiple identical manifests in each sysroot eats diskspace so
531 # create a shared pool of them and hardlink if we can.
532 # We create the manifest in advance so that if something fails during installation,
533 # or the build is interrupted, subsequent exeuction can cleanup.
534 sharedm = sharedmanifests + "/" + os.path.basename(taskmanifest)
535 if not os.path.exists(sharedm):
536 smlock = bb.utils.lockfile(sharedm + ".lock")
537 # Can race here. You'd think it just means we may not end up with all copies hardlinked to each other
538 # but python can lose file handles so we need to do this under a lock.
539 if not os.path.exists(sharedm):
540 with open(sharedm, 'w') as m:
541 for l in newmanifest:
542 dest = newmanifest[l]
543 m.write(dest.replace(workdir + "/", "") + "\n")
544 bb.utils.unlockfile(smlock)
545 try:
546 os.link(sharedm, taskmanifest)
547 except OSError as err:
548 if err.errno == errno.EXDEV:
549 bb.utils.copyfile(sharedm, taskmanifest)
550 else:
551 raise
552 # Finally actually install the files
553 for l in newmanifest:
554 dest = newmanifest[l]
555 if l.endswith("/"):
556 staging_copydir(l, targetdir, dest, seendirs)
557 continue
558 staging_copyfile(l, targetdir, dest, postinsts, seendirs)
559
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500560 bb.note("Installed into sysroot: %s" % str(msg_adding))
561 bb.note("Skipping as already exists in sysroot: %s" % str(msg_exists))
562
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500563 for f in fixme:
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700564 staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500565
566 for p in postinsts:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400567 subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500568
569 for dep in manifests:
570 c = setscenedeps[dep][0]
571 os.symlink(manifests[dep], depdir + "/" + c + ".complete")
572
573 with open(taskindex, "w") as f:
574 for l in sorted(installed):
575 f.write(l + "\n")
576
577 bb.utils.unlockfile(lock)
578}
579extend_recipe_sysroot[vardepsexclude] += "MACHINE_ARCH PACKAGE_EXTRA_ARCHS SDK_ARCH BUILD_ARCH SDK_OS BB_TASKDEPDATA"
580
Brad Bishop19323692019-04-05 15:28:33 -0400581do_prepare_recipe_sysroot[deptask] = "do_populate_sysroot"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500582python do_prepare_recipe_sysroot () {
583 bb.build.exec_func("extend_recipe_sysroot", d)
584}
585addtask do_prepare_recipe_sysroot before do_configure after do_fetch
586
587# Clean out the recipe specific sysroots before do_fetch
588# (use a prefunc so we can order before extend_recipe_sysroot if it gets added)
589python clean_recipe_sysroot() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500590 # We remove these stamps since we're removing any content they'd have added with
591 # cleandirs. This removes the sigdata too, likely not a big deal,
592 oe.path.remove(d.getVar("STAMP") + "*addto_recipe_sysroot*")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500593 return
594}
595clean_recipe_sysroot[cleandirs] += "${RECIPE_SYSROOT} ${RECIPE_SYSROOT_NATIVE}"
596do_fetch[prefuncs] += "clean_recipe_sysroot"
597
598python staging_taskhandler() {
599 bbtasks = e.tasklist
600 for task in bbtasks:
601 deps = d.getVarFlag(task, "depends")
602 if deps and "populate_sysroot" in deps:
603 d.appendVarFlag(task, "prefuncs", " extend_recipe_sysroot")
604}
605staging_taskhandler[eventmask] = "bb.event.RecipeTaskPreProcess"
606addhandler staging_taskhandler