diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-07-23 00:38:10 +1200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-07-26 08:56:31 +0100 |
commit | 2ac1fdf53741f1943623df47c7a2bfa2a91544b9 (patch) | |
tree | a8bd37cec6d9f61c7bd2737c7f75542da5a5ab5c /scripts | |
parent | 4253e2e0f394f8ef2c30bbfec8672d64b9eb9c54 (diff) | |
download | poky-2ac1fdf53741f1943623df47c7a2bfa2a91544b9.tar.gz |
scripts: add oe-check-sstate script
Add a script to check which sstate artifacts would be installed by
building a given target - by default this is done with a separate
TMPDIR to ensure we get the "from scratch" result. The script produces a
list of tasks that will be restored from the sstate cache. This can also
be combined with BB_SETSCENE_ENFORCE* to check if sstate artifacts are
available.
The implementation is a little crude - we're running bitbake -n and
looking at the output. In future when we have the ability to execute
tasks from tinfoil-based scripts we can look at rewriting that part of
it to use that instead.
(From OE-Core rev: 4d059e02099e6244765027f2771192434764c606)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/oe-check-sstate | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/scripts/oe-check-sstate b/scripts/oe-check-sstate new file mode 100755 index 0000000000..8aab86adb3 --- /dev/null +++ b/scripts/oe-check-sstate | |||
@@ -0,0 +1,121 @@ | |||
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 | # | ||
8 | # This program is free software; you can redistribute it and/or modify | ||
9 | # it under the terms of the GNU General Public License version 2 as | ||
10 | # published by the Free Software Foundation. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | # | ||
17 | # You should have received a copy of the GNU General Public License along | ||
18 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
20 | |||
21 | import sys | ||
22 | import os | ||
23 | import subprocess | ||
24 | import tempfile | ||
25 | import shutil | ||
26 | import re | ||
27 | |||
28 | scripts_path = os.path.dirname(os.path.realpath(__file__)) | ||
29 | lib_path = scripts_path + '/lib' | ||
30 | sys.path = sys.path + [lib_path] | ||
31 | import scriptutils | ||
32 | import scriptpath | ||
33 | scriptpath.add_bitbake_lib_path() | ||
34 | import argparse_oe | ||
35 | |||
36 | |||
37 | def translate_virtualfns(tasks): | ||
38 | import bb.tinfoil | ||
39 | tinfoil = bb.tinfoil.Tinfoil() | ||
40 | try: | ||
41 | tinfoil.prepare(False) | ||
42 | |||
43 | pkg_fn = tinfoil.cooker.recipecache.pkg_fn | ||
44 | outtasks = [] | ||
45 | for task in tasks: | ||
46 | fn, taskname = task.rsplit(':', 1) | ||
47 | if taskname.endswith('_setscene'): | ||
48 | taskname = taskname[:-9] | ||
49 | outtasks.append('%s:%s' % (pkg_fn[fn], taskname)) | ||
50 | finally: | ||
51 | tinfoil.shutdown() | ||
52 | return outtasks | ||
53 | |||
54 | |||
55 | def check(args): | ||
56 | tmpdir = tempfile.mkdtemp(prefix='oe-check-sstate-') | ||
57 | try: | ||
58 | env = os.environ.copy() | ||
59 | if not args.same_tmpdir: | ||
60 | env['BB_ENV_EXTRAWHITE'] = env.get('BB_ENV_EXTRAWHITE', '') + ' TMPDIR_forcevariable' | ||
61 | env['TMPDIR_forcevariable'] = tmpdir | ||
62 | |||
63 | try: | ||
64 | output = subprocess.check_output( | ||
65 | 'bitbake -n %s' % ' '.join(args.target), | ||
66 | stderr=subprocess.STDOUT, | ||
67 | env=env, | ||
68 | shell=True) | ||
69 | |||
70 | task_re = re.compile('NOTE: Running setscene task [0-9]+ of [0-9]+ \(([^)]+)\)') | ||
71 | tasks = [] | ||
72 | for line in output.decode('utf-8').splitlines(): | ||
73 | res = task_re.match(line) | ||
74 | if res: | ||
75 | tasks.append(res.group(1)) | ||
76 | outtasks = translate_virtualfns(tasks) | ||
77 | except subprocess.CalledProcessError as e: | ||
78 | print('ERROR: bitbake failed:\n%s' % e.output.decode('utf-8')) | ||
79 | return e.returncode | ||
80 | finally: | ||
81 | shutil.rmtree(tmpdir) | ||
82 | |||
83 | if args.log: | ||
84 | with open(args.log, 'wb') as f: | ||
85 | f.write(output) | ||
86 | |||
87 | if args.outfile: | ||
88 | with open(args.outfile, 'w') as f: | ||
89 | for task in outtasks: | ||
90 | f.write('%s\n' % task) | ||
91 | else: | ||
92 | for task in outtasks: | ||
93 | print(task) | ||
94 | |||
95 | return 0 | ||
96 | |||
97 | |||
98 | def main(): | ||
99 | 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.') | ||
100 | |||
101 | parser.add_argument('target', nargs='+', help='Target to check') | ||
102 | parser.add_argument('-o', '--outfile', help='Write list to a file instead of stdout') | ||
103 | parser.add_argument('-l', '--log', help='Write full log to a file') | ||
104 | 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)') | ||
105 | |||
106 | parser.set_defaults(func=check) | ||
107 | |||
108 | args = parser.parse_args() | ||
109 | |||
110 | ret = args.func(args) | ||
111 | return ret | ||
112 | |||
113 | |||
114 | if __name__ == "__main__": | ||
115 | try: | ||
116 | ret = main() | ||
117 | except Exception: | ||
118 | ret = 1 | ||
119 | import traceback | ||
120 | traceback.print_exc() | ||
121 | sys.exit(ret) | ||