archiver.bbclass 26 KB

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