summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-07-23 00:38:10 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-07-25 23:47:02 +0100
commit4d059e02099e6244765027f2771192434764c606 (patch)
tree451c39b2b38f45f7ddb46e734ed16a52ef2eb3a6
parented0d8ed72370df694f720cc13897493478dc1de9 (diff)
downloadopenembedded-core-4d059e02099e6244765027f2771192434764c606.tar.gz
openembedded-core-4d059e02099e6244765027f2771192434764c606.tar.bz2
openembedded-core-4d059e02099e6244765027f2771192434764c606.zip
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. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xscripts/oe-check-sstate121
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 @@
+#!/usr/bin/env python3
+
+# Query which tasks will be restored from sstate
+#
+# Copyright 2016 Intel Corporation
+# Authored-by: Paul Eggleton <paul.eggleton@intel.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import sys
+import os
+import subprocess
+import tempfile
+import shutil
+import re
+
+scripts_path = os.path.dirname(os.path.realpath(__file__))
+lib_path = scripts_path + '/lib'
+sys.path = sys.path + [lib_path]
+import scriptutils
+import scriptpath
+scriptpath.add_bitbake_lib_path()
+import argparse_oe
+
+
+def translate_virtualfns(tasks):
+ import bb.tinfoil
+ tinfoil = bb.tinfoil.Tinfoil()
+ try:
+ tinfoil.prepare(False)
+
+ pkg_fn = tinfoil.cooker.recipecache.pkg_fn
+ outtasks = []
+ for task in tasks:
+ fn, taskname = task.rsplit(':', 1)
+ if taskname.endswith('_setscene'):
+ taskname = taskname[:-9]
+ outtasks.append('%s:%s' % (pkg_fn[fn], taskname))
+ finally:
+ tinfoil.shutdown()
+ return outtasks
+
+
+def check(args):
+ tmpdir = tempfile.mkdtemp(prefix='oe-check-sstate-')
+ try:
+ env = os.environ.copy()
+ if not args.same_tmpdir:
+ env['BB_ENV_EXTRAWHITE'] = env.get('BB_ENV_EXTRAWHITE', '') + ' TMPDIR_forcevariable'
+ env['TMPDIR_forcevariable'] = tmpdir
+
+ try:
+ output = subprocess.check_output(
+ 'bitbake -n %s' % ' '.join(args.target),
+ stderr=subprocess.STDOUT,
+ env=env,
+ shell=True)
+
+ task_re = re.compile('NOTE: Running setscene task [0-9]+ of [0-9]+ \(([^)]+)\)')
+ tasks = []
+ for line in output.decode('utf-8').splitlines():
+ res = task_re.match(line)
+ if res:
+ tasks.append(res.group(1))
+ outtasks = translate_virtualfns(tasks)
+ except subprocess.CalledProcessError as e:
+ print('ERROR: bitbake failed:\n%s' % e.output.decode('utf-8'))
+ return e.returncode
+ finally:
+ shutil.rmtree(tmpdir)
+
+ if args.log:
+ with open(args.log, 'wb') as f:
+ f.write(output)
+
+ if args.outfile:
+ with open(args.outfile, 'w') as f:
+ for task in outtasks:
+ f.write('%s\n' % task)
+ else:
+ for task in outtasks:
+ print(task)
+
+ return 0
+
+
+def main():
+ 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.')
+
+ parser.add_argument('target', nargs='+', help='Target to check')
+ parser.add_argument('-o', '--outfile', help='Write list to a file instead of stdout')
+ parser.add_argument('-l', '--log', help='Write full log to a file')
+ 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)')
+
+ parser.set_defaults(func=check)
+
+ args = parser.parse_args()
+
+ ret = args.func(args)
+ return ret
+
+
+if __name__ == "__main__":
+ try:
+ ret = main()
+ except Exception:
+ ret = 1
+ import traceback
+ traceback.print_exc()
+ sys.exit(ret)