diff options
Diffstat (limited to 'meta/classes/archiver.bbclass')
| -rw-r--r-- | meta/classes/archiver.bbclass | 291 |
1 files changed, 169 insertions, 122 deletions
diff --git a/meta/classes/archiver.bbclass b/meta/classes/archiver.bbclass index b598aa3ad6..2c04557f79 100644 --- a/meta/classes/archiver.bbclass +++ b/meta/classes/archiver.bbclass @@ -45,25 +45,37 @@ ARCHIVER_WORKDIR = "${WORKDIR}/archiver-work/" do_dumpdata[dirs] = "${ARCHIVER_OUTDIR}" do_ar_recipe[dirs] = "${ARCHIVER_OUTDIR}" do_ar_original[dirs] = "${ARCHIVER_OUTDIR} ${ARCHIVER_WORKDIR}" +do_deploy_archives[dirs] = "${WORKDIR}" +do_deploy_all_archives[dirs] = "${WORKDIR}" # This is a convenience for the shell script to use it python () { - pn = d.getVar('PN', True) - - if d.getVar('COPYLEFT_LICENSE_INCLUDE', True) or \ - d.getVar('COPYLEFT_LICENSE_EXCLUDE', True): - included, reason = copyleft_should_include(d) - if not included: - bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason)) - return - else: - bb.debug(1, 'archiver: %s is included: %s' % (pn, reason)) + pn = d.getVar('PN') + assume_provided = (d.getVar("ASSUME_PROVIDED") or "").split() + if pn in assume_provided: + for p in d.getVar("PROVIDES").split(): + if p != pn: + pn = p + break + + included, reason = copyleft_should_include(d) + if not included: + bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason)) + return + else: + bb.debug(1, 'archiver: %s is included: %s' % (pn, reason)) + + # We just archive gcc-source for all the gcc related recipes + if d.getVar('BPN') in ['gcc', 'libgcc'] \ + and not pn.startswith('gcc-source'): + bb.debug(1, 'archiver: %s is excluded, covered by gcc-source' % pn) + return - ar_src = d.getVarFlag('ARCHIVER_MODE', 'src', True) - ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata', True) - ar_recipe = d.getVarFlag('ARCHIVER_MODE', 'recipe', True) + ar_src = d.getVarFlag('ARCHIVER_MODE', 'src') + ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata') + ar_recipe = d.getVarFlag('ARCHIVER_MODE', 'recipe') if ar_src == "original": d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_original' % pn) @@ -73,8 +85,15 @@ python () { # We can't use "addtask do_ar_configured after do_configure" since it # will cause the deptask of do_populate_sysroot to run not matter what # archives we need, so we add the depends here. - d.appendVarFlag('do_ar_configured', 'depends', ' %s:do_configure' % pn) + + # There is a corner case with "gcc-source-${PV}" recipes, they don't have + # the "do_configure" task, so we need to use "do_preconfigure" + if pn.startswith("gcc-source-"): + d.appendVarFlag('do_ar_configured', 'depends', ' %s:do_preconfigure' % pn) + else: + d.appendVarFlag('do_ar_configured', 'depends', ' %s:do_configure' % pn) d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_configured' % pn) + elif ar_src: bb.fatal("Invalid ARCHIVER_MODE[src]: %s" % ar_src) @@ -85,9 +104,9 @@ python () { d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_recipe' % pn) # Output the srpm package - ar_srpm = d.getVarFlag('ARCHIVER_MODE', 'srpm', True) + ar_srpm = d.getVarFlag('ARCHIVER_MODE', 'srpm') if ar_srpm == "1": - if d.getVar('PACKAGES', True) != '' and d.getVar('IMAGE_PKGTYPE', True) == 'rpm': + if d.getVar('PACKAGES') != '' and d.getVar('IMAGE_PKGTYPE') == 'rpm': d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_package_write_rpm' % pn) if ar_dumpdata == "1": d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_dumpdata' % pn) @@ -99,27 +118,6 @@ python () { d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_patched' % pn) elif ar_src == "configured": d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_configured' % pn) - - # The gcc staff uses shared source - flag = d.getVarFlag("do_unpack", "stamp-base", True) - if flag: - if ar_src in [ 'original', 'patched' ]: - ar_outdir = os.path.join(d.getVar('ARCHIVER_TOPDIR', True), 'work-shared') - d.setVar('ARCHIVER_OUTDIR', ar_outdir) - d.setVarFlag('do_ar_original', 'stamp-base', flag) - d.setVarFlag('do_ar_patched', 'stamp-base', flag) - d.setVarFlag('do_unpack_and_patch', 'stamp-base', flag) - d.setVarFlag('do_ar_original', 'vardepsexclude', 'PN PF ARCHIVER_OUTDIR WORKDIR') - d.setVarFlag('do_unpack_and_patch', 'vardepsexclude', 'PN PF ARCHIVER_OUTDIR WORKDIR') - d.setVarFlag('do_ar_patched', 'vardepsexclude', 'PN PF ARCHIVER_OUTDIR WORKDIR') - d.setVarFlag('create_diff_gz', 'vardepsexclude', 'PF') - d.setVarFlag('create_tarball', 'vardepsexclude', 'PF') - - flag_clean = d.getVarFlag('do_unpack', 'stamp-base-clean', True) - if flag_clean: - d.setVarFlag('do_ar_original', 'stamp-base-clean', flag_clean) - d.setVarFlag('do_ar_patched', 'stamp-base-clean', flag_clean) - d.setVarFlag('do_unpack_and_patch', 'stamp-base-clean', flag_clean) } # Take all the sources for a recipe and puts them in WORKDIR/archiver-work/. @@ -127,34 +125,55 @@ python () { # (e.g. git repositories) is "unpacked" and then put into a tarball. python do_ar_original() { - import shutil, tarfile, tempfile + import shutil, tempfile - if d.getVarFlag('ARCHIVER_MODE', 'src', True) != "original": + if d.getVarFlag('ARCHIVER_MODE', 'src') != "original": return - ar_outdir = d.getVar('ARCHIVER_OUTDIR', True) + ar_outdir = d.getVar('ARCHIVER_OUTDIR') bb.note('Archiving the original source...') - fetch = bb.fetch2.Fetch([], d) + urls = d.getVar("SRC_URI").split() + # destsuffix (git fetcher) and subdir (everything else) are allowed to be + # absolute paths (for example, destsuffix=${S}/foobar). + # That messes with unpacking inside our tmpdir below, because the fetchers + # will then unpack in that directory and completely ignore the tmpdir. + # That breaks parallel tasks relying on ${S}, like do_compile. + # + # To solve this, we remove these parameters from all URLs. + # We do this even for relative paths because it makes the content of the + # archives more useful (no extra paths that are only used during + # compilation). + for i, url in enumerate(urls): + decoded = bb.fetch2.decodeurl(url) + for param in ('destsuffix', 'subdir'): + if param in decoded[5]: + del decoded[5][param] + encoded = bb.fetch2.encodeurl(decoded) + urls[i] = encoded + fetch = bb.fetch2.Fetch(urls, d) + tarball_suffix = {} for url in fetch.urls: local = fetch.localpath(url).rstrip("/"); if os.path.isfile(local): shutil.copy(local, ar_outdir) elif os.path.isdir(local): - basename = os.path.basename(local) - - tmpdir = tempfile.mkdtemp(dir=d.getVar('ARCHIVER_WORKDIR', True)) + tmpdir = tempfile.mkdtemp(dir=d.getVar('ARCHIVER_WORKDIR')) fetch.unpack(tmpdir, (url,)) - - os.chdir(tmpdir) - # We eliminate any AUTOINC+ in the revision. - try: - src_rev = bb.fetch2.get_srcrev(d).replace('AUTOINC+','') - except: - src_rev = 'NOREV' - tarname = os.path.join(ar_outdir, basename + '.' + src_rev + '.tar.gz') - tar = tarfile.open(tarname, 'w:gz') - tar.add('.') - tar.close() + # To handle recipes with more than one source, we add the "name" + # URL parameter as suffix. We treat it as an error when + # there's more than one URL without a name, or a name gets reused. + # This is an additional safety net, in practice the name has + # to be set when using the git fetcher, otherwise SRCREV cannot + # be set separately for each URL. + params = bb.fetch2.decodeurl(url)[5] + name = params.get('name', '') + if name in tarball_suffix: + if not name: + 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)) + else: + 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)) + tarball_suffix[name] = url + create_tarball(d, tmpdir + '/.', name, ar_outdir) # Emit patch series files for 'original' bb.note('Writing patch series files...') @@ -172,76 +191,79 @@ python do_ar_original() { python do_ar_patched() { - if d.getVarFlag('ARCHIVER_MODE', 'src', True) != 'patched': + if d.getVarFlag('ARCHIVER_MODE', 'src') != 'patched': return # Get the ARCHIVER_OUTDIR before we reset the WORKDIR - ar_outdir = d.getVar('ARCHIVER_OUTDIR', True) + ar_outdir = d.getVar('ARCHIVER_OUTDIR') + ar_workdir = d.getVar('ARCHIVER_WORKDIR') bb.note('Archiving the patched source...') - d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR', True)) - # The gcc staff uses shared source - flag = d.getVarFlag('do_unpack', 'stamp-base', True) - if flag: - create_tarball(d, d.getVar('S', True), 'patched', ar_outdir, 'gcc') - else: - create_tarball(d, d.getVar('S', True), 'patched', ar_outdir) + d.setVar('WORKDIR', ar_workdir) + create_tarball(d, d.getVar('S'), 'patched', ar_outdir) } python do_ar_configured() { import shutil - ar_outdir = d.getVar('ARCHIVER_OUTDIR', True) - if d.getVarFlag('ARCHIVER_MODE', 'src', True) == 'configured': + ar_outdir = d.getVar('ARCHIVER_OUTDIR') + if d.getVarFlag('ARCHIVER_MODE', 'src') == 'configured': bb.note('Archiving the configured source...') + pn = d.getVar('PN') + # "gcc-source-${PV}" recipes don't have "do_configure" + # task, so we need to run "do_preconfigure" instead + if pn.startswith("gcc-source-"): + d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR')) + bb.build.exec_func('do_preconfigure', d) + # The libtool-native's do_configure will remove the # ${STAGING_DATADIR}/aclocal/libtool.m4, so we can't re-run the # do_configure, we archive the already configured ${S} to # instead of. - if d.getVar('PN', True) != 'libtool-native': + elif pn != 'libtool-native': # Change the WORKDIR to make do_configure run in another dir. - d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR', True)) + d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR')) if bb.data.inherits_class('kernel-yocto', d): bb.build.exec_func('do_kernel_configme', d) if bb.data.inherits_class('cmake', d): bb.build.exec_func('do_generate_toolchain_file', d) - prefuncs = d.getVarFlag('do_configure', 'prefuncs', True) + prefuncs = d.getVarFlag('do_configure', 'prefuncs') for func in (prefuncs or '').split(): if func != "sysroot_cleansstate": bb.build.exec_func(func, d) bb.build.exec_func('do_configure', d) - postfuncs = d.getVarFlag('do_configure', 'postfuncs', True) + postfuncs = d.getVarFlag('do_configure', 'postfuncs') for func in (postfuncs or '').split(): if func != "do_qa_configure": bb.build.exec_func(func, d) - srcdir = d.getVar('S', True) - builddir = d.getVar('B', True) + srcdir = d.getVar('S') + builddir = d.getVar('B') if srcdir != builddir: if os.path.exists(builddir): oe.path.copytree(builddir, os.path.join(srcdir, \ - 'build.%s.ar_configured' % d.getVar('PF', True))) + 'build.%s.ar_configured' % d.getVar('PF'))) create_tarball(d, srcdir, 'configured', ar_outdir) } -def create_tarball(d, srcdir, suffix, ar_outdir, pf=None): +def create_tarball(d, srcdir, suffix, ar_outdir): """ create the tarball from srcdir """ import tarfile + # Make sure we are only creating a single tarball for gcc sources + if (d.getVar('SRC_URI') == ""): + return + bb.utils.mkdirhier(ar_outdir) - if pf: - tarname = os.path.join(ar_outdir, '%s-%s.tar.gz' % (pf, suffix)) + if suffix: + filename = '%s-%s.tar.gz' % (d.getVar('PF'), suffix) else: - tarname = os.path.join(ar_outdir, '%s-%s.tar.gz' % \ - (d.getVar('PF', True), suffix)) + filename = '%s.tar.gz' % d.getVar('PF') + tarname = os.path.join(ar_outdir, filename) - srcdir = srcdir.rstrip('/') - dirname = os.path.dirname(srcdir) - basename = os.path.basename(srcdir) - os.chdir(dirname) bb.note('Creating %s' % tarname) tar = tarfile.open(tarname, 'w:gz') - tar.add(basename) + tar.add(srcdir, arcname=os.path.basename(srcdir)) tar.close() # creating .diff.gz between source.orig and source @@ -257,51 +279,52 @@ def create_diff_gz(d, src_orig, src, ar_outdir): # exclude. src_patched = src + '.patched' oe.path.copyhardlinktree(src, src_patched) - for i in d.getVarFlag('ARCHIVER_MODE', 'diff-exclude', True).split(): + for i in d.getVarFlag('ARCHIVER_MODE', 'diff-exclude').split(): bb.utils.remove(os.path.join(src_orig, i), recurse=True) bb.utils.remove(os.path.join(src_patched, i), recurse=True) dirname = os.path.dirname(src) basename = os.path.basename(src) os.chdir(dirname) - out_file = os.path.join(ar_outdir, '%s-diff.gz' % d.getVar('PF', True)) + out_file = os.path.join(ar_outdir, '%s-diff.gz' % d.getVar('PF')) diff_cmd = 'diff -Naur %s.orig %s.patched | gzip -c > %s' % (basename, basename, out_file) subprocess.call(diff_cmd, shell=True) bb.utils.remove(src_patched, recurse=True) # Run do_unpack and do_patch python do_unpack_and_patch() { - if d.getVarFlag('ARCHIVER_MODE', 'src', True) not in \ + if d.getVarFlag('ARCHIVER_MODE', 'src') not in \ [ 'patched', 'configured'] and \ - d.getVarFlag('ARCHIVER_MODE', 'diff', True) != '1': + d.getVarFlag('ARCHIVER_MODE', 'diff') != '1': return + ar_outdir = d.getVar('ARCHIVER_OUTDIR') + ar_workdir = d.getVar('ARCHIVER_WORKDIR') + pn = d.getVar('PN') - ar_outdir = d.getVar('ARCHIVER_OUTDIR', True) - - # Change the WORKDIR to make do_unpack do_patch run in another dir. - d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR', True)) + # The kernel class functions require it to be on work-shared, so we dont change WORKDIR + if not (bb.data.inherits_class('kernel-yocto', d) or pn.startswith('gcc-source')): + # Change the WORKDIR to make do_unpack do_patch run in another dir. + d.setVar('WORKDIR', ar_workdir) - # The changed 'WORKDIR' also casued 'B' changed, create dir 'B' for the - # possibly requiring of the following tasks (such as some recipes's - # do_patch required 'B' existed). - bb.utils.mkdirhier(d.getVar('B', True)) + # The changed 'WORKDIR' also caused 'B' changed, create dir 'B' for the + # possibly requiring of the following tasks (such as some recipes's + # do_patch required 'B' existed). + bb.utils.mkdirhier(d.getVar('B')) - # The kernel source is ready after do_validate_branches - if bb.data.inherits_class('kernel-yocto', d): - bb.build.exec_func('do_unpack', d) - bb.build.exec_func('do_kernel_checkout', d) - bb.build.exec_func('do_validate_branches', d) - else: bb.build.exec_func('do_unpack', d) # Save the original source for creating the patches - if d.getVarFlag('ARCHIVER_MODE', 'diff', True) == '1': - src = d.getVar('S', True).rstrip('/') + if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1': + src = d.getVar('S').rstrip('/') src_orig = '%s.orig' % src oe.path.copytree(src, src_orig) - bb.build.exec_func('do_patch', d) + + # Make sure gcc and kernel sources are patched only once + if not (d.getVar('SRC_URI') == "" or (bb.data.inherits_class('kernel-yocto', d) or pn.startswith('gcc-source'))): + bb.build.exec_func('do_patch', d) + # Create the patches - if d.getVarFlag('ARCHIVER_MODE', 'diff', True) == '1': + if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1': bb.note('Creating diff gz...') create_diff_gz(d, src_orig, src, ar_outdir) bb.utils.remove(src_orig, recurse=True) @@ -316,14 +339,24 @@ python do_ar_recipe () { require_re = re.compile( r"require\s+(.+)" ) include_re = re.compile( r"include\s+(.+)" ) - bbfile = d.getVar('FILE', True) - outdir = os.path.join(d.getVar('WORKDIR', True), \ - '%s-recipe' % d.getVar('PF', True)) + bbfile = d.getVar('FILE') + outdir = os.path.join(d.getVar('WORKDIR'), \ + '%s-recipe' % d.getVar('PF')) bb.utils.mkdirhier(outdir) shutil.copy(bbfile, outdir) + pn = d.getVar('PN') + bbappend_files = d.getVar('BBINCLUDED').split() + # If recipe name is aa, we need to match files like aa.bbappend and aa_1.1.bbappend + # Files like aa1.bbappend or aa1_1.1.bbappend must be excluded. + bbappend_re = re.compile( r".*/%s_[^/]*\.bbappend$" %pn) + bbappend_re1 = re.compile( r".*/%s\.bbappend$" %pn) + for file in bbappend_files: + if bbappend_re.match(file) or bbappend_re1.match(file): + shutil.copy(file, outdir) + dirname = os.path.dirname(bbfile) - bbpath = '%s:%s' % (dirname, d.getVar('BBPATH', True)) + bbpath = '%s:%s' % (dirname, d.getVar('BBPATH')) f = open(bbfile, 'r') for line in f.readlines(): incfile = None @@ -332,12 +365,12 @@ python do_ar_recipe () { elif include_re.match(line): incfile = include_re.match(line).group(1) if incfile: - incfile = bb.data.expand(incfile, d) + incfile = d.expand(incfile) incfile = bb.utils.which(bbpath, incfile) if incfile: shutil.copy(incfile, outdir) - create_tarball(d, outdir, 'recipe', d.getVar('ARCHIVER_OUTDIR', True)) + create_tarball(d, outdir, 'recipe', d.getVar('ARCHIVER_OUTDIR')) bb.utils.remove(outdir, recurse=True) } @@ -346,28 +379,29 @@ python do_dumpdata () { dump environment data to ${PF}-showdata.dump """ - dumpfile = os.path.join(d.getVar('ARCHIVER_OUTDIR', True), \ - '%s-showdata.dump' % d.getVar('PF', True)) + dumpfile = os.path.join(d.getVar('ARCHIVER_OUTDIR'), \ + '%s-showdata.dump' % d.getVar('PF')) bb.note('Dumping metadata into %s' % dumpfile) - f = open(dumpfile, 'w') - # emit variables and shell functions - bb.data.emit_env(f, d, True) - # emit the metadata which isn't valid shell - for e in d.keys(): - if bb.data.getVarFlag(e, 'python', d): - f.write("\npython %s () {\n%s}\n" % (e, bb.data.getVar(e, d, True))) - f.close() + with open(dumpfile, "w") as f: + # emit variables and shell functions + bb.data.emit_env(f, d, True) + # emit the metadata which isn't valid shell + for e in d.keys(): + if d.getVarFlag(e, "python", False): + f.write("\npython %s () {\n%s}\n" % (e, d.getVar(e, False))) } SSTATETASKS += "do_deploy_archives" do_deploy_archives () { - echo "Deploying source archive files ..." + echo "Deploying source archive files from ${ARCHIVER_TOPDIR} to ${DEPLOY_DIR_SRC}." } python do_deploy_archives_setscene () { sstate_setscene(d) } +do_deploy_archives[dirs] = "${ARCHIVER_TOPDIR}" do_deploy_archives[sstate-inputdirs] = "${ARCHIVER_TOPDIR}" do_deploy_archives[sstate-outputdirs] = "${DEPLOY_DIR_SRC}" +addtask do_deploy_archives_setscene addtask do_ar_original after do_unpack addtask do_unpack_and_patch after do_patch @@ -376,3 +410,16 @@ addtask do_ar_configured after do_unpack_and_patch addtask do_dumpdata addtask do_ar_recipe addtask do_deploy_archives before do_build + +addtask do_deploy_all_archives after do_deploy_archives +do_deploy_all_archives[recrdeptask] = "do_deploy_archives" +do_deploy_all_archives[recideptask] = "do_${BB_DEFAULT_TASK}" +do_deploy_all_archives() { + : +} + +python () { + # Add tasks in the correct order, specifically for linux-yocto to avoid race condition + if bb.data.inherits_class('kernel-yocto', d): + bb.build.addtask('do_kernel_configme', 'do_configure', 'do_unpack_and_patch', d) +} |
