Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | # These directories will be staged in the sysroot |
| 2 | SYSROOT_DIRS = " \ |
| 3 | ${includedir} \ |
| 4 | ${libdir} \ |
| 5 | ${base_libdir} \ |
| 6 | ${nonarch_base_libdir} \ |
| 7 | ${datadir} \ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 8 | /sysroot-only \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9 | " |
| 10 | |
| 11 | # These directories are also staged in the sysroot when they contain files that |
| 12 | # are usable on the build system |
| 13 | SYSROOT_DIRS_NATIVE = " \ |
| 14 | ${bindir} \ |
| 15 | ${sbindir} \ |
| 16 | ${base_bindir} \ |
| 17 | ${base_sbindir} \ |
| 18 | ${libexecdir} \ |
| 19 | ${sysconfdir} \ |
| 20 | ${localstatedir} \ |
| 21 | " |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 22 | SYSROOT_DIRS:append:class-native = " ${SYSROOT_DIRS_NATIVE}" |
| 23 | SYSROOT_DIRS:append:class-cross = " ${SYSROOT_DIRS_NATIVE}" |
| 24 | SYSROOT_DIRS:append:class-crosssdk = " ${SYSROOT_DIRS_NATIVE}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 25 | |
| 26 | # These directories will not be staged in the sysroot |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 27 | SYSROOT_DIRS_IGNORE = " \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 28 | ${mandir} \ |
| 29 | ${docdir} \ |
| 30 | ${infodir} \ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 31 | ${datadir}/X11/locale \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 32 | ${datadir}/applications \ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 33 | ${datadir}/bash-completion \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 34 | ${datadir}/fonts \ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 35 | ${datadir}/gtk-doc/html \ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 36 | ${datadir}/installed-tests \ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 37 | ${datadir}/locale \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 38 | ${datadir}/pixmaps \ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 39 | ${datadir}/terminfo \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 40 | ${libdir}/${BPN}/ptest \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | |
| 43 | sysroot_stage_dir() { |
| 44 | src="$1" |
| 45 | dest="$2" |
| 46 | # if the src doesn't exist don't do anything |
| 47 | if [ ! -d "$src" ]; then |
| 48 | return |
| 49 | fi |
| 50 | |
| 51 | mkdir -p "$dest" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 52 | rdest=$(realpath --relative-to="$src" "$dest") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | ( |
| 54 | cd $src |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 55 | find . -print0 | cpio --null -pdlu $rdest |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | ) |
| 57 | } |
| 58 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | sysroot_stage_dirs() { |
| 60 | from="$1" |
| 61 | to="$2" |
| 62 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 63 | for dir in ${SYSROOT_DIRS}; do |
| 64 | sysroot_stage_dir "$from$dir" "$to$dir" |
| 65 | done |
| 66 | |
| 67 | # Remove directories we do not care about |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 68 | for dir in ${SYSROOT_DIRS_IGNORE}; do |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | rm -rf "$to$dir" |
| 70 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | sysroot_stage_all() { |
| 74 | sysroot_stage_dirs ${D} ${SYSROOT_DESTDIR} |
| 75 | } |
| 76 | |
| 77 | python sysroot_strip () { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 78 | inhibit_sysroot = d.getVar('INHIBIT_SYSROOT_STRIP') |
| 79 | if inhibit_sysroot and oe.types.boolean(inhibit_sysroot): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 80 | return |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 82 | dstdir = d.getVar('SYSROOT_DESTDIR') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 83 | pn = d.getVar('PN') |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 84 | libdir = d.getVar("libdir") |
| 85 | base_libdir = d.getVar("base_libdir") |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 86 | qa_already_stripped = 'already-stripped' in (d.getVar('INSANE_SKIP:' + pn) or "").split() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 87 | strip_cmd = d.getVar("STRIP") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 89 | oe.package.strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, d, |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 90 | qa_already_stripped=qa_already_stripped) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | do_populate_sysroot[dirs] = "${SYSROOT_DESTDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | |
| 95 | addtask populate_sysroot after do_install |
| 96 | |
| 97 | SYSROOT_PREPROCESS_FUNCS ?= "" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 98 | SYSROOT_DESTDIR = "${WORKDIR}/sysroot-destdir" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 99 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | python do_populate_sysroot () { |
Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 101 | # SYSROOT 'version' 2 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | bb.build.exec_func("sysroot_stage_all", d) |
| 103 | bb.build.exec_func("sysroot_strip", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 104 | for f in (d.getVar('SYSROOT_PREPROCESS_FUNCS') or '').split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | bb.build.exec_func(f, d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 106 | pn = d.getVar("PN") |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 107 | multiprov = d.getVar("BB_MULTI_PROVIDER_ALLOWED").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | provdir = d.expand("${SYSROOT_DESTDIR}${base_prefix}/sysroot-providers/") |
| 109 | bb.utils.mkdirhier(provdir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 110 | for p in d.getVar("PROVIDES").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 111 | if p in multiprov: |
| 112 | continue |
| 113 | p = p.replace("/", "_") |
| 114 | with open(provdir + p, "w") as f: |
| 115 | f.write(pn) |
| 116 | } |
| 117 | |
| 118 | do_populate_sysroot[vardeps] += "${SYSROOT_PREPROCESS_FUNCS}" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 119 | do_populate_sysroot[vardepsexclude] += "BB_MULTI_PROVIDER_ALLOWED" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 120 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 121 | POPULATESYSROOTDEPS = "" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 122 | POPULATESYSROOTDEPS:class-target = "virtual/${MLPREFIX}${HOST_PREFIX}binutils:do_populate_sysroot" |
| 123 | POPULATESYSROOTDEPS:class-nativesdk = "virtual/${HOST_PREFIX}binutils-crosssdk:do_populate_sysroot" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 124 | do_populate_sysroot[depends] += "${POPULATESYSROOTDEPS}" |
| 125 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | SSTATETASKS += "do_populate_sysroot" |
| 127 | do_populate_sysroot[cleandirs] = "${SYSROOT_DESTDIR}" |
| 128 | do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 129 | do_populate_sysroot[sstate-outputdirs] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}" |
| 130 | do_populate_sysroot[sstate-fixmedir] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | |
| 132 | python do_populate_sysroot_setscene () { |
| 133 | sstate_setscene(d) |
| 134 | } |
| 135 | addtask do_populate_sysroot_setscene |
| 136 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 137 | def staging_copyfile(c, target, dest, postinsts, seendirs): |
| 138 | import errno |
| 139 | |
| 140 | destdir = os.path.dirname(dest) |
| 141 | if destdir not in seendirs: |
| 142 | bb.utils.mkdirhier(destdir) |
| 143 | seendirs.add(destdir) |
| 144 | if "/usr/bin/postinst-" in c: |
| 145 | postinsts.append(dest) |
| 146 | if os.path.islink(c): |
| 147 | linkto = os.readlink(c) |
| 148 | if os.path.lexists(dest): |
| 149 | if not os.path.islink(dest): |
| 150 | raise OSError(errno.EEXIST, "Link %s already exists as a file" % dest, dest) |
| 151 | if os.readlink(dest) == linkto: |
| 152 | return dest |
| 153 | raise OSError(errno.EEXIST, "Link %s already exists to a different location? (%s vs %s)" % (dest, os.readlink(dest), linkto), dest) |
| 154 | os.symlink(linkto, dest) |
| 155 | #bb.warn(c) |
| 156 | else: |
| 157 | try: |
| 158 | os.link(c, dest) |
| 159 | except OSError as err: |
| 160 | if err.errno == errno.EXDEV: |
| 161 | bb.utils.copyfile(c, dest) |
| 162 | else: |
| 163 | raise |
| 164 | return dest |
| 165 | |
| 166 | def staging_copydir(c, target, dest, seendirs): |
| 167 | if dest not in seendirs: |
| 168 | bb.utils.mkdirhier(dest) |
| 169 | seendirs.add(dest) |
| 170 | |
| 171 | def staging_processfixme(fixme, target, recipesysroot, recipesysrootnative, d): |
| 172 | import subprocess |
| 173 | |
| 174 | if not fixme: |
| 175 | return |
| 176 | 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 Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 177 | for fixmevar in ['PSEUDO_SYSROOT', 'HOSTTOOLS_DIR', 'PKGDATA_DIR', 'PSEUDO_LOCALSTATEDIR', 'LOGFIFO']: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 178 | fixme_path = d.getVar(fixmevar) |
| 179 | cmd += " -e 's:FIXME_%s:%s:g'" % (fixmevar, fixme_path) |
| 180 | bb.debug(2, cmd) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 181 | subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 182 | |
| 183 | |
| 184 | def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d): |
| 185 | import glob |
| 186 | import subprocess |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 187 | import errno |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 188 | |
| 189 | fixme = [] |
| 190 | postinsts = [] |
| 191 | seendirs = set() |
| 192 | stagingdir = d.getVar("STAGING_DIR") |
| 193 | if native: |
| 194 | pkgarchs = ['${BUILD_ARCH}', '${BUILD_ARCH}_*'] |
| 195 | targetdir = nativesysroot |
| 196 | else: |
| 197 | pkgarchs = ['${MACHINE_ARCH}'] |
| 198 | pkgarchs = pkgarchs + list(reversed(d.getVar("PACKAGE_EXTRA_ARCHS").split())) |
| 199 | pkgarchs.append('allarch') |
| 200 | targetdir = targetsysroot |
| 201 | |
| 202 | bb.utils.mkdirhier(targetdir) |
| 203 | for pkgarch in pkgarchs: |
| 204 | for manifest in glob.glob(d.expand("${SSTATE_MANIFESTS}/manifest-%s-*.populate_sysroot" % pkgarch)): |
| 205 | if manifest.endswith("-initial.populate_sysroot"): |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 206 | # skip libgcc-initial due to file overlap |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 207 | continue |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 208 | if not native and (manifest.endswith("-native.populate_sysroot") or "nativesdk-" in manifest): |
| 209 | continue |
| 210 | if native and not (manifest.endswith("-native.populate_sysroot") or manifest.endswith("-cross.populate_sysroot") or "-cross-" in manifest): |
| 211 | continue |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 212 | tmanifest = targetdir + "/" + os.path.basename(manifest) |
| 213 | if os.path.exists(tmanifest): |
| 214 | continue |
| 215 | try: |
| 216 | os.link(manifest, tmanifest) |
| 217 | except OSError as err: |
| 218 | if err.errno == errno.EXDEV: |
| 219 | bb.utils.copyfile(manifest, tmanifest) |
| 220 | else: |
| 221 | raise |
| 222 | with open(manifest, "r") as f: |
| 223 | for l in f: |
| 224 | l = l.strip() |
| 225 | if l.endswith("/fixmepath"): |
| 226 | fixme.append(l) |
| 227 | continue |
| 228 | if l.endswith("/fixmepath.cmd"): |
| 229 | continue |
| 230 | dest = l.replace(stagingdir, "") |
| 231 | dest = targetdir + "/" + "/".join(dest.split("/")[3:]) |
| 232 | if l.endswith("/"): |
| 233 | staging_copydir(l, targetdir, dest, seendirs) |
| 234 | continue |
| 235 | try: |
| 236 | staging_copyfile(l, targetdir, dest, postinsts, seendirs) |
| 237 | except FileExistsError: |
| 238 | continue |
| 239 | |
| 240 | staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot, d) |
| 241 | for p in postinsts: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 242 | subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 243 | |
| 244 | # |
| 245 | # Manifests here are complicated. The main sysroot area has the unpacked sstate |
| 246 | # which us unrelocated and tracked by the main sstate manifests. Each recipe |
| 247 | # specific sysroot has manifests for each dependency that is installed there. |
| 248 | # The task hash is used to tell whether the data needs to be reinstalled. We |
| 249 | # use a symlink to point to the currently installed hash. There is also a |
| 250 | # "complete" stamp file which is used to mark if installation completed. If |
| 251 | # something fails (e.g. a postinst), this won't get written and we would |
| 252 | # remove and reinstall the dependency. This also means partially installed |
| 253 | # dependencies should get cleaned up correctly. |
| 254 | # |
| 255 | |
| 256 | python extend_recipe_sysroot() { |
| 257 | import copy |
| 258 | import subprocess |
| 259 | import errno |
| 260 | import collections |
| 261 | import glob |
| 262 | |
| 263 | taskdepdata = d.getVar("BB_TASKDEPDATA", False) |
| 264 | mytaskname = d.getVar("BB_RUNTASK") |
| 265 | if mytaskname.endswith("_setscene"): |
| 266 | mytaskname = mytaskname.replace("_setscene", "") |
| 267 | workdir = d.getVar("WORKDIR") |
| 268 | #bb.warn(str(taskdepdata)) |
| 269 | pn = d.getVar("PN") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 270 | stagingdir = d.getVar("STAGING_DIR") |
| 271 | sharedmanifests = d.getVar("COMPONENTS_DIR") + "/manifests" |
| 272 | recipesysroot = d.getVar("RECIPE_SYSROOT") |
| 273 | recipesysrootnative = d.getVar("RECIPE_SYSROOT_NATIVE") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 274 | |
| 275 | # Detect bitbake -b usage |
| 276 | nodeps = d.getVar("BB_LIMITEDDEPS") or False |
| 277 | if nodeps: |
| 278 | lock = bb.utils.lockfile(recipesysroot + "/sysroot.lock") |
| 279 | staging_populate_sysroot_dir(recipesysroot, recipesysrootnative, True, d) |
| 280 | staging_populate_sysroot_dir(recipesysroot, recipesysrootnative, False, d) |
| 281 | bb.utils.unlockfile(lock) |
| 282 | return |
| 283 | |
| 284 | start = None |
| 285 | configuredeps = [] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 286 | owntaskdeps = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 287 | for dep in taskdepdata: |
| 288 | data = taskdepdata[dep] |
| 289 | if data[1] == mytaskname and data[0] == pn: |
| 290 | start = dep |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 291 | elif data[0] == pn: |
| 292 | owntaskdeps.append(data[1]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 293 | if start is None: |
| 294 | bb.fatal("Couldn't find ourself in BB_TASKDEPDATA?") |
| 295 | |
| 296 | # We need to figure out which sysroot files we need to expose to this task. |
| 297 | # This needs to match what would get restored from sstate, which is controlled |
| 298 | # ultimately by calls from bitbake to setscene_depvalid(). |
| 299 | # That function expects a setscene dependency tree. We build a dependency tree |
| 300 | # condensed to inter-sstate task dependencies, similar to that used by setscene |
| 301 | # tasks. We can then call into setscene_depvalid() and decide |
| 302 | # which dependencies we can "see" and should expose in the recipe specific sysroot. |
| 303 | setscenedeps = copy.deepcopy(taskdepdata) |
| 304 | |
| 305 | start = set([start]) |
| 306 | |
| 307 | sstatetasks = d.getVar("SSTATETASKS").split() |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 308 | # Add recipe specific tasks referenced by setscene_depvalid() |
| 309 | sstatetasks.append("do_stash_locale") |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 310 | sstatetasks.append("do_deploy") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 311 | |
| 312 | def print_dep_tree(deptree): |
| 313 | data = "" |
| 314 | for dep in deptree: |
| 315 | deps = " " + "\n ".join(deptree[dep][3]) + "\n" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 316 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 317 | return data |
| 318 | |
| 319 | #bb.note("Full dep tree is:\n%s" % print_dep_tree(taskdepdata)) |
| 320 | |
| 321 | #bb.note(" start2 is %s" % str(start)) |
| 322 | |
| 323 | # If start is an sstate task (like do_package) we need to add in its direct dependencies |
| 324 | # else the code below won't recurse into them. |
| 325 | for dep in set(start): |
| 326 | for dep2 in setscenedeps[dep][3]: |
| 327 | start.add(dep2) |
| 328 | start.remove(dep) |
| 329 | |
| 330 | #bb.note(" start3 is %s" % str(start)) |
| 331 | |
| 332 | # Create collapsed do_populate_sysroot -> do_populate_sysroot tree |
| 333 | for dep in taskdepdata: |
| 334 | data = setscenedeps[dep] |
| 335 | if data[1] not in sstatetasks: |
| 336 | for dep2 in setscenedeps: |
| 337 | data2 = setscenedeps[dep2] |
| 338 | if dep in data2[3]: |
| 339 | data2[3].update(setscenedeps[dep][3]) |
| 340 | data2[3].remove(dep) |
| 341 | if dep in start: |
| 342 | start.update(setscenedeps[dep][3]) |
| 343 | start.remove(dep) |
| 344 | del setscenedeps[dep] |
| 345 | |
| 346 | # Remove circular references |
| 347 | for dep in setscenedeps: |
| 348 | if dep in setscenedeps[dep][3]: |
| 349 | setscenedeps[dep][3].remove(dep) |
| 350 | |
| 351 | #bb.note("Computed dep tree is:\n%s" % print_dep_tree(setscenedeps)) |
| 352 | #bb.note(" start is %s" % str(start)) |
| 353 | |
| 354 | # Direct dependencies should be present and can be depended upon |
| 355 | for dep in set(start): |
| 356 | if setscenedeps[dep][1] == "do_populate_sysroot": |
| 357 | if dep not in configuredeps: |
| 358 | configuredeps.append(dep) |
| 359 | bb.note("Direct dependencies are %s" % str(configuredeps)) |
| 360 | #bb.note(" or %s" % str(start)) |
| 361 | |
| 362 | msgbuf = [] |
| 363 | # Call into setscene_depvalid for each sub-dependency and only copy sysroot files |
| 364 | # for ones that would be restored from sstate. |
| 365 | done = list(start) |
| 366 | next = list(start) |
| 367 | while next: |
| 368 | new = [] |
| 369 | for dep in next: |
| 370 | data = setscenedeps[dep] |
| 371 | for datadep in data[3]: |
| 372 | if datadep in done: |
| 373 | continue |
| 374 | taskdeps = {} |
| 375 | taskdeps[dep] = setscenedeps[dep][:2] |
| 376 | taskdeps[datadep] = setscenedeps[datadep][:2] |
| 377 | retval = setscene_depvalid(datadep, taskdeps, [], d, msgbuf) |
| 378 | if retval: |
| 379 | msgbuf.append("Skipping setscene dependency %s for installation into the sysroot" % datadep) |
| 380 | continue |
| 381 | done.append(datadep) |
| 382 | new.append(datadep) |
| 383 | if datadep not in configuredeps and setscenedeps[datadep][1] == "do_populate_sysroot": |
| 384 | configuredeps.append(datadep) |
| 385 | msgbuf.append("Adding dependency on %s" % setscenedeps[datadep][0]) |
| 386 | else: |
| 387 | msgbuf.append("Following dependency on %s" % setscenedeps[datadep][0]) |
| 388 | next = new |
| 389 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 390 | # This logging is too verbose for day to day use sadly |
| 391 | #bb.debug(2, "\n".join(msgbuf)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 392 | |
| 393 | depdir = recipesysrootnative + "/installeddeps" |
| 394 | bb.utils.mkdirhier(depdir) |
| 395 | bb.utils.mkdirhier(sharedmanifests) |
| 396 | |
| 397 | lock = bb.utils.lockfile(recipesysroot + "/sysroot.lock") |
| 398 | |
| 399 | fixme = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 400 | seendirs = set() |
| 401 | postinsts = [] |
| 402 | multilibs = {} |
| 403 | manifests = {} |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 404 | # All files that we're going to be installing, to find conflicts. |
| 405 | fileset = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 406 | |
| 407 | for f in os.listdir(depdir): |
| 408 | if not f.endswith(".complete"): |
| 409 | continue |
| 410 | f = depdir + "/" + f |
| 411 | if os.path.islink(f) and not os.path.exists(f): |
| 412 | bb.note("%s no longer exists, removing from sysroot" % f) |
| 413 | lnk = os.readlink(f.replace(".complete", "")) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 414 | sstate_clean_manifest(depdir + "/" + lnk, d, canrace=True, prefix=workdir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 415 | os.unlink(f) |
| 416 | os.unlink(f.replace(".complete", "")) |
| 417 | |
| 418 | installed = [] |
| 419 | for dep in configuredeps: |
| 420 | c = setscenedeps[dep][0] |
| 421 | if mytaskname in ["do_sdk_depends", "do_populate_sdk_ext"] and c.endswith("-initial"): |
| 422 | bb.note("Skipping initial setscene dependency %s for installation into the sysroot" % c) |
| 423 | continue |
| 424 | installed.append(c) |
| 425 | |
| 426 | # We want to remove anything which this task previously installed but is no longer a dependency |
| 427 | taskindex = depdir + "/" + "index." + mytaskname |
| 428 | if os.path.exists(taskindex): |
| 429 | potential = [] |
| 430 | with open(taskindex, "r") as f: |
| 431 | for l in f: |
| 432 | l = l.strip() |
| 433 | if l not in installed: |
| 434 | fl = depdir + "/" + l |
| 435 | if not os.path.exists(fl): |
| 436 | # Was likely already uninstalled |
| 437 | continue |
| 438 | potential.append(l) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 439 | # We need to ensure no other task needs this dependency. We hold the sysroot |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 440 | # lock so we ca search the indexes to check |
| 441 | if potential: |
| 442 | for i in glob.glob(depdir + "/index.*"): |
| 443 | if i.endswith("." + mytaskname): |
| 444 | continue |
| 445 | with open(i, "r") as f: |
| 446 | for l in f: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 447 | if l.startswith("TaskDeps:"): |
| 448 | prevtasks = l.split()[1:] |
| 449 | if mytaskname in prevtasks: |
| 450 | # We're a dependency of this task so we can clear items out the sysroot |
| 451 | break |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 452 | l = l.strip() |
| 453 | if l in potential: |
| 454 | potential.remove(l) |
| 455 | for l in potential: |
| 456 | fl = depdir + "/" + l |
| 457 | bb.note("Task %s no longer depends on %s, removing from sysroot" % (mytaskname, l)) |
| 458 | lnk = os.readlink(fl) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 459 | sstate_clean_manifest(depdir + "/" + lnk, d, canrace=True, prefix=workdir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 460 | os.unlink(fl) |
| 461 | os.unlink(fl + ".complete") |
| 462 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 463 | msg_exists = [] |
| 464 | msg_adding = [] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 465 | |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 466 | # Handle all removals first since files may move between recipes |
| 467 | for dep in configuredeps: |
| 468 | c = setscenedeps[dep][0] |
| 469 | if c not in installed: |
| 470 | continue |
| 471 | taskhash = setscenedeps[dep][5] |
| 472 | taskmanifest = depdir + "/" + c + "." + taskhash |
| 473 | |
| 474 | if os.path.exists(depdir + "/" + c): |
| 475 | lnk = os.readlink(depdir + "/" + c) |
| 476 | if lnk == c + "." + taskhash and os.path.exists(depdir + "/" + c + ".complete"): |
| 477 | continue |
| 478 | else: |
| 479 | bb.note("%s exists in sysroot, but is stale (%s vs. %s), removing." % (c, lnk, c + "." + taskhash)) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 480 | sstate_clean_manifest(depdir + "/" + lnk, d, canrace=True, prefix=workdir) |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 481 | os.unlink(depdir + "/" + c) |
| 482 | if os.path.lexists(depdir + "/" + c + ".complete"): |
| 483 | os.unlink(depdir + "/" + c + ".complete") |
| 484 | elif os.path.lexists(depdir + "/" + c): |
| 485 | os.unlink(depdir + "/" + c) |
| 486 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 487 | binfiles = {} |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 488 | # Now handle installs |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 489 | for dep in configuredeps: |
| 490 | c = setscenedeps[dep][0] |
| 491 | if c not in installed: |
| 492 | continue |
| 493 | taskhash = setscenedeps[dep][5] |
| 494 | taskmanifest = depdir + "/" + c + "." + taskhash |
| 495 | |
| 496 | if os.path.exists(depdir + "/" + c): |
| 497 | lnk = os.readlink(depdir + "/" + c) |
| 498 | if lnk == c + "." + taskhash and os.path.exists(depdir + "/" + c + ".complete"): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 499 | msg_exists.append(c) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 500 | continue |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 501 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 502 | msg_adding.append(c) |
| 503 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 504 | os.symlink(c + "." + taskhash, depdir + "/" + c) |
| 505 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 506 | manifest, d2 = oe.sstatesig.find_sstate_manifest(c, setscenedeps[dep][2], "populate_sysroot", d, multilibs) |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 507 | if d2 is not d: |
| 508 | # If we don't do this, the recipe sysroot will be placed in the wrong WORKDIR for multilibs |
| 509 | # We need a consistent WORKDIR for the image |
| 510 | d2.setVar("WORKDIR", d.getVar("WORKDIR")) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 511 | destsysroot = d2.getVar("RECIPE_SYSROOT") |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 512 | # We put allarch recipes into the default sysroot |
| 513 | if manifest and "allarch" in manifest: |
| 514 | destsysroot = d.getVar("RECIPE_SYSROOT") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 515 | |
| 516 | native = False |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 517 | if c.endswith("-native") or "-cross-" in c or "-crosssdk" in c: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 518 | native = True |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 519 | |
| 520 | if manifest: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 521 | newmanifest = collections.OrderedDict() |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 522 | targetdir = destsysroot |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 523 | if native: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 524 | targetdir = recipesysrootnative |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 525 | if targetdir not in fixme: |
| 526 | fixme[targetdir] = [] |
| 527 | fm = fixme[targetdir] |
| 528 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 529 | with open(manifest, "r") as f: |
| 530 | manifests[dep] = manifest |
| 531 | for l in f: |
| 532 | l = l.strip() |
| 533 | if l.endswith("/fixmepath"): |
| 534 | fm.append(l) |
| 535 | continue |
| 536 | if l.endswith("/fixmepath.cmd"): |
| 537 | continue |
| 538 | dest = l.replace(stagingdir, "") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 539 | dest = "/" + "/".join(dest.split("/")[3:]) |
| 540 | newmanifest[l] = targetdir + dest |
| 541 | |
| 542 | # Check if files have already been installed by another |
| 543 | # recipe and abort if they have, explaining what recipes are |
| 544 | # conflicting. |
| 545 | hashname = targetdir + dest |
| 546 | if not hashname.endswith("/"): |
| 547 | if hashname in fileset: |
| 548 | bb.fatal("The file %s is installed by both %s and %s, aborting" % (dest, c, fileset[hashname])) |
| 549 | else: |
| 550 | fileset[hashname] = c |
| 551 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 552 | # Having multiple identical manifests in each sysroot eats diskspace so |
| 553 | # create a shared pool of them and hardlink if we can. |
| 554 | # We create the manifest in advance so that if something fails during installation, |
| 555 | # or the build is interrupted, subsequent exeuction can cleanup. |
| 556 | sharedm = sharedmanifests + "/" + os.path.basename(taskmanifest) |
| 557 | if not os.path.exists(sharedm): |
| 558 | smlock = bb.utils.lockfile(sharedm + ".lock") |
| 559 | # Can race here. You'd think it just means we may not end up with all copies hardlinked to each other |
| 560 | # but python can lose file handles so we need to do this under a lock. |
| 561 | if not os.path.exists(sharedm): |
| 562 | with open(sharedm, 'w') as m: |
| 563 | for l in newmanifest: |
| 564 | dest = newmanifest[l] |
| 565 | m.write(dest.replace(workdir + "/", "") + "\n") |
| 566 | bb.utils.unlockfile(smlock) |
| 567 | try: |
| 568 | os.link(sharedm, taskmanifest) |
| 569 | except OSError as err: |
| 570 | if err.errno == errno.EXDEV: |
| 571 | bb.utils.copyfile(sharedm, taskmanifest) |
| 572 | else: |
| 573 | raise |
| 574 | # Finally actually install the files |
| 575 | for l in newmanifest: |
| 576 | dest = newmanifest[l] |
| 577 | if l.endswith("/"): |
| 578 | staging_copydir(l, targetdir, dest, seendirs) |
| 579 | continue |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 580 | if "/bin/" in l or "/sbin/" in l: |
| 581 | # defer /*bin/* files until last in case they need libs |
| 582 | binfiles[l] = (targetdir, dest) |
| 583 | else: |
| 584 | staging_copyfile(l, targetdir, dest, postinsts, seendirs) |
| 585 | |
| 586 | # Handle deferred binfiles |
| 587 | for l in binfiles: |
| 588 | (targetdir, dest) = binfiles[l] |
| 589 | staging_copyfile(l, targetdir, dest, postinsts, seendirs) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 590 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 591 | bb.note("Installed into sysroot: %s" % str(msg_adding)) |
| 592 | bb.note("Skipping as already exists in sysroot: %s" % str(msg_exists)) |
| 593 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 594 | for f in fixme: |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 595 | staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 596 | |
| 597 | for p in postinsts: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 598 | subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 599 | |
| 600 | for dep in manifests: |
| 601 | c = setscenedeps[dep][0] |
| 602 | os.symlink(manifests[dep], depdir + "/" + c + ".complete") |
| 603 | |
| 604 | with open(taskindex, "w") as f: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 605 | f.write("TaskDeps: " + " ".join(owntaskdeps) + "\n") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 606 | for l in sorted(installed): |
| 607 | f.write(l + "\n") |
| 608 | |
| 609 | bb.utils.unlockfile(lock) |
| 610 | } |
| 611 | extend_recipe_sysroot[vardepsexclude] += "MACHINE_ARCH PACKAGE_EXTRA_ARCHS SDK_ARCH BUILD_ARCH SDK_OS BB_TASKDEPDATA" |
| 612 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 613 | do_prepare_recipe_sysroot[deptask] = "do_populate_sysroot" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 614 | python do_prepare_recipe_sysroot () { |
| 615 | bb.build.exec_func("extend_recipe_sysroot", d) |
| 616 | } |
| 617 | addtask do_prepare_recipe_sysroot before do_configure after do_fetch |
| 618 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 619 | python staging_taskhandler() { |
| 620 | bbtasks = e.tasklist |
| 621 | for task in bbtasks: |
| 622 | deps = d.getVarFlag(task, "depends") |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 623 | if task == "do_configure" or (deps and "populate_sysroot" in deps): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 624 | d.prependVarFlag(task, "prefuncs", "extend_recipe_sysroot ") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 625 | } |
| 626 | staging_taskhandler[eventmask] = "bb.event.RecipeTaskPreProcess" |
| 627 | addhandler staging_taskhandler |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 628 | |
| 629 | |
| 630 | # |
| 631 | # Target build output, stored in do_populate_sysroot or do_package can depend |
| 632 | # not only upon direct dependencies but also indirect ones. A good example is |
| 633 | # linux-libc-headers. The toolchain depends on this but most target recipes do |
| 634 | # not. There are some headers which are not used by the toolchain build and do |
| 635 | # not change the toolchain task output, hence the task hashes can change without |
| 636 | # changing the sysroot output of that recipe yet they can influence others. |
| 637 | # |
| 638 | # A specific example is rtc.h which can change rtcwake.c in util-linux but is not |
| 639 | # used in the glibc or gcc build. To account for this, we need to account for the |
| 640 | # populate_sysroot hashes in the task output hashes. |
| 641 | # |
| 642 | python target_add_sysroot_deps () { |
| 643 | current_task = "do_" + d.getVar("BB_CURRENTTASK") |
| 644 | if current_task not in ["do_populate_sysroot", "do_package"]: |
| 645 | return |
| 646 | |
| 647 | pn = d.getVar("PN") |
| 648 | if pn.endswith("-native"): |
| 649 | return |
| 650 | |
| 651 | taskdepdata = d.getVar("BB_TASKDEPDATA", False) |
| 652 | deps = {} |
| 653 | for dep in taskdepdata.values(): |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 654 | if dep[1] == "do_populate_sysroot" and not dep[0].endswith(("-native", "-initial")) and "-cross-" not in dep[0] and dep[0] != pn: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 655 | deps[dep[0]] = dep[6] |
| 656 | |
| 657 | d.setVar("HASHEQUIV_EXTRA_SIGDATA", "\n".join("%s: %s" % (k, deps[k]) for k in sorted(deps.keys()))) |
| 658 | } |
| 659 | SSTATECREATEFUNCS += "target_add_sysroot_deps" |
| 660 | |