blob: 18c5b96689b38185431b8a0358fa7e3b05ff0c65 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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
27COPYLEFT_LICENSE_INCLUDE ?= ''
28COPYLEFT_LICENSE_EXCLUDE ?= ''
29# Create archive for all the recipe types
30COPYLEFT_RECIPE_TYPES ?= 'target native nativesdk cross crosssdk cross-canadian'
31inherit copyleft_filter
32
33ARCHIVER_MODE[srpm] ?= "0"
34ARCHIVER_MODE[src] ?= "patched"
35ARCHIVER_MODE[diff] ?= "0"
36ARCHIVER_MODE[diff-exclude] ?= ".pc autom4te.cache patches"
37ARCHIVER_MODE[dumpdata] ?= "0"
38ARCHIVER_MODE[recipe] ?= "0"
39
40DEPLOY_DIR_SRC ?= "${DEPLOY_DIR}/sources"
41ARCHIVER_TOPDIR ?= "${WORKDIR}/deploy-sources"
42ARCHIVER_OUTDIR = "${ARCHIVER_TOPDIR}/${TARGET_SYS}/${PF}/"
43ARCHIVER_WORKDIR = "${WORKDIR}/archiver-work/"
44
45do_dumpdata[dirs] = "${ARCHIVER_OUTDIR}"
46do_ar_recipe[dirs] = "${ARCHIVER_OUTDIR}"
47do_ar_original[dirs] = "${ARCHIVER_OUTDIR} ${ARCHIVER_WORKDIR}"
48do_deploy_archives[dirs] = "${WORKDIR}"
49do_deploy_all_archives[dirs] = "${WORKDIR}"
50
51# This is a convenience for the shell script to use it
52
53
54python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050055 pn = d.getVar('PN')
56 assume_provided = (d.getVar("ASSUME_PROVIDED") or "").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050057 if pn in assume_provided:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050058 for p in d.getVar("PROVIDES").split():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050059 if p != pn:
60 pn = p
61 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062
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 Bishop6e60e8b2018-02-01 10:27:11 -050070
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 Williamsd8c66bc2016-06-20 12:57:21 -050076 # We just archive gcc-source for all the gcc related recipes
Brad Bishop6e60e8b2018-02-01 10:27:11 -050077 if d.getVar('BPN') in ['gcc', 'libgcc'] \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050078 and not pn.startswith('gcc-source'):
79 bb.debug(1, 'archiver: %s is excluded, covered by gcc-source' % pn)
80 return
81
Brad Bishop6e60e8b2018-02-01 10:27:11 -050082 ar_src = d.getVarFlag('ARCHIVER_MODE', 'src')
83 ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata')
84 ar_recipe = d.getVarFlag('ARCHIVER_MODE', 'recipe')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085
86 if ar_src == "original":
87 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_original' % pn)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050088 # '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 Williamsc124f4f2015-09-15 14:41:29 -050093 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 Williamsd8c66bc2016-06-20 12:57:21 -050099
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 Williamsc124f4f2015-09-15 14:41:29 -0500106 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_configured' % pn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500107
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108 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 Bishop6e60e8b2018-02-01 10:27:11 -0500118 ar_srpm = d.getVarFlag('ARCHIVER_MODE', 'srpm')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 if ar_srpm == "1":
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500120 if d.getVar('PACKAGES') != '' and d.getVar('IMAGE_PKGTYPE') == 'rpm':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500121 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 Williamsc124f4f2015-09-15 14:41:29 -0500132}
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.
137python do_ar_original() {
138
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500139 import shutil, tempfile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500141 if d.getVarFlag('ARCHIVER_MODE', 'src') != "original":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500142 return
143
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500144 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500145 bb.note('Archiving the original source...')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500146 urls = d.getVar("SRC_URI").split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600147 # 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 Williamsc124f4f2015-09-15 14:41:29 -0500166 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 Bishop6e60e8b2018-02-01 10:27:11 -0500171 tmpdir = tempfile.mkdtemp(dir=d.getVar('ARCHIVER_WORKDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172 fetch.unpack(tmpdir, (url,))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600173 # 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 Bishop6e60e8b2018-02-01 10:27:11 -0500180 type = bb.fetch2.decodeurl(url)[0]
181 location = bb.fetch2.decodeurl(url)[2]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600182 name = params.get('name', '')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500183 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 Williamsc0f7c042017-02-23 20:41:17 -0600192 tarball_suffix[name] = url
193 create_tarball(d, tmpdir + '/.', name, ar_outdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500194
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
209python do_ar_patched() {
210
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500211 if d.getVarFlag('ARCHIVER_MODE', 'src') != 'patched':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500212 return
213
214 # Get the ARCHIVER_OUTDIR before we reset the WORKDIR
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500215 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
216 ar_workdir = d.getVar('ARCHIVER_WORKDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217 bb.note('Archiving the patched source...')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500218 d.setVar('WORKDIR', ar_workdir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500219 create_tarball(d, d.getVar('S'), 'patched', ar_outdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220}
221
222python do_ar_configured() {
223 import shutil
224
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500225 # Forcibly expand the sysroot paths as we're about to change WORKDIR
226 d.setVar('RECIPE_SYSROOT', d.getVar('RECIPE_SYSROOT'))
227 d.setVar('RECIPE_SYSROOT_NATIVE', d.getVar('RECIPE_SYSROOT_NATIVE'))
228
229 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
230 if d.getVarFlag('ARCHIVER_MODE', 'src') == 'configured':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231 bb.note('Archiving the configured source...')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500232 pn = d.getVar('PN')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500233 # "gcc-source-${PV}" recipes don't have "do_configure"
234 # task, so we need to run "do_preconfigure" instead
235 if pn.startswith("gcc-source-"):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500236 d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500237 bb.build.exec_func('do_preconfigure', d)
238
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239 # The libtool-native's do_configure will remove the
240 # ${STAGING_DATADIR}/aclocal/libtool.m4, so we can't re-run the
241 # do_configure, we archive the already configured ${S} to
242 # instead of.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500243 elif pn != 'libtool-native':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 # Change the WORKDIR to make do_configure run in another dir.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500245 d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246 if bb.data.inherits_class('kernel-yocto', d):
247 bb.build.exec_func('do_kernel_configme', d)
248 if bb.data.inherits_class('cmake', d):
249 bb.build.exec_func('do_generate_toolchain_file', d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500250 prefuncs = d.getVarFlag('do_configure', 'prefuncs')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500251 for func in (prefuncs or '').split():
252 if func != "sysroot_cleansstate":
253 bb.build.exec_func(func, d)
254 bb.build.exec_func('do_configure', d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500255 postfuncs = d.getVarFlag('do_configure', 'postfuncs')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500256 for func in (postfuncs or '').split():
257 if func != "do_qa_configure":
258 bb.build.exec_func(func, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500259 srcdir = d.getVar('S')
260 builddir = d.getVar('B')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500261 if srcdir != builddir:
262 if os.path.exists(builddir):
263 oe.path.copytree(builddir, os.path.join(srcdir, \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500264 'build.%s.ar_configured' % d.getVar('PF')))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265 create_tarball(d, srcdir, 'configured', ar_outdir)
266}
267
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500268def create_tarball(d, srcdir, suffix, ar_outdir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500269 """
270 create the tarball from srcdir
271 """
272 import tarfile
273
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500274 # Make sure we are only creating a single tarball for gcc sources
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500275 if (d.getVar('SRC_URI') == ""):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500276 return
277
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 bb.utils.mkdirhier(ar_outdir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500279 if suffix:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500280 filename = '%s-%s.tar.gz' % (d.getVar('PF'), suffix)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500281 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500282 filename = '%s.tar.gz' % d.getVar('PF')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500283 tarname = os.path.join(ar_outdir, filename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500284
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500285 bb.note('Creating %s' % tarname)
286 tar = tarfile.open(tarname, 'w:gz')
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500287 tar.add(srcdir, arcname=os.path.basename(srcdir))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288 tar.close()
289
290# creating .diff.gz between source.orig and source
291def create_diff_gz(d, src_orig, src, ar_outdir):
292
293 import subprocess
294
295 if not os.path.isdir(src) or not os.path.isdir(src_orig):
296 return
297
298 # The diff --exclude can't exclude the file with path, so we copy
299 # the patched source, and remove the files that we'd like to
300 # exclude.
301 src_patched = src + '.patched'
302 oe.path.copyhardlinktree(src, src_patched)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500303 for i in d.getVarFlag('ARCHIVER_MODE', 'diff-exclude').split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500304 bb.utils.remove(os.path.join(src_orig, i), recurse=True)
305 bb.utils.remove(os.path.join(src_patched, i), recurse=True)
306
307 dirname = os.path.dirname(src)
308 basename = os.path.basename(src)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500309 bb.utils.mkdirhier(ar_outdir)
310 cwd = os.getcwd()
311 try:
312 os.chdir(dirname)
313 out_file = os.path.join(ar_outdir, '%s-diff.gz' % d.getVar('PF'))
314 diff_cmd = 'diff -Naur %s.orig %s.patched | gzip -c > %s' % (basename, basename, out_file)
315 subprocess.check_call(diff_cmd, shell=True)
316 bb.utils.remove(src_patched, recurse=True)
317 finally:
318 os.chdir(cwd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500319
320# Run do_unpack and do_patch
321python do_unpack_and_patch() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500322 if d.getVarFlag('ARCHIVER_MODE', 'src') not in \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500323 [ 'patched', 'configured'] and \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500324 d.getVarFlag('ARCHIVER_MODE', 'diff') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325 return
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500326 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
327 ar_workdir = d.getVar('ARCHIVER_WORKDIR')
328 ar_sysroot_native = d.getVar('STAGING_DIR_NATIVE')
329 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500330
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500331 # The kernel class functions require it to be on work-shared, so we dont change WORKDIR
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600332 if not (bb.data.inherits_class('kernel-yocto', d) or pn.startswith('gcc-source')):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500333 # Change the WORKDIR to make do_unpack do_patch run in another dir.
334 d.setVar('WORKDIR', ar_workdir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500335 # Restore the original path to recipe's native sysroot (it's relative to WORKDIR).
336 d.setVar('STAGING_DIR_NATIVE', ar_sysroot_native)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500337
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500338 # The changed 'WORKDIR' also caused 'B' changed, create dir 'B' for the
339 # possibly requiring of the following tasks (such as some recipes's
340 # do_patch required 'B' existed).
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500341 bb.utils.mkdirhier(d.getVar('B'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500342
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500343 bb.build.exec_func('do_unpack', d)
344
345 # Save the original source for creating the patches
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500346 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1':
347 src = d.getVar('S').rstrip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500348 src_orig = '%s.orig' % src
349 oe.path.copytree(src, src_orig)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500350
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500351 # Make sure gcc and kernel sources are patched only once
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500352 if not (d.getVar('SRC_URI') == "" or (bb.data.inherits_class('kernel-yocto', d) or pn.startswith('gcc-source'))):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500353 bb.build.exec_func('do_patch', d)
354
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500355 # Create the patches
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500356 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357 bb.note('Creating diff gz...')
358 create_diff_gz(d, src_orig, src, ar_outdir)
359 bb.utils.remove(src_orig, recurse=True)
360}
361
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500362# BBINCLUDED is special (excluded from basehash signature
363# calculation). Using it in a task signature can cause "basehash
364# changed" errors.
365#
366# Depending on BBINCLUDED also causes do_ar_recipe to run again
367# for unrelated changes, like adding or removing buildhistory.bbclass.
368#
369# For these reasons we ignore the dependency completely. The versioning
370# of the output file ensures that we create it each time the recipe
371# gets rebuilt, at least as long as a PR server is used. We also rely
372# on that mechanism to catch changes in the file content, because the
373# file content is not part of of the task signature either.
374do_ar_recipe[vardepsexclude] += "BBINCLUDED"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500375python do_ar_recipe () {
376 """
377 archive the recipe, including .bb and .inc.
378 """
379 import re
380 import shutil
381
382 require_re = re.compile( r"require\s+(.+)" )
383 include_re = re.compile( r"include\s+(.+)" )
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500384 bbfile = d.getVar('FILE')
385 outdir = os.path.join(d.getVar('WORKDIR'), \
386 '%s-recipe' % d.getVar('PF'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500387 bb.utils.mkdirhier(outdir)
388 shutil.copy(bbfile, outdir)
389
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500390 pn = d.getVar('PN')
391 bbappend_files = d.getVar('BBINCLUDED').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500392 # If recipe name is aa, we need to match files like aa.bbappend and aa_1.1.bbappend
393 # Files like aa1.bbappend or aa1_1.1.bbappend must be excluded.
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500394 bbappend_re = re.compile( r".*/%s_[^/]*\.bbappend$" % re.escape(pn))
395 bbappend_re1 = re.compile( r".*/%s\.bbappend$" % re.escape(pn))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500396 for file in bbappend_files:
397 if bbappend_re.match(file) or bbappend_re1.match(file):
398 shutil.copy(file, outdir)
399
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500400 dirname = os.path.dirname(bbfile)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500401 bbpath = '%s:%s' % (dirname, d.getVar('BBPATH'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500402 f = open(bbfile, 'r')
403 for line in f.readlines():
404 incfile = None
405 if require_re.match(line):
406 incfile = require_re.match(line).group(1)
407 elif include_re.match(line):
408 incfile = include_re.match(line).group(1)
409 if incfile:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500410 incfile = d.expand(incfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500411 incfile = bb.utils.which(bbpath, incfile)
412 if incfile:
413 shutil.copy(incfile, outdir)
414
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500415 create_tarball(d, outdir, 'recipe', d.getVar('ARCHIVER_OUTDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500416 bb.utils.remove(outdir, recurse=True)
417}
418
419python do_dumpdata () {
420 """
421 dump environment data to ${PF}-showdata.dump
422 """
423
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500424 dumpfile = os.path.join(d.getVar('ARCHIVER_OUTDIR'), \
425 '%s-showdata.dump' % d.getVar('PF'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500426 bb.note('Dumping metadata into %s' % dumpfile)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500427 with open(dumpfile, "w") as f:
428 # emit variables and shell functions
429 bb.data.emit_env(f, d, True)
430 # emit the metadata which isn't valid shell
431 for e in d.keys():
432 if d.getVarFlag(e, "python", False):
433 f.write("\npython %s () {\n%s}\n" % (e, d.getVar(e, False)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500434}
435
436SSTATETASKS += "do_deploy_archives"
437do_deploy_archives () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500438 echo "Deploying source archive files from ${ARCHIVER_TOPDIR} to ${DEPLOY_DIR_SRC}."
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500439}
440python do_deploy_archives_setscene () {
441 sstate_setscene(d)
442}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500443do_deploy_archives[dirs] = "${ARCHIVER_TOPDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500444do_deploy_archives[sstate-inputdirs] = "${ARCHIVER_TOPDIR}"
445do_deploy_archives[sstate-outputdirs] = "${DEPLOY_DIR_SRC}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500446addtask do_deploy_archives_setscene
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500447
448addtask do_ar_original after do_unpack
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500449addtask do_unpack_and_patch after do_patch
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500450addtask do_ar_patched after do_unpack_and_patch
451addtask do_ar_configured after do_unpack_and_patch
452addtask do_dumpdata
453addtask do_ar_recipe
454addtask do_deploy_archives before do_build
455
456addtask do_deploy_all_archives after do_deploy_archives
457do_deploy_all_archives[recrdeptask] = "do_deploy_archives"
458do_deploy_all_archives[recideptask] = "do_${BB_DEFAULT_TASK}"
459do_deploy_all_archives() {
460 :
461}
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500462
463python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500464 # Add tasks in the correct order, specifically for linux-yocto to avoid race condition.
465 # sstatesig.py:sstate_rundepfilter has special support that excludes this dependency
466 # so that do_kernel_configme does not need to run again when do_unpack_and_patch
467 # gets added or removed (by adding or removing archiver.bbclass).
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500468 if bb.data.inherits_class('kernel-yocto', d):
469 bb.build.addtask('do_kernel_configme', 'do_configure', 'do_unpack_and_patch', d)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500470}