]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/blame - scripts/oe-check-sstate
cargo.bbclass: use offline mode for building
[thirdparty/openembedded/openembedded-core.git] / scripts / oe-check-sstate
CommitLineData
4d059e02
PE
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#
f8c9c511 8# SPDX-License-Identifier: GPL-2.0-only
4d059e02 9#
4d059e02
PE
10
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]
4d059e02
PE
21import 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
041212fa 32 recipecaches = tinfoil.cooker.recipecaches
4d059e02
PE
33 outtasks = []
34 for task in tasks:
041212fa 35 (mc, fn, taskname) = bb.runqueue.split_tid(task)
4d059e02
PE
36 if taskname.endswith('_setscene'):
37 taskname = taskname[:-9]
041212fa 38 outtasks.append('%s:%s' % (recipecaches[mc].pkg_fn[fn], taskname))
4d059e02
PE
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:
193affb9 49 env['BB_ENV_PASSTHROUGH_ADDITIONS'] = env.get('BB_ENV_PASSTHROUGH_ADDITIONS', '') + ' TMPDIR:forcevariable'
42344347 50 env['TMPDIR:forcevariable'] = tmpdir
4d059e02
PE
51
52 try:
1b62344f 53 cmd = ['bitbake', '--dry-run', '--runall=build'] + args.target
663aa284 54 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env)
4d059e02
PE
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
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)