blob: 4187e7745812252bfaf3f1f83a318f9678ebc1fa [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/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 Bishopc342db32019-05-15 21:57:59 -04008# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010
11import sys
12import os
13import subprocess
14import tempfile
15import shutil
16import re
17
18scripts_path = os.path.dirname(os.path.realpath(__file__))
19lib_path = scripts_path + '/lib'
20sys.path = sys.path + [lib_path]
Patrick Williamsc0f7c042017-02-23 20:41:17 -060021import scriptpath
22scriptpath.add_bitbake_lib_path()
23import argparse_oe
24
25
26def 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
44def check(args):
45 tmpdir = tempfile.mkdtemp(prefix='oe-check-sstate-')
46 try:
47 env = os.environ.copy()
48 if not args.same_tmpdir:
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000049 env['BB_ENV_PASSTHROUGH_ADDITIONS'] = env.get('BB_ENV_PASSTHROUGH_ADDITIONS', '') + ' TMPDIR:forcevariable'
Patrick Williams213cb262021-08-07 19:21:33 -050050 env['TMPDIR:forcevariable'] = tmpdir
Patrick Williamsc0f7c042017-02-23 20:41:17 -060051
52 try:
Patrick Williams2390b1b2022-11-03 13:47:49 -050053 cmd = ['bitbake', '--dry-run', '--runall=build'] + args.target
54 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060055
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
84def 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
100if __name__ == "__main__":
101 try:
102 ret = main()
103 except Exception:
104 ret = 1
105 import traceback
106 traceback.print_exc()
107 sys.exit(ret)