oe-check-sstate 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 scriptpath
  19. scriptpath.add_bitbake_lib_path()
  20. import argparse_oe
  21. def translate_virtualfns(tasks):
  22. import bb.tinfoil
  23. tinfoil = bb.tinfoil.Tinfoil()
  24. try:
  25. tinfoil.prepare(False)
  26. recipecaches = tinfoil.cooker.recipecaches
  27. outtasks = []
  28. for task in tasks:
  29. (mc, fn, taskname) = bb.runqueue.split_tid(task)
  30. if taskname.endswith('_setscene'):
  31. taskname = taskname[:-9]
  32. outtasks.append('%s:%s' % (recipecaches[mc].pkg_fn[fn], taskname))
  33. finally:
  34. tinfoil.shutdown()
  35. return outtasks
  36. def check(args):
  37. tmpdir = tempfile.mkdtemp(prefix='oe-check-sstate-')
  38. try:
  39. env = os.environ.copy()
  40. if not args.same_tmpdir:
  41. env['BB_ENV_PASSTHROUGH_ADDITIONS'] = env.get('BB_ENV_PASSTHROUGH_ADDITIONS', '') + ' TMPDIR:forcevariable'
  42. env['TMPDIR:forcevariable'] = tmpdir
  43. try:
  44. cmd = ['bitbake', '--dry-run', '--runall=build'] + args.target
  45. output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env)
  46. task_re = re.compile('NOTE: Running setscene task [0-9]+ of [0-9]+ \(([^)]+)\)')
  47. tasks = []
  48. for line in output.decode('utf-8').splitlines():
  49. res = task_re.match(line)
  50. if res:
  51. tasks.append(res.group(1))
  52. outtasks = translate_virtualfns(tasks)
  53. except subprocess.CalledProcessError as e:
  54. print('ERROR: bitbake failed:\n%s' % e.output.decode('utf-8'))
  55. return e.returncode
  56. finally:
  57. shutil.rmtree(tmpdir)
  58. if args.log:
  59. with open(args.log, 'wb') as f:
  60. f.write(output)
  61. if args.outfile:
  62. with open(args.outfile, 'w') as f:
  63. for task in outtasks:
  64. f.write('%s\n' % task)
  65. else:
  66. for task in outtasks:
  67. print(task)
  68. return 0
  69. def main():
  70. 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.')
  71. parser.add_argument('target', nargs='+', help='Target to check')
  72. parser.add_argument('-o', '--outfile', help='Write list to a file instead of stdout')
  73. parser.add_argument('-l', '--log', help='Write full log to a file')
  74. 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)')
  75. parser.set_defaults(func=check)
  76. args = parser.parse_args()
  77. ret = args.func(args)
  78. return ret
  79. if __name__ == "__main__":
  80. try:
  81. ret = main()
  82. except Exception:
  83. ret = 1
  84. import traceback
  85. traceback.print_exc()
  86. sys.exit(ret)