Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # ex:ts=4:sw=4:sts=4:et |
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 3 | # |
| 4 | # This bbclass is used for creating archive for: |
| 5 | # 1) original (or unpacked) source: ARCHIVER_MODE[src] = "original" |
| 6 | # 2) patched source: ARCHIVER_MODE[src] = "patched" (default) |
| 7 | # 3) configured source: ARCHIVER_MODE[src] = "configured" |
| 8 | # 4) The patches between do_unpack and do_patch: |
| 9 | # ARCHIVER_MODE[diff] = "1" |
| 10 | # And you can set the one that you'd like to exclude from the diff: |
| 11 | # ARCHIVER_MODE[diff-exclude] ?= ".pc autom4te.cache patches" |
| 12 | # 5) The environment data, similar to 'bitbake -e recipe': |
| 13 | # ARCHIVER_MODE[dumpdata] = "1" |
| 14 | # 6) The recipe (.bb and .inc): ARCHIVER_MODE[recipe] = "1" |
| 15 | # 7) Whether output the .src.rpm package: |
| 16 | # ARCHIVER_MODE[srpm] = "1" |
| 17 | # 8) Filter the license, the recipe whose license in |
| 18 | # COPYLEFT_LICENSE_INCLUDE will be included, and in |
| 19 | # COPYLEFT_LICENSE_EXCLUDE will be excluded. |
| 20 | # COPYLEFT_LICENSE_INCLUDE = 'GPL* LGPL*' |
| 21 | # COPYLEFT_LICENSE_EXCLUDE = 'CLOSED Proprietary' |
| 22 | # 9) The recipe type that will be archived: |
| 23 | # COPYLEFT_RECIPE_TYPES = 'target' |
| 24 | # |
| 25 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | # Create archive for all the recipe types |
| 27 | COPYLEFT_RECIPE_TYPES ?= 'target native nativesdk cross crosssdk cross-canadian' |
| 28 | inherit copyleft_filter |
| 29 | |
| 30 | ARCHIVER_MODE[srpm] ?= "0" |
| 31 | ARCHIVER_MODE[src] ?= "patched" |
| 32 | ARCHIVER_MODE[diff] ?= "0" |
| 33 | ARCHIVER_MODE[diff-exclude] ?= ".pc autom4te.cache patches" |
| 34 | ARCHIVER_MODE[dumpdata] ?= "0" |
| 35 | ARCHIVER_MODE[recipe] ?= "0" |
| 36 | |
| 37 | DEPLOY_DIR_SRC ?= "${DEPLOY_DIR}/sources" |
| 38 | ARCHIVER_TOPDIR ?= "${WORKDIR}/deploy-sources" |
| 39 | ARCHIVER_OUTDIR = "${ARCHIVER_TOPDIR}/${TARGET_SYS}/${PF}/" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 40 | ARCHIVER_RPMTOPDIR ?= "${WORKDIR}/deploy-sources-rpm" |
| 41 | ARCHIVER_RPMOUTDIR = "${ARCHIVER_RPMTOPDIR}/${TARGET_SYS}/${PF}/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | ARCHIVER_WORKDIR = "${WORKDIR}/archiver-work/" |
| 43 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 44 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | do_dumpdata[dirs] = "${ARCHIVER_OUTDIR}" |
| 46 | do_ar_recipe[dirs] = "${ARCHIVER_OUTDIR}" |
| 47 | do_ar_original[dirs] = "${ARCHIVER_OUTDIR} ${ARCHIVER_WORKDIR}" |
| 48 | do_deploy_archives[dirs] = "${WORKDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 49 | |
| 50 | # This is a convenience for the shell script to use it |
| 51 | |
| 52 | |
| 53 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 | pn = d.getVar('PN') |
| 55 | assume_provided = (d.getVar("ASSUME_PROVIDED") or "").split() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 56 | if pn in assume_provided: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 57 | for p in d.getVar("PROVIDES").split(): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 58 | if p != pn: |
| 59 | pn = p |
| 60 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | |
| 62 | included, reason = copyleft_should_include(d) |
| 63 | if not included: |
| 64 | bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason)) |
| 65 | return |
| 66 | else: |
| 67 | bb.debug(1, 'archiver: %s is included: %s' % (pn, reason)) |
| 68 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 69 | |
| 70 | # glibc-locale: do_fetch, do_unpack and do_patch tasks have been deleted, |
| 71 | # so avoid archiving source here. |
| 72 | if pn.startswith('glibc-locale'): |
| 73 | return |
| 74 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 75 | # We just archive gcc-source for all the gcc related recipes |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 76 | if d.getVar('BPN') in ['gcc', 'libgcc'] \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 77 | and not pn.startswith('gcc-source'): |
| 78 | bb.debug(1, 'archiver: %s is excluded, covered by gcc-source' % pn) |
| 79 | return |
| 80 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 81 | ar_src = d.getVarFlag('ARCHIVER_MODE', 'src') |
| 82 | ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata') |
| 83 | ar_recipe = d.getVarFlag('ARCHIVER_MODE', 'recipe') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | |
| 85 | if ar_src == "original": |
| 86 | d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_original' % pn) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 87 | # 'patched' and 'configured' invoke do_unpack_and_patch because |
| 88 | # do_ar_patched resp. do_ar_configured depend on it, but for 'original' |
| 89 | # we have to add it explicitly. |
| 90 | if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1': |
| 91 | d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_unpack_and_patch' % pn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | elif ar_src == "patched": |
| 93 | d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_patched' % pn) |
| 94 | elif ar_src == "configured": |
| 95 | # We can't use "addtask do_ar_configured after do_configure" since it |
| 96 | # will cause the deptask of do_populate_sysroot to run not matter what |
| 97 | # archives we need, so we add the depends here. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 98 | |
| 99 | # There is a corner case with "gcc-source-${PV}" recipes, they don't have |
| 100 | # the "do_configure" task, so we need to use "do_preconfigure" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 101 | def hasTask(task): |
| 102 | return bool(d.getVarFlag(task, "task", False)) and not bool(d.getVarFlag(task, "noexec", False)) |
| 103 | |
| 104 | if hasTask("do_preconfigure"): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 105 | d.appendVarFlag('do_ar_configured', 'depends', ' %s:do_preconfigure' % pn) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 106 | elif hasTask("do_configure"): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 107 | d.appendVarFlag('do_ar_configured', 'depends', ' %s:do_configure' % pn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_configured' % pn) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 109 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | elif ar_src: |
| 111 | bb.fatal("Invalid ARCHIVER_MODE[src]: %s" % ar_src) |
| 112 | |
| 113 | if ar_dumpdata == "1": |
| 114 | d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_dumpdata' % pn) |
| 115 | |
| 116 | if ar_recipe == "1": |
| 117 | d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_recipe' % pn) |
| 118 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 119 | # Output the SRPM package |
| 120 | if d.getVarFlag('ARCHIVER_MODE', 'srpm') == "1" and d.getVar('PACKAGES'): |
| 121 | if "package_rpm" in d.getVar('PACKAGE_CLASSES'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_package_write_rpm' % pn) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 123 | d.appendVarFlag('do_package_write_rpm', 'dirs', ' ${ARCHIVER_RPMTOPDIR}') |
| 124 | d.appendVarFlag('do_package_write_rpm', 'sstate-inputdirs', ' ${ARCHIVER_RPMTOPDIR}') |
| 125 | d.appendVarFlag('do_package_write_rpm', 'sstate-outputdirs', ' ${DEPLOY_DIR_SRC}') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | if ar_dumpdata == "1": |
| 127 | d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_dumpdata' % pn) |
| 128 | if ar_recipe == "1": |
| 129 | d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_recipe' % pn) |
| 130 | if ar_src == "original": |
| 131 | d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_original' % pn) |
| 132 | elif ar_src == "patched": |
| 133 | d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_patched' % pn) |
| 134 | elif ar_src == "configured": |
| 135 | d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_configured' % pn) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 136 | else: |
| 137 | bb.fatal("ARCHIVER_MODE[srpm] needs package_rpm in PACKAGE_CLASSES") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | # Take all the sources for a recipe and puts them in WORKDIR/archiver-work/. |
| 141 | # Files in SRC_URI are copied directly, anything that's a directory |
| 142 | # (e.g. git repositories) is "unpacked" and then put into a tarball. |
| 143 | python do_ar_original() { |
| 144 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 145 | import shutil, tempfile |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 146 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 147 | if d.getVarFlag('ARCHIVER_MODE', 'src') != "original": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 148 | return |
| 149 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 150 | ar_outdir = d.getVar('ARCHIVER_OUTDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 151 | bb.note('Archiving the original source...') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 152 | urls = d.getVar("SRC_URI").split() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 153 | # destsuffix (git fetcher) and subdir (everything else) are allowed to be |
| 154 | # absolute paths (for example, destsuffix=${S}/foobar). |
| 155 | # That messes with unpacking inside our tmpdir below, because the fetchers |
| 156 | # will then unpack in that directory and completely ignore the tmpdir. |
| 157 | # That breaks parallel tasks relying on ${S}, like do_compile. |
| 158 | # |
| 159 | # To solve this, we remove these parameters from all URLs. |
| 160 | # We do this even for relative paths because it makes the content of the |
| 161 | # archives more useful (no extra paths that are only used during |
| 162 | # compilation). |
| 163 | for i, url in enumerate(urls): |
| 164 | decoded = bb.fetch2.decodeurl(url) |
| 165 | for param in ('destsuffix', 'subdir'): |
| 166 | if param in decoded[5]: |
| 167 | del decoded[5][param] |
| 168 | encoded = bb.fetch2.encodeurl(decoded) |
| 169 | urls[i] = encoded |
| 170 | fetch = bb.fetch2.Fetch(urls, d) |
| 171 | tarball_suffix = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 172 | for url in fetch.urls: |
| 173 | local = fetch.localpath(url).rstrip("/"); |
| 174 | if os.path.isfile(local): |
| 175 | shutil.copy(local, ar_outdir) |
| 176 | elif os.path.isdir(local): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 177 | tmpdir = tempfile.mkdtemp(dir=d.getVar('ARCHIVER_WORKDIR')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 178 | fetch.unpack(tmpdir, (url,)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 179 | # To handle recipes with more than one source, we add the "name" |
| 180 | # URL parameter as suffix. We treat it as an error when |
| 181 | # there's more than one URL without a name, or a name gets reused. |
| 182 | # This is an additional safety net, in practice the name has |
| 183 | # to be set when using the git fetcher, otherwise SRCREV cannot |
| 184 | # be set separately for each URL. |
| 185 | params = bb.fetch2.decodeurl(url)[5] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 186 | type = bb.fetch2.decodeurl(url)[0] |
| 187 | location = bb.fetch2.decodeurl(url)[2] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 188 | name = params.get('name', '') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 189 | if type.lower() == 'file': |
| 190 | name_tmp = location.rstrip("*").rstrip("/") |
| 191 | name = os.path.basename(name_tmp) |
| 192 | else: |
| 193 | if name in tarball_suffix: |
| 194 | if not name: |
| 195 | bb.fatal("Cannot determine archive names for original source because 'name' URL parameter is unset in more than one URL. Add it to at least one of these: %s %s" % (tarball_suffix[name], url)) |
| 196 | else: |
| 197 | bb.fatal("Cannot determine archive names for original source because 'name=' URL parameter '%s' is used twice. Make it unique in: %s %s" % (tarball_suffix[name], url)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 198 | tarball_suffix[name] = url |
| 199 | create_tarball(d, tmpdir + '/.', name, ar_outdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | |
| 201 | # Emit patch series files for 'original' |
| 202 | bb.note('Writing patch series files...') |
| 203 | for patch in src_patches(d): |
| 204 | _, _, local, _, _, parm = bb.fetch.decodeurl(patch) |
| 205 | patchdir = parm.get('patchdir') |
| 206 | if patchdir: |
| 207 | series = os.path.join(ar_outdir, 'series.subdir.%s' % patchdir.replace('/', '_')) |
| 208 | else: |
| 209 | series = os.path.join(ar_outdir, 'series') |
| 210 | |
| 211 | with open(series, 'a') as s: |
| 212 | s.write('%s -p%s\n' % (os.path.basename(local), parm['striplevel'])) |
| 213 | } |
| 214 | |
| 215 | python do_ar_patched() { |
| 216 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 217 | if d.getVarFlag('ARCHIVER_MODE', 'src') != 'patched': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 | return |
| 219 | |
| 220 | # Get the ARCHIVER_OUTDIR before we reset the WORKDIR |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 221 | ar_outdir = d.getVar('ARCHIVER_OUTDIR') |
| 222 | ar_workdir = d.getVar('ARCHIVER_WORKDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 223 | bb.note('Archiving the patched source...') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 224 | d.setVar('WORKDIR', ar_workdir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 225 | create_tarball(d, d.getVar('S'), 'patched', ar_outdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | python do_ar_configured() { |
| 229 | import shutil |
| 230 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 231 | # Forcibly expand the sysroot paths as we're about to change WORKDIR |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 232 | d.setVar('STAGING_DIR_HOST', d.getVar('STAGING_DIR_HOST')) |
| 233 | d.setVar('STAGING_DIR_TARGET', d.getVar('STAGING_DIR_TARGET')) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 234 | d.setVar('RECIPE_SYSROOT', d.getVar('RECIPE_SYSROOT')) |
| 235 | d.setVar('RECIPE_SYSROOT_NATIVE', d.getVar('RECIPE_SYSROOT_NATIVE')) |
| 236 | |
| 237 | ar_outdir = d.getVar('ARCHIVER_OUTDIR') |
| 238 | if d.getVarFlag('ARCHIVER_MODE', 'src') == 'configured': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | bb.note('Archiving the configured source...') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 240 | pn = d.getVar('PN') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 241 | # "gcc-source-${PV}" recipes don't have "do_configure" |
| 242 | # task, so we need to run "do_preconfigure" instead |
| 243 | if pn.startswith("gcc-source-"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 244 | d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR')) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 245 | bb.build.exec_func('do_preconfigure', d) |
| 246 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 247 | # The libtool-native's do_configure will remove the |
| 248 | # ${STAGING_DATADIR}/aclocal/libtool.m4, so we can't re-run the |
| 249 | # do_configure, we archive the already configured ${S} to |
| 250 | # instead of. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 251 | elif pn != 'libtool-native': |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 252 | def runTask(task): |
| 253 | prefuncs = d.getVarFlag(task, 'prefuncs') or '' |
| 254 | for func in prefuncs.split(): |
| 255 | if func != "sysroot_cleansstate": |
| 256 | bb.build.exec_func(func, d) |
| 257 | bb.build.exec_func(task, d) |
| 258 | postfuncs = d.getVarFlag(task, 'postfuncs') or '' |
| 259 | for func in postfuncs.split(): |
| 260 | if func != 'do_qa_configure': |
| 261 | bb.build.exec_func(func, d) |
| 262 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 263 | # Change the WORKDIR to make do_configure run in another dir. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 264 | d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR')) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 265 | |
| 266 | preceeds = bb.build.preceedtask('do_configure', False, d) |
| 267 | for task in preceeds: |
| 268 | if task != 'do_patch' and task != 'do_prepare_recipe_sysroot': |
| 269 | runTask(task) |
| 270 | runTask('do_configure') |
| 271 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 272 | srcdir = d.getVar('S') |
| 273 | builddir = d.getVar('B') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 274 | if srcdir != builddir: |
| 275 | if os.path.exists(builddir): |
| 276 | oe.path.copytree(builddir, os.path.join(srcdir, \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 277 | 'build.%s.ar_configured' % d.getVar('PF'))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | create_tarball(d, srcdir, 'configured', ar_outdir) |
| 279 | } |
| 280 | |
Brad Bishop | c4ea075 | 2018-11-15 14:30:15 -0800 | [diff] [blame] | 281 | def exclude_useless_paths(tarinfo): |
| 282 | if tarinfo.isdir(): |
| 283 | if tarinfo.name.endswith('/temp') or tarinfo.name.endswith('/patches') or tarinfo.name.endswith('/.pc'): |
| 284 | return None |
| 285 | elif tarinfo.name == 'temp' or tarinfo.name == 'patches' or tarinfo.name == '.pc': |
| 286 | return None |
| 287 | return tarinfo |
| 288 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 289 | def create_tarball(d, srcdir, suffix, ar_outdir): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 290 | """ |
| 291 | create the tarball from srcdir |
| 292 | """ |
| 293 | import tarfile |
| 294 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 295 | # Make sure we are only creating a single tarball for gcc sources |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 296 | if (d.getVar('SRC_URI') == ""): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 297 | return |
| 298 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 299 | # For the kernel archive, srcdir may just be a link to the |
| 300 | # work-shared location. Use os.path.realpath to make sure |
| 301 | # that we archive the actual directory and not just the link. |
| 302 | srcdir = os.path.realpath(srcdir) |
| 303 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 304 | bb.utils.mkdirhier(ar_outdir) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 305 | if suffix: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 306 | filename = '%s-%s.tar.gz' % (d.getVar('PF'), suffix) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 307 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 308 | filename = '%s.tar.gz' % d.getVar('PF') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 309 | tarname = os.path.join(ar_outdir, filename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 310 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 311 | bb.note('Creating %s' % tarname) |
| 312 | tar = tarfile.open(tarname, 'w:gz') |
Brad Bishop | c4ea075 | 2018-11-15 14:30:15 -0800 | [diff] [blame] | 313 | tar.add(srcdir, arcname=os.path.basename(srcdir), filter=exclude_useless_paths) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 314 | tar.close() |
| 315 | |
| 316 | # creating .diff.gz between source.orig and source |
| 317 | def create_diff_gz(d, src_orig, src, ar_outdir): |
| 318 | |
| 319 | import subprocess |
| 320 | |
| 321 | if not os.path.isdir(src) or not os.path.isdir(src_orig): |
| 322 | return |
| 323 | |
| 324 | # The diff --exclude can't exclude the file with path, so we copy |
| 325 | # the patched source, and remove the files that we'd like to |
| 326 | # exclude. |
| 327 | src_patched = src + '.patched' |
| 328 | oe.path.copyhardlinktree(src, src_patched) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 329 | for i in d.getVarFlag('ARCHIVER_MODE', 'diff-exclude').split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 330 | bb.utils.remove(os.path.join(src_orig, i), recurse=True) |
| 331 | bb.utils.remove(os.path.join(src_patched, i), recurse=True) |
| 332 | |
| 333 | dirname = os.path.dirname(src) |
| 334 | basename = os.path.basename(src) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 335 | bb.utils.mkdirhier(ar_outdir) |
| 336 | cwd = os.getcwd() |
| 337 | try: |
| 338 | os.chdir(dirname) |
| 339 | out_file = os.path.join(ar_outdir, '%s-diff.gz' % d.getVar('PF')) |
| 340 | diff_cmd = 'diff -Naur %s.orig %s.patched | gzip -c > %s' % (basename, basename, out_file) |
| 341 | subprocess.check_call(diff_cmd, shell=True) |
| 342 | bb.utils.remove(src_patched, recurse=True) |
| 343 | finally: |
| 344 | os.chdir(cwd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 345 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 346 | def is_work_shared(d): |
| 347 | pn = d.getVar('PN') |
| 348 | return bb.data.inherits_class('kernel', d) or pn.startswith('gcc-source') |
| 349 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 350 | # Run do_unpack and do_patch |
| 351 | python do_unpack_and_patch() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 352 | if d.getVarFlag('ARCHIVER_MODE', 'src') not in \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 353 | [ 'patched', 'configured'] and \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 354 | d.getVarFlag('ARCHIVER_MODE', 'diff') != '1': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 355 | return |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 356 | ar_outdir = d.getVar('ARCHIVER_OUTDIR') |
| 357 | ar_workdir = d.getVar('ARCHIVER_WORKDIR') |
| 358 | ar_sysroot_native = d.getVar('STAGING_DIR_NATIVE') |
| 359 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 360 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 361 | # The kernel class functions require it to be on work-shared, so we dont change WORKDIR |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 362 | if not is_work_shared(d): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 363 | # Change the WORKDIR to make do_unpack do_patch run in another dir. |
| 364 | d.setVar('WORKDIR', ar_workdir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 365 | # Restore the original path to recipe's native sysroot (it's relative to WORKDIR). |
| 366 | d.setVar('STAGING_DIR_NATIVE', ar_sysroot_native) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 367 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 368 | # The changed 'WORKDIR' also caused 'B' changed, create dir 'B' for the |
| 369 | # possibly requiring of the following tasks (such as some recipes's |
| 370 | # do_patch required 'B' existed). |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 371 | bb.utils.mkdirhier(d.getVar('B')) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 372 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 373 | bb.build.exec_func('do_unpack', d) |
| 374 | |
| 375 | # Save the original source for creating the patches |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 376 | if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1': |
| 377 | src = d.getVar('S').rstrip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 378 | src_orig = '%s.orig' % src |
| 379 | oe.path.copytree(src, src_orig) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 380 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 381 | # Make sure gcc and kernel sources are patched only once |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 382 | if not (d.getVar('SRC_URI') == "" or is_work_shared(d)): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 383 | bb.build.exec_func('do_patch', d) |
| 384 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 385 | # Create the patches |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 386 | if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 387 | bb.note('Creating diff gz...') |
| 388 | create_diff_gz(d, src_orig, src, ar_outdir) |
| 389 | bb.utils.remove(src_orig, recurse=True) |
| 390 | } |
| 391 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 392 | # BBINCLUDED is special (excluded from basehash signature |
| 393 | # calculation). Using it in a task signature can cause "basehash |
| 394 | # changed" errors. |
| 395 | # |
| 396 | # Depending on BBINCLUDED also causes do_ar_recipe to run again |
| 397 | # for unrelated changes, like adding or removing buildhistory.bbclass. |
| 398 | # |
| 399 | # For these reasons we ignore the dependency completely. The versioning |
| 400 | # of the output file ensures that we create it each time the recipe |
| 401 | # gets rebuilt, at least as long as a PR server is used. We also rely |
| 402 | # on that mechanism to catch changes in the file content, because the |
| 403 | # file content is not part of of the task signature either. |
| 404 | do_ar_recipe[vardepsexclude] += "BBINCLUDED" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 405 | python do_ar_recipe () { |
| 406 | """ |
| 407 | archive the recipe, including .bb and .inc. |
| 408 | """ |
| 409 | import re |
| 410 | import shutil |
| 411 | |
| 412 | require_re = re.compile( r"require\s+(.+)" ) |
| 413 | include_re = re.compile( r"include\s+(.+)" ) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 414 | bbfile = d.getVar('FILE') |
| 415 | outdir = os.path.join(d.getVar('WORKDIR'), \ |
| 416 | '%s-recipe' % d.getVar('PF')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 417 | bb.utils.mkdirhier(outdir) |
| 418 | shutil.copy(bbfile, outdir) |
| 419 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 420 | pn = d.getVar('PN') |
| 421 | bbappend_files = d.getVar('BBINCLUDED').split() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 422 | # If recipe name is aa, we need to match files like aa.bbappend and aa_1.1.bbappend |
| 423 | # Files like aa1.bbappend or aa1_1.1.bbappend must be excluded. |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 424 | bbappend_re = re.compile( r".*/%s_[^/]*\.bbappend$" % re.escape(pn)) |
| 425 | bbappend_re1 = re.compile( r".*/%s\.bbappend$" % re.escape(pn)) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 426 | for file in bbappend_files: |
| 427 | if bbappend_re.match(file) or bbappend_re1.match(file): |
| 428 | shutil.copy(file, outdir) |
| 429 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 430 | dirname = os.path.dirname(bbfile) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 431 | bbpath = '%s:%s' % (dirname, d.getVar('BBPATH')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 432 | f = open(bbfile, 'r') |
| 433 | for line in f.readlines(): |
| 434 | incfile = None |
| 435 | if require_re.match(line): |
| 436 | incfile = require_re.match(line).group(1) |
| 437 | elif include_re.match(line): |
| 438 | incfile = include_re.match(line).group(1) |
| 439 | if incfile: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 440 | incfile = d.expand(incfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 441 | incfile = bb.utils.which(bbpath, incfile) |
| 442 | if incfile: |
| 443 | shutil.copy(incfile, outdir) |
| 444 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 445 | create_tarball(d, outdir, 'recipe', d.getVar('ARCHIVER_OUTDIR')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 446 | bb.utils.remove(outdir, recurse=True) |
| 447 | } |
| 448 | |
| 449 | python do_dumpdata () { |
| 450 | """ |
| 451 | dump environment data to ${PF}-showdata.dump |
| 452 | """ |
| 453 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 454 | dumpfile = os.path.join(d.getVar('ARCHIVER_OUTDIR'), \ |
| 455 | '%s-showdata.dump' % d.getVar('PF')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 456 | bb.note('Dumping metadata into %s' % dumpfile) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 457 | with open(dumpfile, "w") as f: |
| 458 | # emit variables and shell functions |
| 459 | bb.data.emit_env(f, d, True) |
| 460 | # emit the metadata which isn't valid shell |
| 461 | for e in d.keys(): |
| 462 | if d.getVarFlag(e, "python", False): |
| 463 | f.write("\npython %s () {\n%s}\n" % (e, d.getVar(e, False))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | SSTATETASKS += "do_deploy_archives" |
| 467 | do_deploy_archives () { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 468 | echo "Deploying source archive files from ${ARCHIVER_TOPDIR} to ${DEPLOY_DIR_SRC}." |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 469 | } |
| 470 | python do_deploy_archives_setscene () { |
| 471 | sstate_setscene(d) |
| 472 | } |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 473 | do_deploy_archives[dirs] = "${ARCHIVER_TOPDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 474 | do_deploy_archives[sstate-inputdirs] = "${ARCHIVER_TOPDIR}" |
| 475 | do_deploy_archives[sstate-outputdirs] = "${DEPLOY_DIR_SRC}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 476 | addtask do_deploy_archives_setscene |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 477 | |
| 478 | addtask do_ar_original after do_unpack |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 479 | addtask do_unpack_and_patch after do_patch |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 480 | addtask do_ar_patched after do_unpack_and_patch |
| 481 | addtask do_ar_configured after do_unpack_and_patch |
| 482 | addtask do_dumpdata |
| 483 | addtask do_ar_recipe |
| 484 | addtask do_deploy_archives before do_build |
| 485 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 486 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 487 | # Add tasks in the correct order, specifically for linux-yocto to avoid race condition. |
| 488 | # sstatesig.py:sstate_rundepfilter has special support that excludes this dependency |
| 489 | # so that do_kernel_configme does not need to run again when do_unpack_and_patch |
| 490 | # gets added or removed (by adding or removing archiver.bbclass). |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 491 | if bb.data.inherits_class('kernel-yocto', d): |
| 492 | bb.build.addtask('do_kernel_configme', 'do_configure', 'do_unpack_and_patch', d) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 493 | } |