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