aboutsummaryrefslogtreecommitdiffstats
path: root/meta-mel/recipes-devtools/python/python3_%.bbappend
blob: 3330ed557960a35e06cc201cce2f91c59c01fc37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# ---------------------------------------------------------------------------------------------------------------------
# SPDX-License-Identifier: MIT
# ---------------------------------------------------------------------------------------------------------------------

# Needed by patchinfo
PATCHINFO_PYTHONPATH = "${COMPONENTS_DIR}/${BUILD_ARCH}/python3-unidiff-native/${libdir}/python${PYTHON_MAJMIN}/site-packages"
DEPENDS_UNIDIFF = ""
DEPENDS_UNIDIFF:mel:class-target = "python3-unidiff-native:do_populate_sysroot"
do_archive_release_downloads[depends] += "${DEPENDS_UNIDIFF}"

# Write patch names and modified files to python3-patches.txt
python do_archive_release_downloads:append:mel:class-target () {
    import csv
    import json
    from collections import defaultdict
    from pathlib import Path

    sources_dir = Path(sources_dir)
    layerdir = d.getVar('LAYERDIR_mel')
    script = Path(layerdir).parent / 'scripts' / 'patchinfo'
    if not script.exists():
        bb.fatal('Expected {} script does not exist'.format(str(script)))
    
    python = d.getVar('PYTHON')
    env = os.environ.copy()
    env['PYTHONPATH'] = d.getVar('PATCHINFO_PYTHONPATH')

    patchinfos = []
    patches = [bb.fetch.decodeurl(u)[2] for u in src_patches(d)]
    for patch in patches:
        try:
            info, _ = bb.process.run([python, str(script), patch], cwd=sources_dir, env=env)
        except bb.process.ExecutionError as exc:
            bb.warn("Failed to get patchinfo for %s: %s" % (patch, exc))
            continue
        else:
            try:
                patchinfo = json.loads(info)
            except json.decoder.JSONDecodeError as exc:
                bb.warn("Failed to decode json from patchinfo for %s" % patch)
                continue
            else:
                if 'Filename' in patchinfo and 'Files' in patchinfo:
                    patchinfos.append(patchinfo)
                else:
                    bb.warn("Unexpected json contents for patchinfo for %s" % patch)
    
    with open(sources_dir / 'python3-patches.txt', 'w') as f:
        for patchinfo in patchinfos:
            patch, files = patchinfo['Filename'], patchinfo['Files']
            f.write(patch + ':\n')
            for fn in files:
                f.write('  ' + fn + '\n')
}