oe-check-sstate 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env python3
  2. # Query which tasks will be restored from sstate
  3. #
  4. # Copyright 2016 Intel Corporation
  5. # Authored-by: Paul Eggleton <paul.eggleton@intel.com>
  6. #
  7. # SPDX-License-Identifier: GPL-2.0-only
  8. #
  9. import sys
  10. import os
  11. import subprocess
  12. import tempfile
  13. import shutil
  14. import re
  15. scripts_path = os.path.dirname(os.path.realpath(__file__))
  16. lib_path = scripts_path + '/lib'
  17. sys.path = sys.path + [lib_path]
  18. import scriptutils
  19. import scriptpath
  20. scriptpath.add_bitbake_lib_path()
  21. import argparse_oe
  22. def translate_virtualfns(tasks):
  23. import bb.tinfoil
  24. tinfoil = bb.tinfoil.Tinfoil()
  25. try:
  26. tinfoil.prepare(False)
  27. recipecaches = tinfoil.cooker.recipecaches
  28. outtasks = []
  29. for task in tasks:
  30. (mc, fn, taskname) = bb.runqueue.split_tid(task)
  31. if taskname.endswith('_setscene'):
  32. taskname = taskname[:-9]
  33. outtasks.append('%s:%s' % (recipecaches[mc].pkg_fn[fn], taskname))
  34. finally:
  35. tinfoil.shutdown()
  36. return outtasks
  37. def check(args):
  38. tmpdir = tempfile.mkdtemp(prefix='oe-check-sstate-')
  39. try:
  40. env = os.environ.copy()
  41. if not args.same_tmpdir:
  42. env['BB_ENV_EXTRAWHITE'] = env.get('BB_ENV_EXTRAWHITE', '') + ' TMPDIR_forcevariable'
  43. env['TMPDIR_forcevariable'] = tmpdir
  44. try:
  45. output = subprocess.check_output(
  46. 'bitbake -n %s' % ' '.join(args.target),
  47. stderr=subprocess.STDOUT,
  48. env=env,
  49. shell=True)
  50. task_re = re.compile('NOTE: Running setscene task [0-9]+ of [0-9]+ \(([^)]+)\)')
  51. tasks = []
  52. for line in output.decode('utf-8').splitlines():
  53. res = task_re.match(line)
  54. if res:
  55. tasks.append(res.group(1))
  56. outtasks = translate_virtualfns(tasks)
  57. except subprocess.CalledProcessError as e:
  58. print('ERROR: bitbake failed:\n%s' % e.output.decode('utf-8'))
  59. return e.returncode
  60. finally:
  61. shutil.rmtree(tmpdir)
  62. if args.log:
  63. with open(args.log, 'wb') as f:
  64. f.write(output)
  65. if args.outfile:
  66. with open(args.outfile, 'w') as f:
  67. for task in outtasks:
  68. f.write('%s\n' % task)
  69. else:
  70. for task in outtasks:
  71. print(task)
  72. return 0
  73. def main():
  74. 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.')
  75. parser.add_argument('target', nargs='+', help='Target to check')
  76. parser.add_argument('-o', '--outfile', help='Write list to a file instead of stdout')
  77. parser.add_argument('-l', '--log', help='Write full log to a file')
  78. 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)')
  79. parser.set_defaults(func=check)
  80. args = parser.parse_args()
  81. ret = args.func(args)
  82. return ret
  83. if __name__ == "__main__":
  84. try:
  85. ret = main()
  86. except Exception:
  87. ret = 1
  88. import traceback
  89. traceback.print_exc()
  90. sys.exit(ret)