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) source mirror: ARCHIVE_MODE[src] = "mirror" 9# 5) The patches between do_unpack and do_patch: 10# ARCHIVER_MODE[diff] = "1" 11# And you can set the one that you'd like to exclude from the diff: 12# ARCHIVER_MODE[diff-exclude] ?= ".pc autom4te.cache patches" 13# 6) The environment data, similar to 'bitbake -e recipe': 14# ARCHIVER_MODE[dumpdata] = "1" 15# 7) The recipe (.bb and .inc): ARCHIVER_MODE[recipe] = "1" 16# 8) Whether output the .src.rpm package: 17# ARCHIVER_MODE[srpm] = "1" 18# 9) Filter the license, the recipe whose license in 19# COPYLEFT_LICENSE_INCLUDE will be included, and in 20# COPYLEFT_LICENSE_EXCLUDE will be excluded. 21# COPYLEFT_LICENSE_INCLUDE = 'GPL* LGPL*' 22# COPYLEFT_LICENSE_EXCLUDE = 'CLOSED Proprietary' 23# 10) The recipe type that will be archived: 24# COPYLEFT_RECIPE_TYPES = 'target' 25# 11) The source mirror mode: 26# ARCHIVER_MODE[mirror] = "split" (default): Sources are split into 27# per-recipe directories in a similar way to other archiver modes. 28# Post-processing may be required to produce a single mirror directory. 29# This does however allow inspection of duplicate sources and more 30# intelligent handling. 31# ARCHIVER_MODE[mirror] = "combined": All sources are placed into a single 32# directory suitable for direct use as a mirror. Duplicate sources are 33# ignored. 34# 12) Source mirror exclusions: 35# ARCHIVER_MIRROR_EXCLUDE is a list of prefixes to exclude from the mirror. 36# This may be used for sources which you are already publishing yourself 37# (e.g. if the URI starts with 'https://mysite.com/' and your mirror is 38# going to be published to the same site). It may also be used to exclude 39# local files (with the prefix 'file://') if these will be provided as part 40# of an archive of the layers themselves. 41# 42 43# Create archive for all the recipe types 44COPYLEFT_RECIPE_TYPES ?= 'target native nativesdk cross crosssdk cross-canadian' 45inherit copyleft_filter 46 47ARCHIVER_MODE[srpm] ?= "0" 48ARCHIVER_MODE[src] ?= "patched" 49ARCHIVER_MODE[diff] ?= "0" 50ARCHIVER_MODE[diff-exclude] ?= ".pc autom4te.cache patches" 51ARCHIVER_MODE[dumpdata] ?= "0" 52ARCHIVER_MODE[recipe] ?= "0" 53ARCHIVER_MODE[mirror] ?= "split" 54 55DEPLOY_DIR_SRC ?= "${DEPLOY_DIR}/sources" 56ARCHIVER_TOPDIR ?= "${WORKDIR}/archiver-sources" 57ARCHIVER_OUTDIR = "${ARCHIVER_TOPDIR}/${TARGET_SYS}/${PF}/" 58ARCHIVER_RPMTOPDIR ?= "${WORKDIR}/deploy-sources-rpm" 59ARCHIVER_RPMOUTDIR = "${ARCHIVER_RPMTOPDIR}/${TARGET_SYS}/${PF}/" 60ARCHIVER_WORKDIR = "${WORKDIR}/archiver-work/" 61 62# When producing a combined mirror directory, allow duplicates for the case 63# where multiple recipes use the same SRC_URI. 64ARCHIVER_COMBINED_MIRRORDIR = "${ARCHIVER_TOPDIR}/mirror" 65SSTATE_DUPWHITELIST += "${DEPLOY_DIR_SRC}/mirror" 66 67do_dumpdata[dirs] = "${ARCHIVER_OUTDIR}" 68do_ar_recipe[dirs] = "${ARCHIVER_OUTDIR}" 69do_ar_original[dirs] = "${ARCHIVER_OUTDIR} ${ARCHIVER_WORKDIR}" 70do_deploy_archives[dirs] = "${WORKDIR}" 71 72# This is a convenience for the shell script to use it 73 74 75python () { 76 pn = d.getVar('PN') 77 assume_provided = (d.getVar("ASSUME_PROVIDED") or "").split() 78 if pn in assume_provided: 79 for p in d.getVar("PROVIDES").split(): 80 if p != pn: 81 pn = p 82 break 83 84 included, reason = copyleft_should_include(d) 85 if not included: 86 bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason)) 87 return 88 else: 89 bb.debug(1, 'archiver: %s is included: %s' % (pn, reason)) 90 91 92 # glibc-locale: do_fetch, do_unpack and do_patch tasks have been deleted, 93 # so avoid archiving source here. 94 if pn.startswith('glibc-locale'): 95 return 96 97 # We just archive gcc-source for all the gcc related recipes 98 if d.getVar('BPN') in ['gcc', 'libgcc'] \ 99 and not pn.startswith('gcc-source'): 100 bb.debug(1, 'archiver: %s is excluded, covered by gcc-source' % pn) 101 return 102 103 def hasTask(task): 104 return bool(d.getVarFlag(task, "task", False)) and not bool(d.getVarFlag(task, "noexec", False)) 105 106 ar_src = d.getVarFlag('ARCHIVER_MODE', 'src') 107 ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata') 108 ar_recipe = d.getVarFlag('ARCHIVER_MODE', 'recipe') 109 110 if ar_src == "original": 111 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_original' % pn) 112 # 'patched' and 'configured' invoke do_unpack_and_patch because 113 # do_ar_patched resp. do_ar_configured depend on it, but for 'original' 114 # we have to add it explicitly. 115 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1': 116 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_unpack_and_patch' % pn) 117 elif ar_src == "patched": 118 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_patched' % pn) 119 elif ar_src == "configured": 120 # We can't use "addtask do_ar_configured after do_configure" since it 121 # will cause the deptask of do_populate_sysroot to run no matter what 122 # archives we need, so we add the depends here. 123 124 # There is a corner case with "gcc-source-${PV}" recipes, they don't have 125 # the "do_configure" task, so we need to use "do_preconfigure" 126 if hasTask("do_preconfigure"): 127 d.appendVarFlag('do_ar_configured', 'depends', ' %s:do_preconfigure' % pn) 128 elif hasTask("do_configure"): 129 d.appendVarFlag('do_ar_configured', 'depends', ' %s:do_configure' % pn) 130 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_configured' % pn) 131 elif ar_src == "mirror": 132 d.appendVarFlag('do_deploy_archives', 'depends', '%s:do_ar_mirror' % pn) 133 134 elif ar_src: 135 bb.fatal("Invalid ARCHIVER_MODE[src]: %s" % ar_src) 136 137 if ar_dumpdata == "1": 138 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_dumpdata' % pn) 139 140 if ar_recipe == "1": 141 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_recipe' % pn) 142 143 # Output the SRPM package 144 if d.getVarFlag('ARCHIVER_MODE', 'srpm') == "1" and d.getVar('PACKAGES'): 145 if "package_rpm" not in d.getVar('PACKAGE_CLASSES'): 146 bb.fatal("ARCHIVER_MODE[srpm] needs package_rpm in PACKAGE_CLASSES") 147 148 # Some recipes do not have any packaging tasks 149 if hasTask("do_package_write_rpm"): 150 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_package_write_rpm' % pn) 151 d.appendVarFlag('do_package_write_rpm', 'dirs', ' ${ARCHIVER_RPMTOPDIR}') 152 d.appendVarFlag('do_package_write_rpm', 'sstate-inputdirs', ' ${ARCHIVER_RPMTOPDIR}') 153 d.appendVarFlag('do_package_write_rpm', 'sstate-outputdirs', ' ${DEPLOY_DIR_SRC}') 154 if ar_dumpdata == "1": 155 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_dumpdata' % pn) 156 if ar_recipe == "1": 157 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_recipe' % pn) 158 if ar_src == "original": 159 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_original' % pn) 160 elif ar_src == "patched": 161 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_patched' % pn) 162 elif ar_src == "configured": 163 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_configured' % pn) 164} 165 166# Take all the sources for a recipe and put them in WORKDIR/archiver-work/. 167# Files in SRC_URI are copied directly, anything that's a directory 168# (e.g. git repositories) is "unpacked" and then put into a tarball. 169python do_ar_original() { 170 171 import shutil, tempfile 172 173 if d.getVarFlag('ARCHIVER_MODE', 'src') != "original": 174 return 175 176 ar_outdir = d.getVar('ARCHIVER_OUTDIR') 177 bb.note('Archiving the original source...') 178 urls = d.getVar("SRC_URI").split() 179 # destsuffix (git fetcher) and subdir (everything else) are allowed to be 180 # absolute paths (for example, destsuffix=${S}/foobar). 181 # That messes with unpacking inside our tmpdir below, because the fetchers 182 # will then unpack in that directory and completely ignore the tmpdir. 183 # That breaks parallel tasks relying on ${S}, like do_compile. 184 # 185 # To solve this, we remove these parameters from all URLs. 186 # We do this even for relative paths because it makes the content of the 187 # archives more useful (no extra paths that are only used during 188 # compilation). 189 for i, url in enumerate(urls): 190 decoded = bb.fetch2.decodeurl(url) 191 for param in ('destsuffix', 'subdir'): 192 if param in decoded[5]: 193 del decoded[5][param] 194 encoded = bb.fetch2.encodeurl(decoded) 195 urls[i] = encoded 196 197 # Cleanup SRC_URI before call bb.fetch2.Fetch() since now SRC_URI is in the 198 # variable "urls", otherwise there might be errors like: 199 # The SRCREV_FORMAT variable must be set when multiple SCMs are used 200 ld = bb.data.createCopy(d) 201 ld.setVar('SRC_URI', '') 202 fetch = bb.fetch2.Fetch(urls, ld) 203 tarball_suffix = {} 204 for url in fetch.urls: 205 local = fetch.localpath(url).rstrip("/"); 206 if os.path.isfile(local): 207 shutil.copy(local, ar_outdir) 208 elif os.path.isdir(local): 209 tmpdir = tempfile.mkdtemp(dir=d.getVar('ARCHIVER_WORKDIR')) 210 fetch.unpack(tmpdir, (url,)) 211 # To handle recipes with more than one source, we add the "name" 212 # URL parameter as suffix. We treat it as an error when 213 # there's more than one URL without a name, or a name gets reused. 214 # This is an additional safety net, in practice the name has 215 # to be set when using the git fetcher, otherwise SRCREV cannot 216 # be set separately for each URL. 217 params = bb.fetch2.decodeurl(url)[5] 218 type = bb.fetch2.decodeurl(url)[0] 219 location = bb.fetch2.decodeurl(url)[2] 220 name = params.get('name', '') 221 if type.lower() == 'file': 222 name_tmp = location.rstrip("*").rstrip("/") 223 name = os.path.basename(name_tmp) 224 else: 225 if name in tarball_suffix: 226 if not name: 227 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)) 228 else: 229 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)) 230 tarball_suffix[name] = url 231 create_tarball(d, tmpdir + '/.', name, ar_outdir) 232 233 # Emit patch series files for 'original' 234 bb.note('Writing patch series files...') 235 for patch in src_patches(d): 236 _, _, local, _, _, parm = bb.fetch.decodeurl(patch) 237 patchdir = parm.get('patchdir') 238 if patchdir: 239 series = os.path.join(ar_outdir, 'series.subdir.%s' % patchdir.replace('/', '_')) 240 else: 241 series = os.path.join(ar_outdir, 'series') 242 243 with open(series, 'a') as s: 244 s.write('%s -p%s\n' % (os.path.basename(local), parm['striplevel'])) 245} 246 247python do_ar_patched() { 248 249 if d.getVarFlag('ARCHIVER_MODE', 'src') != 'patched': 250 return 251 252 # Get the ARCHIVER_OUTDIR before we reset the WORKDIR 253 ar_outdir = d.getVar('ARCHIVER_OUTDIR') 254 if not is_work_shared(d): 255 ar_workdir = d.getVar('ARCHIVER_WORKDIR') 256 d.setVar('WORKDIR', ar_workdir) 257 bb.note('Archiving the patched source...') 258 create_tarball(d, d.getVar('S'), 'patched', ar_outdir) 259} 260 261python do_ar_configured() { 262 import shutil 263 264 # Forcibly expand the sysroot paths as we're about to change WORKDIR 265 d.setVar('STAGING_DIR_HOST', d.getVar('STAGING_DIR_HOST')) 266 d.setVar('STAGING_DIR_TARGET', d.getVar('STAGING_DIR_TARGET')) 267 d.setVar('RECIPE_SYSROOT', d.getVar('RECIPE_SYSROOT')) 268 d.setVar('RECIPE_SYSROOT_NATIVE', d.getVar('RECIPE_SYSROOT_NATIVE')) 269 270 ar_outdir = d.getVar('ARCHIVER_OUTDIR') 271 if d.getVarFlag('ARCHIVER_MODE', 'src') == 'configured': 272 bb.note('Archiving the configured source...') 273 pn = d.getVar('PN') 274 # "gcc-source-${PV}" recipes don't have "do_configure" 275 # task, so we need to run "do_preconfigure" instead 276 if pn.startswith("gcc-source-"): 277 d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR')) 278 bb.build.exec_func('do_preconfigure', d) 279 280 # The libtool-native's do_configure will remove the 281 # ${STAGING_DATADIR}/aclocal/libtool.m4, so we can't re-run the 282 # do_configure, we archive the already configured ${S} to 283 # instead of. 284 # The kernel class functions require it to be on work-shared, we 285 # don't unpack, patch, configure again, just archive the already 286 # configured ${S} 287 elif not (pn == 'libtool-native' or is_work_shared(d)): 288 def runTask(task): 289 prefuncs = d.getVarFlag(task, 'prefuncs') or '' 290 for func in prefuncs.split(): 291 if func != "sysroot_cleansstate": 292 bb.build.exec_func(func, d) 293 bb.build.exec_func(task, d) 294 postfuncs = d.getVarFlag(task, 'postfuncs') or '' 295 for func in postfuncs.split(): 296 if func != 'do_qa_configure': 297 bb.build.exec_func(func, d) 298 299 # Change the WORKDIR to make do_configure run in another dir. 300 d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR')) 301 302 preceeds = bb.build.preceedtask('do_configure', False, d) 303 for task in preceeds: 304 if task != 'do_patch' and task != 'do_prepare_recipe_sysroot': 305 runTask(task) 306 runTask('do_configure') 307 308 srcdir = d.getVar('S') 309 builddir = d.getVar('B') 310 if srcdir != builddir: 311 if os.path.exists(builddir): 312 oe.path.copytree(builddir, os.path.join(srcdir, \ 313 'build.%s.ar_configured' % d.getVar('PF'))) 314 create_tarball(d, srcdir, 'configured', ar_outdir) 315} 316 317python do_ar_mirror() { 318 import subprocess 319 320 src_uri = (d.getVar('SRC_URI') or '').split() 321 if len(src_uri) == 0: 322 return 323 324 dl_dir = d.getVar('DL_DIR') 325 mirror_exclusions = (d.getVar('ARCHIVER_MIRROR_EXCLUDE') or '').split() 326 mirror_mode = d.getVarFlag('ARCHIVER_MODE', 'mirror') 327 have_mirror_tarballs = d.getVar('BB_GENERATE_MIRROR_TARBALLS') 328 329 if mirror_mode == 'combined': 330 destdir = d.getVar('ARCHIVER_COMBINED_MIRRORDIR') 331 elif mirror_mode == 'split': 332 destdir = d.getVar('ARCHIVER_OUTDIR') 333 else: 334 bb.fatal('Invalid ARCHIVER_MODE[mirror]: %s' % (mirror_mode)) 335 336 if not have_mirror_tarballs: 337 bb.fatal('Using `ARCHIVER_MODE[src] = "mirror"` depends on setting `BB_GENERATE_MIRROR_TARBALLS = "1"`') 338 339 def is_excluded(url): 340 for prefix in mirror_exclusions: 341 if url.startswith(prefix): 342 return True 343 return False 344 345 bb.note('Archiving the source as a mirror...') 346 347 bb.utils.mkdirhier(destdir) 348 349 fetcher = bb.fetch2.Fetch(src_uri, d) 350 351 for ud in fetcher.expanded_urldata(): 352 if is_excluded(ud.url): 353 bb.note('Skipping excluded url: %s' % (ud.url)) 354 continue 355 356 bb.note('Archiving url: %s' % (ud.url)) 357 ud.setup_localpath(d) 358 localpath = None 359 360 # Check for mirror tarballs first. We will archive the first mirror 361 # tarball that we find as it's assumed that we just need one. 362 for mirror_fname in ud.mirrortarballs: 363 mirror_path = os.path.join(dl_dir, mirror_fname) 364 if os.path.exists(mirror_path): 365 bb.note('Found mirror tarball: %s' % (mirror_path)) 366 localpath = mirror_path 367 break 368 369 if len(ud.mirrortarballs) and not localpath: 370 bb.warn('Mirror tarballs are listed for a source but none are present. ' \ 371 'Falling back to original download.\n' \ 372 'SRC_URI = %s' % (ud.url)) 373 374 # Check original download 375 if not localpath: 376 bb.note('Using original download: %s' % (ud.localpath)) 377 localpath = ud.localpath 378 379 if not localpath or not os.path.exists(localpath): 380 bb.fatal('Original download is missing for a source.\n' \ 381 'SRC_URI = %s' % (ud.url)) 382 383 # We now have an appropriate localpath 384 bb.note('Copying source mirror') 385 cmd = 'cp -fpPRH %s %s' % (localpath, destdir) 386 subprocess.check_call(cmd, shell=True) 387} 388 389def exclude_useless_paths(tarinfo): 390 if tarinfo.isdir(): 391 if tarinfo.name.endswith('/temp') or tarinfo.name.endswith('/patches') or tarinfo.name.endswith('/.pc'): 392 return None 393 elif tarinfo.name == 'temp' or tarinfo.name == 'patches' or tarinfo.name == '.pc': 394 return None 395 return tarinfo 396 397def create_tarball(d, srcdir, suffix, ar_outdir): 398 """ 399 create the tarball from srcdir 400 """ 401 import tarfile 402 403 # Make sure we are only creating a single tarball for gcc sources 404 if (d.getVar('SRC_URI') == ""): 405 return 406 407 # For the kernel archive, srcdir may just be a link to the 408 # work-shared location. Use os.path.realpath to make sure 409 # that we archive the actual directory and not just the link. 410 srcdir = os.path.realpath(srcdir) 411 412 bb.utils.mkdirhier(ar_outdir) 413 if suffix: 414 filename = '%s-%s.tar.gz' % (d.getVar('PF'), suffix) 415 else: 416 filename = '%s.tar.gz' % d.getVar('PF') 417 tarname = os.path.join(ar_outdir, filename) 418 419 bb.note('Creating %s' % tarname) 420 tar = tarfile.open(tarname, 'w:gz') 421 tar.add(srcdir, arcname=os.path.basename(srcdir), filter=exclude_useless_paths) 422 tar.close() 423 424# creating .diff.gz between source.orig and source 425def create_diff_gz(d, src_orig, src, ar_outdir): 426 427 import subprocess 428 429 if not os.path.isdir(src) or not os.path.isdir(src_orig): 430 return 431 432 # The diff --exclude can't exclude the file with path, so we copy 433 # the patched source, and remove the files that we'd like to 434 # exclude. 435 src_patched = src + '.patched' 436 oe.path.copyhardlinktree(src, src_patched) 437 for i in d.getVarFlag('ARCHIVER_MODE', 'diff-exclude').split(): 438 bb.utils.remove(os.path.join(src_orig, i), recurse=True) 439 bb.utils.remove(os.path.join(src_patched, i), recurse=True) 440 441 dirname = os.path.dirname(src) 442 basename = os.path.basename(src) 443 bb.utils.mkdirhier(ar_outdir) 444 cwd = os.getcwd() 445 try: 446 os.chdir(dirname) 447 out_file = os.path.join(ar_outdir, '%s-diff.gz' % d.getVar('PF')) 448 diff_cmd = 'diff -Naur %s.orig %s.patched | gzip -c > %s' % (basename, basename, out_file) 449 subprocess.check_call(diff_cmd, shell=True) 450 bb.utils.remove(src_patched, recurse=True) 451 finally: 452 os.chdir(cwd) 453 454def is_work_shared(d): 455 pn = d.getVar('PN') 456 return bb.data.inherits_class('kernel', d) or pn.startswith('gcc-source') 457 458# Run do_unpack and do_patch 459python do_unpack_and_patch() { 460 if d.getVarFlag('ARCHIVER_MODE', 'src') not in \ 461 [ 'patched', 'configured'] and \ 462 d.getVarFlag('ARCHIVER_MODE', 'diff') != '1': 463 return 464 ar_outdir = d.getVar('ARCHIVER_OUTDIR') 465 ar_workdir = d.getVar('ARCHIVER_WORKDIR') 466 ar_sysroot_native = d.getVar('STAGING_DIR_NATIVE') 467 pn = d.getVar('PN') 468 469 # The kernel class functions require it to be on work-shared, so we don't change WORKDIR 470 if not is_work_shared(d): 471 # Change the WORKDIR to make do_unpack do_patch run in another dir. 472 d.setVar('WORKDIR', ar_workdir) 473 # Restore the original path to recipe's native sysroot (it's relative to WORKDIR). 474 d.setVar('STAGING_DIR_NATIVE', ar_sysroot_native) 475 476 # The changed 'WORKDIR' also caused 'B' changed, create dir 'B' for the 477 # possibly requiring of the following tasks (such as some recipes's 478 # do_patch required 'B' existed). 479 bb.utils.mkdirhier(d.getVar('B')) 480 481 bb.build.exec_func('do_unpack', d) 482 483 # Save the original source for creating the patches 484 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1': 485 src = d.getVar('S').rstrip('/') 486 src_orig = '%s.orig' % src 487 oe.path.copytree(src, src_orig) 488 489 if bb.data.inherits_class('dos2unix', d): 490 bb.build.exec_func('do_convert_crlf_to_lf', d) 491 492 # Make sure gcc and kernel sources are patched only once 493 if not (d.getVar('SRC_URI') == "" or is_work_shared(d)): 494 bb.build.exec_func('do_patch', d) 495 496 # Create the patches 497 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1': 498 bb.note('Creating diff gz...') 499 create_diff_gz(d, src_orig, src, ar_outdir) 500 bb.utils.remove(src_orig, recurse=True) 501} 502 503# BBINCLUDED is special (excluded from basehash signature 504# calculation). Using it in a task signature can cause "basehash 505# changed" errors. 506# 507# Depending on BBINCLUDED also causes do_ar_recipe to run again 508# for unrelated changes, like adding or removing buildhistory.bbclass. 509# 510# For these reasons we ignore the dependency completely. The versioning 511# of the output file ensures that we create it each time the recipe 512# gets rebuilt, at least as long as a PR server is used. We also rely 513# on that mechanism to catch changes in the file content, because the 514# file content is not part of the task signature either. 515do_ar_recipe[vardepsexclude] += "BBINCLUDED" 516python do_ar_recipe () { 517 """ 518 archive the recipe, including .bb and .inc. 519 """ 520 import re 521 import shutil 522 523 require_re = re.compile( r"require\s+(.+)" ) 524 include_re = re.compile( r"include\s+(.+)" ) 525 bbfile = d.getVar('FILE') 526 outdir = os.path.join(d.getVar('WORKDIR'), \ 527 '%s-recipe' % d.getVar('PF')) 528 bb.utils.mkdirhier(outdir) 529 shutil.copy(bbfile, outdir) 530 531 pn = d.getVar('PN') 532 bbappend_files = d.getVar('BBINCLUDED').split() 533 # If recipe name is aa, we need to match files like aa.bbappend and aa_1.1.bbappend 534 # Files like aa1.bbappend or aa1_1.1.bbappend must be excluded. 535 bbappend_re = re.compile( r".*/%s_[^/]*\.bbappend$" % re.escape(pn)) 536 bbappend_re1 = re.compile( r".*/%s\.bbappend$" % re.escape(pn)) 537 for file in bbappend_files: 538 if bbappend_re.match(file) or bbappend_re1.match(file): 539 shutil.copy(file, outdir) 540 541 dirname = os.path.dirname(bbfile) 542 bbpath = '%s:%s' % (dirname, d.getVar('BBPATH')) 543 f = open(bbfile, 'r') 544 for line in f.readlines(): 545 incfile = None 546 if require_re.match(line): 547 incfile = require_re.match(line).group(1) 548 elif include_re.match(line): 549 incfile = include_re.match(line).group(1) 550 if incfile: 551 incfile = d.expand(incfile) 552 if incfile: 553 incfile = bb.utils.which(bbpath, incfile) 554 if incfile: 555 shutil.copy(incfile, outdir) 556 557 create_tarball(d, outdir, 'recipe', d.getVar('ARCHIVER_OUTDIR')) 558 bb.utils.remove(outdir, recurse=True) 559} 560 561python do_dumpdata () { 562 """ 563 dump environment data to ${PF}-showdata.dump 564 """ 565 566 dumpfile = os.path.join(d.getVar('ARCHIVER_OUTDIR'), \ 567 '%s-showdata.dump' % d.getVar('PF')) 568 bb.note('Dumping metadata into %s' % dumpfile) 569 with open(dumpfile, "w") as f: 570 # emit variables and shell functions 571 bb.data.emit_env(f, d, True) 572 # emit the metadata which isn't valid shell 573 for e in d.keys(): 574 if d.getVarFlag(e, "python", False): 575 f.write("\npython %s () {\n%s}\n" % (e, d.getVar(e, False))) 576} 577 578SSTATETASKS += "do_deploy_archives" 579do_deploy_archives () { 580 echo "Deploying source archive files from ${ARCHIVER_TOPDIR} to ${DEPLOY_DIR_SRC}." 581} 582python do_deploy_archives_setscene () { 583 sstate_setscene(d) 584} 585do_deploy_archives[dirs] = "${ARCHIVER_TOPDIR}" 586do_deploy_archives[sstate-inputdirs] = "${ARCHIVER_TOPDIR}" 587do_deploy_archives[sstate-outputdirs] = "${DEPLOY_DIR_SRC}" 588addtask do_deploy_archives_setscene 589 590addtask do_ar_original after do_unpack 591addtask do_unpack_and_patch after do_patch do_preconfigure 592addtask do_ar_patched after do_unpack_and_patch 593addtask do_ar_configured after do_unpack_and_patch 594addtask do_ar_mirror after do_fetch 595addtask do_dumpdata 596addtask do_ar_recipe 597addtask do_deploy_archives 598do_build[recrdeptask] += "do_deploy_archives" 599do_rootfs[recrdeptask] += "do_deploy_archives" 600do_populate_sdk[recrdeptask] += "do_deploy_archives" 601 602python () { 603 # Add tasks in the correct order, specifically for linux-yocto to avoid race condition. 604 # sstatesig.py:sstate_rundepfilter has special support that excludes this dependency 605 # so that do_kernel_configme does not need to run again when do_unpack_and_patch 606 # gets added or removed (by adding or removing archiver.bbclass). 607 if bb.data.inherits_class('kernel-yocto', d): 608 bb.build.addtask('do_kernel_configme', 'do_configure', 'do_unpack_and_patch', d) 609} 610