oe-check-sstate 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. import sys
  20. import os
  21. import subprocess
  22. import tempfile
  23. import shutil
  24. import re
  25. scripts_path = os.path.dirname(os.path.realpath(__file__))
  26. lib_path = scripts_path + '/lib'
  27. sys.path = sys.path + [lib_path]
  28. import scriptutils
  29. import scriptpath
  30. scriptpath.add_bitbake_lib_path()
  31. import argparse_oe
  32. def translate_virtualfns(tasks):
  33. import bb.tinfoil
  34. tinfoil = bb.tinfoil.Tinfoil()
  35. try:
  36. tinfoil.prepare(False)
  37. recipecaches = tinfoil.cooker.recipecaches
  38. outtasks = []
  39. for task in tasks:
  40. (mc, fn, taskname) = bb.runqueue.split_tid(task)
  41. if taskname.endswith('_setscene'):
  42. taskname = taskname[:-9]
  43. outtasks.append('%s:%s' % (recipecaches[mc].pkg_fn[fn], taskname))
  44. finally:
  45. tinfoil.shutdown()
  46. return outtasks
  47. def check(args):
  48. tmpdir = tempfile.mkdtemp(prefix='oe-check-sstate-')
  49. try:
  50. env = os.environ.copy()
  51. if not args.same_tmpdir:
  52. env['BB_ENV_EXTRAWHITE'] = env.get('BB_ENV_EXTRAWHITE', '') + ' TMPDIR_forcevariable'
  53. env['TMPDIR_forcevariable'] = tmpdir
  54. try:
  55. output = subprocess.check_output(
  56. 'bitbake -n %s' % ' '.join(args.target),
  57. stderr=subprocess.STDOUT,
  58. env=env,
  59. shell=True)
  60. task_re = re.compile('NOTE: Running setscene task [0-9]+ of [0-9]+ \(([^)]+)\)')
  61. tasks = []
  62. for line in output.decode('utf-8').splitlines():
  63. res = task_re.match(line)
  64. if res:
  65. tasks.append(res.group(1))
  66. outtasks = translate_virtualfns(tasks)
  67. except subprocess.CalledProcessError as e:
  68. print('ERROR: bitbake failed:\n%s' % e.output.decode('utf-8'))
  69. return e.returncode
  70. finally:
  71. shutil.rmtree(tmpdir)
  72. if args.log:
  73. with open(args.log, 'wb') as f:
  74. f.write(output)
  75. if args.outfile:
  76. with open(args.outfile, 'w') as f:
  77. for task in outtasks:
  78. f.write('%s\n' % task)
  79. else:
  80. for task in outtasks:
  81. print(task)
  82. return 0
  83. def main():
  84. 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.')
  85. parser.add_argument('target', nargs='+', help='Target to check')
  86. parser.add_argument('-o', '--outfile', help='Write list to a file instead of stdout')
  87. parser.add_argument('-l', '--log', help='Write full log to a file')
  88. 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)')
  89. parser.set_defaults(func=check)
  90. args = parser.parse_args()
  91. ret = args.func(args)
  92. return ret
  93. if __name__ == "__main__":
  94. try:
  95. ret = main()
  96. except Exception:
  97. ret = 1
  98. import traceback
  99. traceback.print_exc()
  100. sys.exit(ret)