Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # Query which tasks will be restored from sstate |
| 4 | # |
| 5 | # Copyright 2016 Intel Corporation |
| 6 | # Authored-by: Paul Eggleton <paul.eggleton@intel.com> |
| 7 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 8 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 10 | |
| 11 | import sys |
| 12 | import os |
| 13 | import subprocess |
| 14 | import tempfile |
| 15 | import shutil |
| 16 | import re |
| 17 | |
| 18 | scripts_path = os.path.dirname(os.path.realpath(__file__)) |
| 19 | lib_path = scripts_path + '/lib' |
| 20 | sys.path = sys.path + [lib_path] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 21 | import scriptpath |
| 22 | scriptpath.add_bitbake_lib_path() |
| 23 | import argparse_oe |
| 24 | |
| 25 | |
| 26 | def translate_virtualfns(tasks): |
| 27 | import bb.tinfoil |
| 28 | tinfoil = bb.tinfoil.Tinfoil() |
| 29 | try: |
| 30 | tinfoil.prepare(False) |
| 31 | |
| 32 | recipecaches = tinfoil.cooker.recipecaches |
| 33 | outtasks = [] |
| 34 | for task in tasks: |
| 35 | (mc, fn, taskname) = bb.runqueue.split_tid(task) |
| 36 | if taskname.endswith('_setscene'): |
| 37 | taskname = taskname[:-9] |
| 38 | outtasks.append('%s:%s' % (recipecaches[mc].pkg_fn[fn], taskname)) |
| 39 | finally: |
| 40 | tinfoil.shutdown() |
| 41 | return outtasks |
| 42 | |
| 43 | |
| 44 | def check(args): |
| 45 | tmpdir = tempfile.mkdtemp(prefix='oe-check-sstate-') |
| 46 | try: |
| 47 | env = os.environ.copy() |
| 48 | if not args.same_tmpdir: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 49 | env['BB_ENV_PASSTHROUGH_ADDITIONS'] = env.get('BB_ENV_PASSTHROUGH_ADDITIONS', '') + ' TMPDIR:forcevariable' |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 50 | env['TMPDIR:forcevariable'] = tmpdir |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 51 | |
| 52 | try: |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 53 | cmd = ['bitbake', '--dry-run', '--runall=build'] + args.target |
| 54 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 55 | |
| 56 | task_re = re.compile('NOTE: Running setscene task [0-9]+ of [0-9]+ \(([^)]+)\)') |
| 57 | tasks = [] |
| 58 | for line in output.decode('utf-8').splitlines(): |
| 59 | res = task_re.match(line) |
| 60 | if res: |
| 61 | tasks.append(res.group(1)) |
| 62 | outtasks = translate_virtualfns(tasks) |
| 63 | except subprocess.CalledProcessError as e: |
| 64 | print('ERROR: bitbake failed:\n%s' % e.output.decode('utf-8')) |
| 65 | return e.returncode |
| 66 | finally: |
| 67 | shutil.rmtree(tmpdir) |
| 68 | |
| 69 | if args.log: |
| 70 | with open(args.log, 'wb') as f: |
| 71 | f.write(output) |
| 72 | |
| 73 | if args.outfile: |
| 74 | with open(args.outfile, 'w') as f: |
| 75 | for task in outtasks: |
| 76 | f.write('%s\n' % task) |
| 77 | else: |
| 78 | for task in outtasks: |
| 79 | print(task) |
| 80 | |
| 81 | return 0 |
| 82 | |
| 83 | |
| 84 | def main(): |
| 85 | parser = argparse_oe.ArgumentParser(description='OpenEmbedded sstate check tool. Does a dry-run to check restoring the specified targets from shared state, and lists the tasks that would be restored. Set BB_SETSCENE_ENFORCE=1 in the environment if you wish to ensure real tasks are disallowed.') |
| 86 | |
| 87 | parser.add_argument('target', nargs='+', help='Target to check') |
| 88 | parser.add_argument('-o', '--outfile', help='Write list to a file instead of stdout') |
| 89 | parser.add_argument('-l', '--log', help='Write full log to a file') |
| 90 | parser.add_argument('-s', '--same-tmpdir', action='store_true', help='Use same TMPDIR for check (list will then be dependent on what tasks have executed previously)') |
| 91 | |
| 92 | parser.set_defaults(func=check) |
| 93 | |
| 94 | args = parser.parse_args() |
| 95 | |
| 96 | ret = args.func(args) |
| 97 | return ret |
| 98 | |
| 99 | |
| 100 | if __name__ == "__main__": |
| 101 | try: |
| 102 | ret = main() |
| 103 | except Exception: |
| 104 | ret = 1 |
| 105 | import traceback |
| 106 | traceback.print_exc() |
| 107 | sys.exit(ret) |