blob: 13b05bb5f2f71abb5ea07f90f1caffdf5a58162c [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
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026# Create archive for all the recipe types
27COPYLEFT_RECIPE_TYPES ?= 'target native nativesdk cross crosssdk cross-canadian'
28inherit copyleft_filter
29
30ARCHIVER_MODE[srpm] ?= "0"
31ARCHIVER_MODE[src] ?= "patched"
32ARCHIVER_MODE[diff] ?= "0"
33ARCHIVER_MODE[diff-exclude] ?= ".pc autom4te.cache patches"
34ARCHIVER_MODE[dumpdata] ?= "0"
35ARCHIVER_MODE[recipe] ?= "0"
36
37DEPLOY_DIR_SRC ?= "${DEPLOY_DIR}/sources"
38ARCHIVER_TOPDIR ?= "${WORKDIR}/deploy-sources"
39ARCHIVER_OUTDIR = "${ARCHIVER_TOPDIR}/${TARGET_SYS}/${PF}/"
Brad Bishop19323692019-04-05 15:28:33 -040040ARCHIVER_RPMTOPDIR ?= "${WORKDIR}/deploy-sources-rpm"
41ARCHIVER_RPMOUTDIR = "${ARCHIVER_RPMTOPDIR}/${TARGET_SYS}/${PF}/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042ARCHIVER_WORKDIR = "${WORKDIR}/archiver-work/"
43
Brad Bishop19323692019-04-05 15:28:33 -040044
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045do_dumpdata[dirs] = "${ARCHIVER_OUTDIR}"
46do_ar_recipe[dirs] = "${ARCHIVER_OUTDIR}"
47do_ar_original[dirs] = "${ARCHIVER_OUTDIR} ${ARCHIVER_WORKDIR}"
48do_deploy_archives[dirs] = "${WORKDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049
50# This is a convenience for the shell script to use it
51
52
53python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054 pn = d.getVar('PN')
55 assume_provided = (d.getVar("ASSUME_PROVIDED") or "").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050056 if pn in assume_provided:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057 for p in d.getVar("PROVIDES").split():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058 if p != pn:
59 pn = p
60 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061
62 included, reason = copyleft_should_include(d)
63 if not included:
64 bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason))
65 return
66 else:
67 bb.debug(1, 'archiver: %s is included: %s' % (pn, reason))
68
Brad Bishop6e60e8b2018-02-01 10:27:11 -050069
70 # glibc-locale: do_fetch, do_unpack and do_patch tasks have been deleted,
71 # so avoid archiving source here.
72 if pn.startswith('glibc-locale'):
73 return
74
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050075 # We just archive gcc-source for all the gcc related recipes
Brad Bishop6e60e8b2018-02-01 10:27:11 -050076 if d.getVar('BPN') in ['gcc', 'libgcc'] \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050077 and not pn.startswith('gcc-source'):
78 bb.debug(1, 'archiver: %s is excluded, covered by gcc-source' % pn)
79 return
80
Brad Bishop79641f22019-09-10 07:20:22 -040081 def hasTask(task):
82 return bool(d.getVarFlag(task, "task", False)) and not bool(d.getVarFlag(task, "noexec", False))
83
Brad Bishop6e60e8b2018-02-01 10:27:11 -050084 ar_src = d.getVarFlag('ARCHIVER_MODE', 'src')
85 ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata')
86 ar_recipe = d.getVarFlag('ARCHIVER_MODE', 'recipe')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050087
88 if ar_src == "original":
89 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_original' % pn)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050090 # 'patched' and 'configured' invoke do_unpack_and_patch because
91 # do_ar_patched resp. do_ar_configured depend on it, but for 'original'
92 # we have to add it explicitly.
93 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1':
94 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_unpack_and_patch' % pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 elif ar_src == "patched":
96 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_patched' % pn)
97 elif ar_src == "configured":
98 # We can't use "addtask do_ar_configured after do_configure" since it
99 # will cause the deptask of do_populate_sysroot to run not matter what
100 # archives we need, so we add the depends here.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500101
102 # There is a corner case with "gcc-source-${PV}" recipes, they don't have
103 # the "do_configure" task, so we need to use "do_preconfigure"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800104 if hasTask("do_preconfigure"):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500105 d.appendVarFlag('do_ar_configured', 'depends', ' %s:do_preconfigure' % pn)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800106 elif hasTask("do_configure"):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500107 d.appendVarFlag('do_ar_configured', 'depends', ' %s:do_configure' % pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_configured' % pn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500109
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110 elif ar_src:
111 bb.fatal("Invalid ARCHIVER_MODE[src]: %s" % ar_src)
112
113 if ar_dumpdata == "1":
114 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_dumpdata' % pn)
115
116 if ar_recipe == "1":
117 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_recipe' % pn)
118
Brad Bishop316dfdd2018-06-25 12:45:53 -0400119 # Output the SRPM package
120 if d.getVarFlag('ARCHIVER_MODE', 'srpm') == "1" and d.getVar('PACKAGES'):
Brad Bishop79641f22019-09-10 07:20:22 -0400121 if "package_rpm" not in d.getVar('PACKAGE_CLASSES'):
122 bb.fatal("ARCHIVER_MODE[srpm] needs package_rpm in PACKAGE_CLASSES")
123
124 # Some recipes do not have any packaging tasks
125 if hasTask("do_package_write_rpm"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_package_write_rpm' % pn)
Brad Bishop19323692019-04-05 15:28:33 -0400127 d.appendVarFlag('do_package_write_rpm', 'dirs', ' ${ARCHIVER_RPMTOPDIR}')
128 d.appendVarFlag('do_package_write_rpm', 'sstate-inputdirs', ' ${ARCHIVER_RPMTOPDIR}')
129 d.appendVarFlag('do_package_write_rpm', 'sstate-outputdirs', ' ${DEPLOY_DIR_SRC}')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 if ar_dumpdata == "1":
131 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_dumpdata' % pn)
132 if ar_recipe == "1":
133 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_recipe' % pn)
134 if ar_src == "original":
135 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_original' % pn)
136 elif ar_src == "patched":
137 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_patched' % pn)
138 elif ar_src == "configured":
139 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_configured' % pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140}
141
142# Take all the sources for a recipe and puts them in WORKDIR/archiver-work/.
143# Files in SRC_URI are copied directly, anything that's a directory
144# (e.g. git repositories) is "unpacked" and then put into a tarball.
145python do_ar_original() {
146
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500147 import shutil, tempfile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500149 if d.getVarFlag('ARCHIVER_MODE', 'src') != "original":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 return
151
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500152 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153 bb.note('Archiving the original source...')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500154 urls = d.getVar("SRC_URI").split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600155 # destsuffix (git fetcher) and subdir (everything else) are allowed to be
156 # absolute paths (for example, destsuffix=${S}/foobar).
157 # That messes with unpacking inside our tmpdir below, because the fetchers
158 # will then unpack in that directory and completely ignore the tmpdir.
159 # That breaks parallel tasks relying on ${S}, like do_compile.
160 #
161 # To solve this, we remove these parameters from all URLs.
162 # We do this even for relative paths because it makes the content of the
163 # archives more useful (no extra paths that are only used during
164 # compilation).
165 for i, url in enumerate(urls):
166 decoded = bb.fetch2.decodeurl(url)
167 for param in ('destsuffix', 'subdir'):
168 if param in decoded[5]:
169 del decoded[5][param]
170 encoded = bb.fetch2.encodeurl(decoded)
171 urls[i] = encoded
172 fetch = bb.fetch2.Fetch(urls, d)
173 tarball_suffix = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174 for url in fetch.urls:
175 local = fetch.localpath(url).rstrip("/");
176 if os.path.isfile(local):
177 shutil.copy(local, ar_outdir)
178 elif os.path.isdir(local):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500179 tmpdir = tempfile.mkdtemp(dir=d.getVar('ARCHIVER_WORKDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500180 fetch.unpack(tmpdir, (url,))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600181 # To handle recipes with more than one source, we add the "name"
182 # URL parameter as suffix. We treat it as an error when
183 # there's more than one URL without a name, or a name gets reused.
184 # This is an additional safety net, in practice the name has
185 # to be set when using the git fetcher, otherwise SRCREV cannot
186 # be set separately for each URL.
187 params = bb.fetch2.decodeurl(url)[5]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500188 type = bb.fetch2.decodeurl(url)[0]
189 location = bb.fetch2.decodeurl(url)[2]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600190 name = params.get('name', '')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500191 if type.lower() == 'file':
192 name_tmp = location.rstrip("*").rstrip("/")
193 name = os.path.basename(name_tmp)
194 else:
195 if name in tarball_suffix:
196 if not name:
197 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))
198 else:
199 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 -0600200 tarball_suffix[name] = url
201 create_tarball(d, tmpdir + '/.', name, ar_outdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202
203 # Emit patch series files for 'original'
204 bb.note('Writing patch series files...')
205 for patch in src_patches(d):
206 _, _, local, _, _, parm = bb.fetch.decodeurl(patch)
207 patchdir = parm.get('patchdir')
208 if patchdir:
209 series = os.path.join(ar_outdir, 'series.subdir.%s' % patchdir.replace('/', '_'))
210 else:
211 series = os.path.join(ar_outdir, 'series')
212
213 with open(series, 'a') as s:
214 s.write('%s -p%s\n' % (os.path.basename(local), parm['striplevel']))
215}
216
217python do_ar_patched() {
218
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500219 if d.getVarFlag('ARCHIVER_MODE', 'src') != 'patched':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220 return
221
222 # Get the ARCHIVER_OUTDIR before we reset the WORKDIR
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500223 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
224 ar_workdir = d.getVar('ARCHIVER_WORKDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500225 bb.note('Archiving the patched source...')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500226 d.setVar('WORKDIR', ar_workdir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500227 create_tarball(d, d.getVar('S'), 'patched', ar_outdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228}
229
230python do_ar_configured() {
231 import shutil
232
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500233 # Forcibly expand the sysroot paths as we're about to change WORKDIR
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500234 d.setVar('STAGING_DIR_HOST', d.getVar('STAGING_DIR_HOST'))
235 d.setVar('STAGING_DIR_TARGET', d.getVar('STAGING_DIR_TARGET'))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500236 d.setVar('RECIPE_SYSROOT', d.getVar('RECIPE_SYSROOT'))
237 d.setVar('RECIPE_SYSROOT_NATIVE', d.getVar('RECIPE_SYSROOT_NATIVE'))
238
239 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
240 if d.getVarFlag('ARCHIVER_MODE', 'src') == 'configured':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241 bb.note('Archiving the configured source...')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500242 pn = d.getVar('PN')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500243 # "gcc-source-${PV}" recipes don't have "do_configure"
244 # task, so we need to run "do_preconfigure" instead
245 if pn.startswith("gcc-source-"):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500246 d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500247 bb.build.exec_func('do_preconfigure', d)
248
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500249 # The libtool-native's do_configure will remove the
250 # ${STAGING_DATADIR}/aclocal/libtool.m4, so we can't re-run the
251 # do_configure, we archive the already configured ${S} to
252 # instead of.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500253 elif pn != 'libtool-native':
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800254 def runTask(task):
255 prefuncs = d.getVarFlag(task, 'prefuncs') or ''
256 for func in prefuncs.split():
257 if func != "sysroot_cleansstate":
258 bb.build.exec_func(func, d)
259 bb.build.exec_func(task, d)
260 postfuncs = d.getVarFlag(task, 'postfuncs') or ''
261 for func in postfuncs.split():
262 if func != 'do_qa_configure':
263 bb.build.exec_func(func, d)
264
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265 # Change the WORKDIR to make do_configure run in another dir.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500266 d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR'))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800267
268 preceeds = bb.build.preceedtask('do_configure', False, d)
269 for task in preceeds:
270 if task != 'do_patch' and task != 'do_prepare_recipe_sysroot':
271 runTask(task)
272 runTask('do_configure')
273
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500274 srcdir = d.getVar('S')
275 builddir = d.getVar('B')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500276 if srcdir != builddir:
277 if os.path.exists(builddir):
278 oe.path.copytree(builddir, os.path.join(srcdir, \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500279 'build.%s.ar_configured' % d.getVar('PF')))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500280 create_tarball(d, srcdir, 'configured', ar_outdir)
281}
282
Brad Bishopc4ea0752018-11-15 14:30:15 -0800283def exclude_useless_paths(tarinfo):
284 if tarinfo.isdir():
285 if tarinfo.name.endswith('/temp') or tarinfo.name.endswith('/patches') or tarinfo.name.endswith('/.pc'):
286 return None
287 elif tarinfo.name == 'temp' or tarinfo.name == 'patches' or tarinfo.name == '.pc':
288 return None
289 return tarinfo
290
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500291def create_tarball(d, srcdir, suffix, ar_outdir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292 """
293 create the tarball from srcdir
294 """
295 import tarfile
296
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500297 # Make sure we are only creating a single tarball for gcc sources
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500298 if (d.getVar('SRC_URI') == ""):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500299 return
300
Brad Bishop316dfdd2018-06-25 12:45:53 -0400301 # For the kernel archive, srcdir may just be a link to the
302 # work-shared location. Use os.path.realpath to make sure
303 # that we archive the actual directory and not just the link.
304 srcdir = os.path.realpath(srcdir)
305
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306 bb.utils.mkdirhier(ar_outdir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500307 if suffix:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500308 filename = '%s-%s.tar.gz' % (d.getVar('PF'), suffix)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500309 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500310 filename = '%s.tar.gz' % d.getVar('PF')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500311 tarname = os.path.join(ar_outdir, filename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500312
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500313 bb.note('Creating %s' % tarname)
314 tar = tarfile.open(tarname, 'w:gz')
Brad Bishopc4ea0752018-11-15 14:30:15 -0800315 tar.add(srcdir, arcname=os.path.basename(srcdir), filter=exclude_useless_paths)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500316 tar.close()
317
318# creating .diff.gz between source.orig and source
319def create_diff_gz(d, src_orig, src, ar_outdir):
320
321 import subprocess
322
323 if not os.path.isdir(src) or not os.path.isdir(src_orig):
324 return
325
326 # The diff --exclude can't exclude the file with path, so we copy
327 # the patched source, and remove the files that we'd like to
328 # exclude.
329 src_patched = src + '.patched'
330 oe.path.copyhardlinktree(src, src_patched)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500331 for i in d.getVarFlag('ARCHIVER_MODE', 'diff-exclude').split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500332 bb.utils.remove(os.path.join(src_orig, i), recurse=True)
333 bb.utils.remove(os.path.join(src_patched, i), recurse=True)
334
335 dirname = os.path.dirname(src)
336 basename = os.path.basename(src)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500337 bb.utils.mkdirhier(ar_outdir)
338 cwd = os.getcwd()
339 try:
340 os.chdir(dirname)
341 out_file = os.path.join(ar_outdir, '%s-diff.gz' % d.getVar('PF'))
342 diff_cmd = 'diff -Naur %s.orig %s.patched | gzip -c > %s' % (basename, basename, out_file)
343 subprocess.check_call(diff_cmd, shell=True)
344 bb.utils.remove(src_patched, recurse=True)
345 finally:
346 os.chdir(cwd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500347
Brad Bishop316dfdd2018-06-25 12:45:53 -0400348def is_work_shared(d):
349 pn = d.getVar('PN')
350 return bb.data.inherits_class('kernel', d) or pn.startswith('gcc-source')
351
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352# Run do_unpack and do_patch
353python do_unpack_and_patch() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500354 if d.getVarFlag('ARCHIVER_MODE', 'src') not in \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500355 [ 'patched', 'configured'] and \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500356 d.getVarFlag('ARCHIVER_MODE', 'diff') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357 return
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500358 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
359 ar_workdir = d.getVar('ARCHIVER_WORKDIR')
360 ar_sysroot_native = d.getVar('STAGING_DIR_NATIVE')
361 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500362
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500363 # The kernel class functions require it to be on work-shared, so we dont change WORKDIR
Brad Bishop316dfdd2018-06-25 12:45:53 -0400364 if not is_work_shared(d):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500365 # Change the WORKDIR to make do_unpack do_patch run in another dir.
366 d.setVar('WORKDIR', ar_workdir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500367 # Restore the original path to recipe's native sysroot (it's relative to WORKDIR).
368 d.setVar('STAGING_DIR_NATIVE', ar_sysroot_native)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500369
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500370 # The changed 'WORKDIR' also caused 'B' changed, create dir 'B' for the
371 # possibly requiring of the following tasks (such as some recipes's
372 # do_patch required 'B' existed).
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500373 bb.utils.mkdirhier(d.getVar('B'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500374
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500375 bb.build.exec_func('do_unpack', d)
376
377 # Save the original source for creating the patches
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500378 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1':
379 src = d.getVar('S').rstrip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500380 src_orig = '%s.orig' % src
381 oe.path.copytree(src, src_orig)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500382
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500383 # Make sure gcc and kernel sources are patched only once
Brad Bishop316dfdd2018-06-25 12:45:53 -0400384 if not (d.getVar('SRC_URI') == "" or is_work_shared(d)):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500385 bb.build.exec_func('do_patch', d)
386
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500387 # Create the patches
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500388 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500389 bb.note('Creating diff gz...')
390 create_diff_gz(d, src_orig, src, ar_outdir)
391 bb.utils.remove(src_orig, recurse=True)
392}
393
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500394# BBINCLUDED is special (excluded from basehash signature
395# calculation). Using it in a task signature can cause "basehash
396# changed" errors.
397#
398# Depending on BBINCLUDED also causes do_ar_recipe to run again
399# for unrelated changes, like adding or removing buildhistory.bbclass.
400#
401# For these reasons we ignore the dependency completely. The versioning
402# of the output file ensures that we create it each time the recipe
403# gets rebuilt, at least as long as a PR server is used. We also rely
404# on that mechanism to catch changes in the file content, because the
405# file content is not part of of the task signature either.
406do_ar_recipe[vardepsexclude] += "BBINCLUDED"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500407python do_ar_recipe () {
408 """
409 archive the recipe, including .bb and .inc.
410 """
411 import re
412 import shutil
413
414 require_re = re.compile( r"require\s+(.+)" )
415 include_re = re.compile( r"include\s+(.+)" )
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500416 bbfile = d.getVar('FILE')
417 outdir = os.path.join(d.getVar('WORKDIR'), \
418 '%s-recipe' % d.getVar('PF'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500419 bb.utils.mkdirhier(outdir)
420 shutil.copy(bbfile, outdir)
421
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500422 pn = d.getVar('PN')
423 bbappend_files = d.getVar('BBINCLUDED').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500424 # If recipe name is aa, we need to match files like aa.bbappend and aa_1.1.bbappend
425 # Files like aa1.bbappend or aa1_1.1.bbappend must be excluded.
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500426 bbappend_re = re.compile( r".*/%s_[^/]*\.bbappend$" % re.escape(pn))
427 bbappend_re1 = re.compile( r".*/%s\.bbappend$" % re.escape(pn))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500428 for file in bbappend_files:
429 if bbappend_re.match(file) or bbappend_re1.match(file):
430 shutil.copy(file, outdir)
431
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500432 dirname = os.path.dirname(bbfile)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500433 bbpath = '%s:%s' % (dirname, d.getVar('BBPATH'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500434 f = open(bbfile, 'r')
435 for line in f.readlines():
436 incfile = None
437 if require_re.match(line):
438 incfile = require_re.match(line).group(1)
439 elif include_re.match(line):
440 incfile = include_re.match(line).group(1)
441 if incfile:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500442 incfile = d.expand(incfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500443 incfile = bb.utils.which(bbpath, incfile)
444 if incfile:
445 shutil.copy(incfile, outdir)
446
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500447 create_tarball(d, outdir, 'recipe', d.getVar('ARCHIVER_OUTDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500448 bb.utils.remove(outdir, recurse=True)
449}
450
451python do_dumpdata () {
452 """
453 dump environment data to ${PF}-showdata.dump
454 """
455
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500456 dumpfile = os.path.join(d.getVar('ARCHIVER_OUTDIR'), \
457 '%s-showdata.dump' % d.getVar('PF'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500458 bb.note('Dumping metadata into %s' % dumpfile)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500459 with open(dumpfile, "w") as f:
460 # emit variables and shell functions
461 bb.data.emit_env(f, d, True)
462 # emit the metadata which isn't valid shell
463 for e in d.keys():
464 if d.getVarFlag(e, "python", False):
465 f.write("\npython %s () {\n%s}\n" % (e, d.getVar(e, False)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500466}
467
468SSTATETASKS += "do_deploy_archives"
469do_deploy_archives () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500470 echo "Deploying source archive files from ${ARCHIVER_TOPDIR} to ${DEPLOY_DIR_SRC}."
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500471}
472python do_deploy_archives_setscene () {
473 sstate_setscene(d)
474}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500475do_deploy_archives[dirs] = "${ARCHIVER_TOPDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500476do_deploy_archives[sstate-inputdirs] = "${ARCHIVER_TOPDIR}"
477do_deploy_archives[sstate-outputdirs] = "${DEPLOY_DIR_SRC}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500478addtask do_deploy_archives_setscene
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500479
480addtask do_ar_original after do_unpack
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500481addtask do_unpack_and_patch after do_patch
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500482addtask do_ar_patched after do_unpack_and_patch
483addtask do_ar_configured after do_unpack_and_patch
484addtask do_dumpdata
485addtask do_ar_recipe
486addtask do_deploy_archives before do_build
487
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500488python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500489 # Add tasks in the correct order, specifically for linux-yocto to avoid race condition.
490 # sstatesig.py:sstate_rundepfilter has special support that excludes this dependency
491 # so that do_kernel_configme does not need to run again when do_unpack_and_patch
492 # gets added or removed (by adding or removing archiver.bbclass).
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500493 if bb.data.inherits_class('kernel-yocto', d):
494 bb.build.addtask('do_kernel_configme', 'do_configure', 'do_unpack_and_patch', d)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500495}