blob: 9ff9956fe9094acbbfc07e00302dba0af9260ddc [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007# Deploy sources for recipes for compliance with copyleft-style licenses
8# Defaults to using symlinks, as it's a quick operation, and one can easily
9# follow the links when making use of the files (e.g. tar with the -h arg).
10#
11# vi:sts=4:sw=4:et
12
13inherit copyleft_filter
14
15COPYLEFT_SOURCES_DIR ?= '${DEPLOY_DIR}/copyleft_sources'
16
17python do_prepare_copyleft_sources () {
18 """Populate a tree of the recipe sources and emit patch series files"""
19 import os.path
20 import shutil
21
Brad Bishop6e60e8b2018-02-01 10:27:11 -050022 p = d.getVar('P')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 included, reason = copyleft_should_include(d)
24 if not included:
25 bb.debug(1, 'copyleft: %s is excluded: %s' % (p, reason))
26 return
27 else:
28 bb.debug(1, 'copyleft: %s is included: %s' % (p, reason))
29
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 sources_dir = d.getVar('COPYLEFT_SOURCES_DIR')
31 dl_dir = d.getVar('DL_DIR')
32 src_uri = d.getVar('SRC_URI').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033 fetch = bb.fetch2.Fetch(src_uri, d)
34 ud = fetch.ud
35
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036 pf = d.getVar('PF')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037 dest = os.path.join(sources_dir, pf)
38 shutil.rmtree(dest, ignore_errors=True)
39 bb.utils.mkdirhier(dest)
40
41 for u in ud.values():
42 local = os.path.normpath(fetch.localpath(u.url))
43 if local.endswith('.bb'):
44 continue
45 elif local.endswith('/'):
46 local = local[:-1]
47
48 if u.mirrortarball:
49 tarball_path = os.path.join(dl_dir, u.mirrortarball)
50 if os.path.exists(tarball_path):
51 local = tarball_path
52
53 oe.path.symlink(local, os.path.join(dest, os.path.basename(local)), force=True)
54
55 patches = src_patches(d)
56 for patch in patches:
57 _, _, local, _, _, parm = bb.fetch.decodeurl(patch)
58 patchdir = parm.get('patchdir')
59 if patchdir:
60 series = os.path.join(dest, 'series.subdir.%s' % patchdir.replace('/', '_'))
61 else:
62 series = os.path.join(dest, 'series')
63
64 with open(series, 'a') as s:
65 s.write('%s -p%s\n' % (os.path.basename(local), parm['striplevel']))
66}
67
68addtask prepare_copyleft_sources after do_fetch before do_build
69do_prepare_copyleft_sources[dirs] = "${WORKDIR}"
70do_build[recrdeptask] += 'do_prepare_copyleft_sources'