blob: 0a9fe4fd1d6bf2f177877e194c88090fd88be26b [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}"
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 Bishop6e60e8b2018-02-01 10:27:11 -050081 ar_src = d.getVarFlag('ARCHIVER_MODE', 'src')
82 ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata')
83 ar_recipe = d.getVarFlag('ARCHIVER_MODE', 'recipe')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084
85 if ar_src == "original":
86 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_original' % pn)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050087 # 'patched' and 'configured' invoke do_unpack_and_patch because
88 # do_ar_patched resp. do_ar_configured depend on it, but for 'original'
89 # we have to add it explicitly.
90 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1':
91 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_unpack_and_patch' % pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050092 elif ar_src == "patched":
93 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_ar_patched' % pn)
94 elif ar_src == "configured":
95 # We can't use "addtask do_ar_configured after do_configure" since it
96 # will cause the deptask of do_populate_sysroot to run not matter what
97 # archives we need, so we add the depends here.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050098
99 # There is a corner case with "gcc-source-${PV}" recipes, they don't have
100 # the "do_configure" task, so we need to use "do_preconfigure"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800101 def hasTask(task):
102 return bool(d.getVarFlag(task, "task", False)) and not bool(d.getVarFlag(task, "noexec", False))
103
104 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'):
121 if "package_rpm" in d.getVar('PACKAGE_CLASSES'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 d.appendVarFlag('do_deploy_archives', 'depends', ' %s:do_package_write_rpm' % pn)
123 if ar_dumpdata == "1":
124 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_dumpdata' % pn)
125 if ar_recipe == "1":
126 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_recipe' % pn)
127 if ar_src == "original":
128 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_original' % pn)
129 elif ar_src == "patched":
130 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_patched' % pn)
131 elif ar_src == "configured":
132 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_configured' % pn)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400133 else:
134 bb.fatal("ARCHIVER_MODE[srpm] needs package_rpm in PACKAGE_CLASSES")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135}
136
137# Take all the sources for a recipe and puts them in WORKDIR/archiver-work/.
138# Files in SRC_URI are copied directly, anything that's a directory
139# (e.g. git repositories) is "unpacked" and then put into a tarball.
140python do_ar_original() {
141
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500142 import shutil, tempfile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500143
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500144 if d.getVarFlag('ARCHIVER_MODE', 'src') != "original":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500145 return
146
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500147 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148 bb.note('Archiving the original source...')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500149 urls = d.getVar("SRC_URI").split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600150 # destsuffix (git fetcher) and subdir (everything else) are allowed to be
151 # absolute paths (for example, destsuffix=${S}/foobar).
152 # That messes with unpacking inside our tmpdir below, because the fetchers
153 # will then unpack in that directory and completely ignore the tmpdir.
154 # That breaks parallel tasks relying on ${S}, like do_compile.
155 #
156 # To solve this, we remove these parameters from all URLs.
157 # We do this even for relative paths because it makes the content of the
158 # archives more useful (no extra paths that are only used during
159 # compilation).
160 for i, url in enumerate(urls):
161 decoded = bb.fetch2.decodeurl(url)
162 for param in ('destsuffix', 'subdir'):
163 if param in decoded[5]:
164 del decoded[5][param]
165 encoded = bb.fetch2.encodeurl(decoded)
166 urls[i] = encoded
167 fetch = bb.fetch2.Fetch(urls, d)
168 tarball_suffix = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500169 for url in fetch.urls:
170 local = fetch.localpath(url).rstrip("/");
171 if os.path.isfile(local):
172 shutil.copy(local, ar_outdir)
173 elif os.path.isdir(local):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500174 tmpdir = tempfile.mkdtemp(dir=d.getVar('ARCHIVER_WORKDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175 fetch.unpack(tmpdir, (url,))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600176 # To handle recipes with more than one source, we add the "name"
177 # URL parameter as suffix. We treat it as an error when
178 # there's more than one URL without a name, or a name gets reused.
179 # This is an additional safety net, in practice the name has
180 # to be set when using the git fetcher, otherwise SRCREV cannot
181 # be set separately for each URL.
182 params = bb.fetch2.decodeurl(url)[5]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500183 type = bb.fetch2.decodeurl(url)[0]
184 location = bb.fetch2.decodeurl(url)[2]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600185 name = params.get('name', '')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500186 if type.lower() == 'file':
187 name_tmp = location.rstrip("*").rstrip("/")
188 name = os.path.basename(name_tmp)
189 else:
190 if name in tarball_suffix:
191 if not name:
192 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))
193 else:
194 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 -0600195 tarball_suffix[name] = url
196 create_tarball(d, tmpdir + '/.', name, ar_outdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500197
198 # Emit patch series files for 'original'
199 bb.note('Writing patch series files...')
200 for patch in src_patches(d):
201 _, _, local, _, _, parm = bb.fetch.decodeurl(patch)
202 patchdir = parm.get('patchdir')
203 if patchdir:
204 series = os.path.join(ar_outdir, 'series.subdir.%s' % patchdir.replace('/', '_'))
205 else:
206 series = os.path.join(ar_outdir, 'series')
207
208 with open(series, 'a') as s:
209 s.write('%s -p%s\n' % (os.path.basename(local), parm['striplevel']))
210}
211
212python do_ar_patched() {
213
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500214 if d.getVarFlag('ARCHIVER_MODE', 'src') != 'patched':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215 return
216
217 # Get the ARCHIVER_OUTDIR before we reset the WORKDIR
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500218 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
219 ar_workdir = d.getVar('ARCHIVER_WORKDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220 bb.note('Archiving the patched source...')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500221 d.setVar('WORKDIR', ar_workdir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500222 create_tarball(d, d.getVar('S'), 'patched', ar_outdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223}
224
225python do_ar_configured() {
226 import shutil
227
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500228 # Forcibly expand the sysroot paths as we're about to change WORKDIR
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500229 d.setVar('STAGING_DIR_HOST', d.getVar('STAGING_DIR_HOST'))
230 d.setVar('STAGING_DIR_TARGET', d.getVar('STAGING_DIR_TARGET'))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500231 d.setVar('RECIPE_SYSROOT', d.getVar('RECIPE_SYSROOT'))
232 d.setVar('RECIPE_SYSROOT_NATIVE', d.getVar('RECIPE_SYSROOT_NATIVE'))
233
234 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
235 if d.getVarFlag('ARCHIVER_MODE', 'src') == 'configured':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500236 bb.note('Archiving the configured source...')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500237 pn = d.getVar('PN')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500238 # "gcc-source-${PV}" recipes don't have "do_configure"
239 # task, so we need to run "do_preconfigure" instead
240 if pn.startswith("gcc-source-"):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500241 d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500242 bb.build.exec_func('do_preconfigure', d)
243
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 # The libtool-native's do_configure will remove the
245 # ${STAGING_DATADIR}/aclocal/libtool.m4, so we can't re-run the
246 # do_configure, we archive the already configured ${S} to
247 # instead of.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500248 elif pn != 'libtool-native':
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800249 def runTask(task):
250 prefuncs = d.getVarFlag(task, 'prefuncs') or ''
251 for func in prefuncs.split():
252 if func != "sysroot_cleansstate":
253 bb.build.exec_func(func, d)
254 bb.build.exec_func(task, d)
255 postfuncs = d.getVarFlag(task, 'postfuncs') or ''
256 for func in postfuncs.split():
257 if func != 'do_qa_configure':
258 bb.build.exec_func(func, d)
259
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500260 # Change the WORKDIR to make do_configure run in another dir.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500261 d.setVar('WORKDIR', d.getVar('ARCHIVER_WORKDIR'))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800262
263 preceeds = bb.build.preceedtask('do_configure', False, d)
264 for task in preceeds:
265 if task != 'do_patch' and task != 'do_prepare_recipe_sysroot':
266 runTask(task)
267 runTask('do_configure')
268
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500269 srcdir = d.getVar('S')
270 builddir = d.getVar('B')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500271 if srcdir != builddir:
272 if os.path.exists(builddir):
273 oe.path.copytree(builddir, os.path.join(srcdir, \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500274 'build.%s.ar_configured' % d.getVar('PF')))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500275 create_tarball(d, srcdir, 'configured', ar_outdir)
276}
277
Brad Bishopc4ea0752018-11-15 14:30:15 -0800278def exclude_useless_paths(tarinfo):
279 if tarinfo.isdir():
280 if tarinfo.name.endswith('/temp') or tarinfo.name.endswith('/patches') or tarinfo.name.endswith('/.pc'):
281 return None
282 elif tarinfo.name == 'temp' or tarinfo.name == 'patches' or tarinfo.name == '.pc':
283 return None
284 return tarinfo
285
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500286def create_tarball(d, srcdir, suffix, ar_outdir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500287 """
288 create the tarball from srcdir
289 """
290 import tarfile
291
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500292 # Make sure we are only creating a single tarball for gcc sources
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500293 if (d.getVar('SRC_URI') == ""):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500294 return
295
Brad Bishop316dfdd2018-06-25 12:45:53 -0400296 # For the kernel archive, srcdir may just be a link to the
297 # work-shared location. Use os.path.realpath to make sure
298 # that we archive the actual directory and not just the link.
299 srcdir = os.path.realpath(srcdir)
300
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500301 bb.utils.mkdirhier(ar_outdir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500302 if suffix:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500303 filename = '%s-%s.tar.gz' % (d.getVar('PF'), suffix)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500304 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500305 filename = '%s.tar.gz' % d.getVar('PF')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500306 tarname = os.path.join(ar_outdir, filename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500307
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500308 bb.note('Creating %s' % tarname)
309 tar = tarfile.open(tarname, 'w:gz')
Brad Bishopc4ea0752018-11-15 14:30:15 -0800310 tar.add(srcdir, arcname=os.path.basename(srcdir), filter=exclude_useless_paths)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500311 tar.close()
312
313# creating .diff.gz between source.orig and source
314def create_diff_gz(d, src_orig, src, ar_outdir):
315
316 import subprocess
317
318 if not os.path.isdir(src) or not os.path.isdir(src_orig):
319 return
320
321 # The diff --exclude can't exclude the file with path, so we copy
322 # the patched source, and remove the files that we'd like to
323 # exclude.
324 src_patched = src + '.patched'
325 oe.path.copyhardlinktree(src, src_patched)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500326 for i in d.getVarFlag('ARCHIVER_MODE', 'diff-exclude').split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500327 bb.utils.remove(os.path.join(src_orig, i), recurse=True)
328 bb.utils.remove(os.path.join(src_patched, i), recurse=True)
329
330 dirname = os.path.dirname(src)
331 basename = os.path.basename(src)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500332 bb.utils.mkdirhier(ar_outdir)
333 cwd = os.getcwd()
334 try:
335 os.chdir(dirname)
336 out_file = os.path.join(ar_outdir, '%s-diff.gz' % d.getVar('PF'))
337 diff_cmd = 'diff -Naur %s.orig %s.patched | gzip -c > %s' % (basename, basename, out_file)
338 subprocess.check_call(diff_cmd, shell=True)
339 bb.utils.remove(src_patched, recurse=True)
340 finally:
341 os.chdir(cwd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500342
Brad Bishop316dfdd2018-06-25 12:45:53 -0400343def is_work_shared(d):
344 pn = d.getVar('PN')
345 return bb.data.inherits_class('kernel', d) or pn.startswith('gcc-source')
346
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500347# Run do_unpack and do_patch
348python do_unpack_and_patch() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500349 if d.getVarFlag('ARCHIVER_MODE', 'src') not in \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500350 [ 'patched', 'configured'] and \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500351 d.getVarFlag('ARCHIVER_MODE', 'diff') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352 return
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500353 ar_outdir = d.getVar('ARCHIVER_OUTDIR')
354 ar_workdir = d.getVar('ARCHIVER_WORKDIR')
355 ar_sysroot_native = d.getVar('STAGING_DIR_NATIVE')
356 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500358 # The kernel class functions require it to be on work-shared, so we dont change WORKDIR
Brad Bishop316dfdd2018-06-25 12:45:53 -0400359 if not is_work_shared(d):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500360 # Change the WORKDIR to make do_unpack do_patch run in another dir.
361 d.setVar('WORKDIR', ar_workdir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500362 # Restore the original path to recipe's native sysroot (it's relative to WORKDIR).
363 d.setVar('STAGING_DIR_NATIVE', ar_sysroot_native)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500364
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500365 # The changed 'WORKDIR' also caused 'B' changed, create dir 'B' for the
366 # possibly requiring of the following tasks (such as some recipes's
367 # do_patch required 'B' existed).
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500368 bb.utils.mkdirhier(d.getVar('B'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500369
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500370 bb.build.exec_func('do_unpack', d)
371
372 # Save the original source for creating the patches
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500373 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1':
374 src = d.getVar('S').rstrip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500375 src_orig = '%s.orig' % src
376 oe.path.copytree(src, src_orig)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500377
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500378 # Make sure gcc and kernel sources are patched only once
Brad Bishop316dfdd2018-06-25 12:45:53 -0400379 if not (d.getVar('SRC_URI') == "" or is_work_shared(d)):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500380 bb.build.exec_func('do_patch', d)
381
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500382 # Create the patches
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500383 if d.getVarFlag('ARCHIVER_MODE', 'diff') == '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500384 bb.note('Creating diff gz...')
385 create_diff_gz(d, src_orig, src, ar_outdir)
386 bb.utils.remove(src_orig, recurse=True)
387}
388
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500389# BBINCLUDED is special (excluded from basehash signature
390# calculation). Using it in a task signature can cause "basehash
391# changed" errors.
392#
393# Depending on BBINCLUDED also causes do_ar_recipe to run again
394# for unrelated changes, like adding or removing buildhistory.bbclass.
395#
396# For these reasons we ignore the dependency completely. The versioning
397# of the output file ensures that we create it each time the recipe
398# gets rebuilt, at least as long as a PR server is used. We also rely
399# on that mechanism to catch changes in the file content, because the
400# file content is not part of of the task signature either.
401do_ar_recipe[vardepsexclude] += "BBINCLUDED"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500402python do_ar_recipe () {
403 """
404 archive the recipe, including .bb and .inc.
405 """
406 import re
407 import shutil
408
409 require_re = re.compile( r"require\s+(.+)" )
410 include_re = re.compile( r"include\s+(.+)" )
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500411 bbfile = d.getVar('FILE')
412 outdir = os.path.join(d.getVar('WORKDIR'), \
413 '%s-recipe' % d.getVar('PF'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500414 bb.utils.mkdirhier(outdir)
415 shutil.copy(bbfile, outdir)
416
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500417 pn = d.getVar('PN')
418 bbappend_files = d.getVar('BBINCLUDED').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500419 # If recipe name is aa, we need to match files like aa.bbappend and aa_1.1.bbappend
420 # Files like aa1.bbappend or aa1_1.1.bbappend must be excluded.
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500421 bbappend_re = re.compile( r".*/%s_[^/]*\.bbappend$" % re.escape(pn))
422 bbappend_re1 = re.compile( r".*/%s\.bbappend$" % re.escape(pn))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500423 for file in bbappend_files:
424 if bbappend_re.match(file) or bbappend_re1.match(file):
425 shutil.copy(file, outdir)
426
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500427 dirname = os.path.dirname(bbfile)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500428 bbpath = '%s:%s' % (dirname, d.getVar('BBPATH'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500429 f = open(bbfile, 'r')
430 for line in f.readlines():
431 incfile = None
432 if require_re.match(line):
433 incfile = require_re.match(line).group(1)
434 elif include_re.match(line):
435 incfile = include_re.match(line).group(1)
436 if incfile:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500437 incfile = d.expand(incfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500438 incfile = bb.utils.which(bbpath, incfile)
439 if incfile:
440 shutil.copy(incfile, outdir)
441
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500442 create_tarball(d, outdir, 'recipe', d.getVar('ARCHIVER_OUTDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500443 bb.utils.remove(outdir, recurse=True)
444}
445
446python do_dumpdata () {
447 """
448 dump environment data to ${PF}-showdata.dump
449 """
450
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500451 dumpfile = os.path.join(d.getVar('ARCHIVER_OUTDIR'), \
452 '%s-showdata.dump' % d.getVar('PF'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500453 bb.note('Dumping metadata into %s' % dumpfile)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500454 with open(dumpfile, "w") as f:
455 # emit variables and shell functions
456 bb.data.emit_env(f, d, True)
457 # emit the metadata which isn't valid shell
458 for e in d.keys():
459 if d.getVarFlag(e, "python", False):
460 f.write("\npython %s () {\n%s}\n" % (e, d.getVar(e, False)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500461}
462
463SSTATETASKS += "do_deploy_archives"
464do_deploy_archives () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500465 echo "Deploying source archive files from ${ARCHIVER_TOPDIR} to ${DEPLOY_DIR_SRC}."
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500466}
467python do_deploy_archives_setscene () {
468 sstate_setscene(d)
469}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500470do_deploy_archives[dirs] = "${ARCHIVER_TOPDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500471do_deploy_archives[sstate-inputdirs] = "${ARCHIVER_TOPDIR}"
472do_deploy_archives[sstate-outputdirs] = "${DEPLOY_DIR_SRC}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500473addtask do_deploy_archives_setscene
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500474
475addtask do_ar_original after do_unpack
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500476addtask do_unpack_and_patch after do_patch
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500477addtask do_ar_patched after do_unpack_and_patch
478addtask do_ar_configured after do_unpack_and_patch
479addtask do_dumpdata
480addtask do_ar_recipe
481addtask do_deploy_archives before do_build
482
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500483python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500484 # Add tasks in the correct order, specifically for linux-yocto to avoid race condition.
485 # sstatesig.py:sstate_rundepfilter has special support that excludes this dependency
486 # so that do_kernel_configme does not need to run again when do_unpack_and_patch
487 # gets added or removed (by adding or removing archiver.bbclass).
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500488 if bb.data.inherits_class('kernel-yocto', d):
489 bb.build.addtask('do_kernel_configme', 'do_configure', 'do_unpack_and_patch', d)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500490}