xref: /OK3568_Linux_fs/yocto/poky/meta/classes/copyleft_compliance.bbclass (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# Deploy sources for recipes for compliance with copyleft-style licenses
2*4882a593Smuzhiyun# Defaults to using symlinks, as it's a quick operation, and one can easily
3*4882a593Smuzhiyun# follow the links when making use of the files (e.g. tar with the -h arg).
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun# vi:sts=4:sw=4:et
6*4882a593Smuzhiyun
7*4882a593Smuzhiyuninherit copyleft_filter
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunCOPYLEFT_SOURCES_DIR ?= '${DEPLOY_DIR}/copyleft_sources'
10*4882a593Smuzhiyun
11*4882a593Smuzhiyunpython do_prepare_copyleft_sources () {
12*4882a593Smuzhiyun    """Populate a tree of the recipe sources and emit patch series files"""
13*4882a593Smuzhiyun    import os.path
14*4882a593Smuzhiyun    import shutil
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun    p = d.getVar('P')
17*4882a593Smuzhiyun    included, reason = copyleft_should_include(d)
18*4882a593Smuzhiyun    if not included:
19*4882a593Smuzhiyun        bb.debug(1, 'copyleft: %s is excluded: %s' % (p, reason))
20*4882a593Smuzhiyun        return
21*4882a593Smuzhiyun    else:
22*4882a593Smuzhiyun        bb.debug(1, 'copyleft: %s is included: %s' % (p, reason))
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun    sources_dir = d.getVar('COPYLEFT_SOURCES_DIR')
25*4882a593Smuzhiyun    dl_dir = d.getVar('DL_DIR')
26*4882a593Smuzhiyun    src_uri = d.getVar('SRC_URI').split()
27*4882a593Smuzhiyun    fetch = bb.fetch2.Fetch(src_uri, d)
28*4882a593Smuzhiyun    ud = fetch.ud
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun    pf = d.getVar('PF')
31*4882a593Smuzhiyun    dest = os.path.join(sources_dir, pf)
32*4882a593Smuzhiyun    shutil.rmtree(dest, ignore_errors=True)
33*4882a593Smuzhiyun    bb.utils.mkdirhier(dest)
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun    for u in ud.values():
36*4882a593Smuzhiyun        local = os.path.normpath(fetch.localpath(u.url))
37*4882a593Smuzhiyun        if local.endswith('.bb'):
38*4882a593Smuzhiyun            continue
39*4882a593Smuzhiyun        elif local.endswith('/'):
40*4882a593Smuzhiyun            local = local[:-1]
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun        if u.mirrortarball:
43*4882a593Smuzhiyun            tarball_path = os.path.join(dl_dir, u.mirrortarball)
44*4882a593Smuzhiyun            if os.path.exists(tarball_path):
45*4882a593Smuzhiyun                local = tarball_path
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun        oe.path.symlink(local, os.path.join(dest, os.path.basename(local)), force=True)
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun    patches = src_patches(d)
50*4882a593Smuzhiyun    for patch in patches:
51*4882a593Smuzhiyun        _, _, local, _, _, parm = bb.fetch.decodeurl(patch)
52*4882a593Smuzhiyun        patchdir = parm.get('patchdir')
53*4882a593Smuzhiyun        if patchdir:
54*4882a593Smuzhiyun            series = os.path.join(dest, 'series.subdir.%s' % patchdir.replace('/', '_'))
55*4882a593Smuzhiyun        else:
56*4882a593Smuzhiyun            series = os.path.join(dest, 'series')
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun        with open(series, 'a') as s:
59*4882a593Smuzhiyun            s.write('%s -p%s\n' % (os.path.basename(local), parm['striplevel']))
60*4882a593Smuzhiyun}
61*4882a593Smuzhiyun
62*4882a593Smuzhiyunaddtask prepare_copyleft_sources after do_fetch before do_build
63*4882a593Smuzhiyundo_prepare_copyleft_sources[dirs] = "${WORKDIR}"
64*4882a593Smuzhiyundo_build[recrdeptask] += 'do_prepare_copyleft_sources'
65