blob: cdc342dbb94a4ae26056c2be3e3830f263a10310 [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 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 = []
280 for dep in taskdepdata:
281 data = taskdepdata[dep]
282 if data[1] == mytaskname and data[0] == pn:
283 start = dep
284 break
285 if start is None:
286 bb.fatal("Couldn't find ourself in BB_TASKDEPDATA?")
287
288 # We need to figure out which sysroot files we need to expose to this task.
289 # This needs to match what would get restored from sstate, which is controlled
290 # ultimately by calls from bitbake to setscene_depvalid().
291 # That function expects a setscene dependency tree. We build a dependency tree
292 # condensed to inter-sstate task dependencies, similar to that used by setscene
293 # tasks. We can then call into setscene_depvalid() and decide
294 # which dependencies we can "see" and should expose in the recipe specific sysroot.
295 setscenedeps = copy.deepcopy(taskdepdata)
296
297 start = set([start])
298
299 sstatetasks = d.getVar("SSTATETASKS").split()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800300 # Add recipe specific tasks referenced by setscene_depvalid()
301 sstatetasks.append("do_stash_locale")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500302
303 def print_dep_tree(deptree):
304 data = ""
305 for dep in deptree:
306 deps = " " + "\n ".join(deptree[dep][3]) + "\n"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800307 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 -0500308 return data
309
310 #bb.note("Full dep tree is:\n%s" % print_dep_tree(taskdepdata))
311
312 #bb.note(" start2 is %s" % str(start))
313
314 # If start is an sstate task (like do_package) we need to add in its direct dependencies
315 # else the code below won't recurse into them.
316 for dep in set(start):
317 for dep2 in setscenedeps[dep][3]:
318 start.add(dep2)
319 start.remove(dep)
320
321 #bb.note(" start3 is %s" % str(start))
322
323 # Create collapsed do_populate_sysroot -> do_populate_sysroot tree
324 for dep in taskdepdata:
325 data = setscenedeps[dep]
326 if data[1] not in sstatetasks:
327 for dep2 in setscenedeps:
328 data2 = setscenedeps[dep2]
329 if dep in data2[3]:
330 data2[3].update(setscenedeps[dep][3])
331 data2[3].remove(dep)
332 if dep in start:
333 start.update(setscenedeps[dep][3])
334 start.remove(dep)
335 del setscenedeps[dep]
336
337 # Remove circular references
338 for dep in setscenedeps:
339 if dep in setscenedeps[dep][3]:
340 setscenedeps[dep][3].remove(dep)
341
342 #bb.note("Computed dep tree is:\n%s" % print_dep_tree(setscenedeps))
343 #bb.note(" start is %s" % str(start))
344
345 # Direct dependencies should be present and can be depended upon
346 for dep in set(start):
347 if setscenedeps[dep][1] == "do_populate_sysroot":
348 if dep not in configuredeps:
349 configuredeps.append(dep)
350 bb.note("Direct dependencies are %s" % str(configuredeps))
351 #bb.note(" or %s" % str(start))
352
353 msgbuf = []
354 # Call into setscene_depvalid for each sub-dependency and only copy sysroot files
355 # for ones that would be restored from sstate.
356 done = list(start)
357 next = list(start)
358 while next:
359 new = []
360 for dep in next:
361 data = setscenedeps[dep]
362 for datadep in data[3]:
363 if datadep in done:
364 continue
365 taskdeps = {}
366 taskdeps[dep] = setscenedeps[dep][:2]
367 taskdeps[datadep] = setscenedeps[datadep][:2]
368 retval = setscene_depvalid(datadep, taskdeps, [], d, msgbuf)
369 if retval:
370 msgbuf.append("Skipping setscene dependency %s for installation into the sysroot" % datadep)
371 continue
372 done.append(datadep)
373 new.append(datadep)
374 if datadep not in configuredeps and setscenedeps[datadep][1] == "do_populate_sysroot":
375 configuredeps.append(datadep)
376 msgbuf.append("Adding dependency on %s" % setscenedeps[datadep][0])
377 else:
378 msgbuf.append("Following dependency on %s" % setscenedeps[datadep][0])
379 next = new
380
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500381 # This logging is too verbose for day to day use sadly
382 #bb.debug(2, "\n".join(msgbuf))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500383
384 depdir = recipesysrootnative + "/installeddeps"
385 bb.utils.mkdirhier(depdir)
386 bb.utils.mkdirhier(sharedmanifests)
387
388 lock = bb.utils.lockfile(recipesysroot + "/sysroot.lock")
389
390 fixme = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500391 seendirs = set()
392 postinsts = []
393 multilibs = {}
394 manifests = {}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500395 # All files that we're going to be installing, to find conflicts.
396 fileset = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500397
398 for f in os.listdir(depdir):
399 if not f.endswith(".complete"):
400 continue
401 f = depdir + "/" + f
402 if os.path.islink(f) and not os.path.exists(f):
403 bb.note("%s no longer exists, removing from sysroot" % f)
404 lnk = os.readlink(f.replace(".complete", ""))
405 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
406 os.unlink(f)
407 os.unlink(f.replace(".complete", ""))
408
409 installed = []
410 for dep in configuredeps:
411 c = setscenedeps[dep][0]
412 if mytaskname in ["do_sdk_depends", "do_populate_sdk_ext"] and c.endswith("-initial"):
413 bb.note("Skipping initial setscene dependency %s for installation into the sysroot" % c)
414 continue
415 installed.append(c)
416
417 # We want to remove anything which this task previously installed but is no longer a dependency
418 taskindex = depdir + "/" + "index." + mytaskname
419 if os.path.exists(taskindex):
420 potential = []
421 with open(taskindex, "r") as f:
422 for l in f:
423 l = l.strip()
424 if l not in installed:
425 fl = depdir + "/" + l
426 if not os.path.exists(fl):
427 # Was likely already uninstalled
428 continue
429 potential.append(l)
430 # We need to ensure not other task needs this dependency. We hold the sysroot
431 # lock so we ca search the indexes to check
432 if potential:
433 for i in glob.glob(depdir + "/index.*"):
434 if i.endswith("." + mytaskname):
435 continue
436 with open(i, "r") as f:
437 for l in f:
438 l = l.strip()
439 if l in potential:
440 potential.remove(l)
441 for l in potential:
442 fl = depdir + "/" + l
443 bb.note("Task %s no longer depends on %s, removing from sysroot" % (mytaskname, l))
444 lnk = os.readlink(fl)
445 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
446 os.unlink(fl)
447 os.unlink(fl + ".complete")
448
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500449 msg_exists = []
450 msg_adding = []
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800451
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500452 for dep in configuredeps:
453 c = setscenedeps[dep][0]
454 if c not in installed:
455 continue
456 taskhash = setscenedeps[dep][5]
457 taskmanifest = depdir + "/" + c + "." + taskhash
458
459 if os.path.exists(depdir + "/" + c):
460 lnk = os.readlink(depdir + "/" + c)
461 if lnk == c + "." + taskhash and os.path.exists(depdir + "/" + c + ".complete"):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500462 msg_exists.append(c)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500463 continue
464 else:
465 bb.note("%s exists in sysroot, but is stale (%s vs. %s), removing." % (c, lnk, c + "." + taskhash))
466 sstate_clean_manifest(depdir + "/" + lnk, d, workdir)
467 os.unlink(depdir + "/" + c)
468 if os.path.lexists(depdir + "/" + c + ".complete"):
469 os.unlink(depdir + "/" + c + ".complete")
470 elif os.path.lexists(depdir + "/" + c):
471 os.unlink(depdir + "/" + c)
472
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500473 msg_adding.append(c)
474
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500475 os.symlink(c + "." + taskhash, depdir + "/" + c)
476
Brad Bishop316dfdd2018-06-25 12:45:53 -0400477 manifest, d2 = oe.sstatesig.find_sstate_manifest(c, setscenedeps[dep][2], "populate_sysroot", d, multilibs)
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700478 if d2 is not d:
479 # If we don't do this, the recipe sysroot will be placed in the wrong WORKDIR for multilibs
480 # We need a consistent WORKDIR for the image
481 d2.setVar("WORKDIR", d.getVar("WORKDIR"))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400482 destsysroot = d2.getVar("RECIPE_SYSROOT")
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700483 # We put allarch recipes into the default sysroot
484 if manifest and "allarch" in manifest:
485 destsysroot = d.getVar("RECIPE_SYSROOT")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500486
487 native = False
Brad Bishop316dfdd2018-06-25 12:45:53 -0400488 if c.endswith("-native") or "-cross-" in c or "-crosssdk" in c:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500489 native = True
Brad Bishop316dfdd2018-06-25 12:45:53 -0400490
491 if manifest:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500492 newmanifest = collections.OrderedDict()
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700493 targetdir = destsysroot
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500494 if native:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500495 targetdir = recipesysrootnative
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700496 if targetdir not in fixme:
497 fixme[targetdir] = []
498 fm = fixme[targetdir]
499
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500500 with open(manifest, "r") as f:
501 manifests[dep] = manifest
502 for l in f:
503 l = l.strip()
504 if l.endswith("/fixmepath"):
505 fm.append(l)
506 continue
507 if l.endswith("/fixmepath.cmd"):
508 continue
509 dest = l.replace(stagingdir, "")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500510 dest = "/" + "/".join(dest.split("/")[3:])
511 newmanifest[l] = targetdir + dest
512
513 # Check if files have already been installed by another
514 # recipe and abort if they have, explaining what recipes are
515 # conflicting.
516 hashname = targetdir + dest
517 if not hashname.endswith("/"):
518 if hashname in fileset:
519 bb.fatal("The file %s is installed by both %s and %s, aborting" % (dest, c, fileset[hashname]))
520 else:
521 fileset[hashname] = c
522
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500523 # Having multiple identical manifests in each sysroot eats diskspace so
524 # create a shared pool of them and hardlink if we can.
525 # We create the manifest in advance so that if something fails during installation,
526 # or the build is interrupted, subsequent exeuction can cleanup.
527 sharedm = sharedmanifests + "/" + os.path.basename(taskmanifest)
528 if not os.path.exists(sharedm):
529 smlock = bb.utils.lockfile(sharedm + ".lock")
530 # Can race here. You'd think it just means we may not end up with all copies hardlinked to each other
531 # but python can lose file handles so we need to do this under a lock.
532 if not os.path.exists(sharedm):
533 with open(sharedm, 'w') as m:
534 for l in newmanifest:
535 dest = newmanifest[l]
536 m.write(dest.replace(workdir + "/", "") + "\n")
537 bb.utils.unlockfile(smlock)
538 try:
539 os.link(sharedm, taskmanifest)
540 except OSError as err:
541 if err.errno == errno.EXDEV:
542 bb.utils.copyfile(sharedm, taskmanifest)
543 else:
544 raise
545 # Finally actually install the files
546 for l in newmanifest:
547 dest = newmanifest[l]
548 if l.endswith("/"):
549 staging_copydir(l, targetdir, dest, seendirs)
550 continue
551 staging_copyfile(l, targetdir, dest, postinsts, seendirs)
552
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500553 bb.note("Installed into sysroot: %s" % str(msg_adding))
554 bb.note("Skipping as already exists in sysroot: %s" % str(msg_exists))
555
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500556 for f in fixme:
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700557 staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500558
559 for p in postinsts:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400560 subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500561
562 for dep in manifests:
563 c = setscenedeps[dep][0]
564 os.symlink(manifests[dep], depdir + "/" + c + ".complete")
565
566 with open(taskindex, "w") as f:
567 for l in sorted(installed):
568 f.write(l + "\n")
569
570 bb.utils.unlockfile(lock)
571}
572extend_recipe_sysroot[vardepsexclude] += "MACHINE_ARCH PACKAGE_EXTRA_ARCHS SDK_ARCH BUILD_ARCH SDK_OS BB_TASKDEPDATA"
573
Brad Bishop19323692019-04-05 15:28:33 -0400574do_prepare_recipe_sysroot[deptask] = "do_populate_sysroot"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500575python do_prepare_recipe_sysroot () {
576 bb.build.exec_func("extend_recipe_sysroot", d)
577}
578addtask do_prepare_recipe_sysroot before do_configure after do_fetch
579
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500580python staging_taskhandler() {
581 bbtasks = e.tasklist
582 for task in bbtasks:
583 deps = d.getVarFlag(task, "depends")
584 if deps and "populate_sysroot" in deps:
585 d.appendVarFlag(task, "prefuncs", " extend_recipe_sysroot")
586}
587staging_taskhandler[eventmask] = "bb.event.RecipeTaskPreProcess"
588addhandler staging_taskhandler