oe-setup-layers 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright OpenEmbedded Contributors
  4. #
  5. # SPDX-License-Identifier: MIT
  6. #
  7. # This file was copied from poky(or oe-core)/scripts/oe-setup-layers by running
  8. #
  9. # bitbake-layers create-layers-setup destdir
  10. #
  11. # It is recommended that you do not modify this file directly, but rather re-run the above command to get the freshest upstream copy.
  12. import argparse
  13. import json
  14. import os
  15. import subprocess
  16. def _do_checkout(args, json):
  17. layers = json['sources']
  18. for l_name in layers:
  19. l_data = layers[l_name]
  20. layerdir = os.path.abspath(os.path.join(args['destdir'], l_data['path']))
  21. if 'contains_this_file' in l_data.keys():
  22. force_arg = 'force_bootstraplayer_checkout'
  23. if not args[force_arg]:
  24. print('Note: not checking out source {layer}, use {layerflag} to override.'.format(layer=l_name, layerflag='--force-bootstraplayer-checkout'))
  25. continue
  26. l_remote = l_data['git-remote']
  27. rev = l_remote['rev']
  28. desc = l_remote['describe']
  29. if not desc:
  30. desc = rev[:10]
  31. branch = l_remote['branch']
  32. remotes = l_remote['remotes']
  33. print('\nSetting up source {}, revision {}, branch {}'.format(l_name, desc, branch))
  34. cmd = 'git init -q {}'.format(layerdir)
  35. print("Running '{}'".format(cmd))
  36. subprocess.check_output(cmd, shell=True)
  37. for remote in remotes:
  38. cmd = "git remote remove {} > /dev/null 2>&1; git remote add {} {}".format(remote, remote, remotes[remote]['uri'])
  39. print("Running '{}' in {}".format(cmd, layerdir))
  40. subprocess.check_output(cmd, shell=True, cwd=layerdir)
  41. cmd = "git fetch -q {} || true".format(remote)
  42. print("Running '{}' in {}".format(cmd, layerdir))
  43. subprocess.check_output(cmd, shell=True, cwd=layerdir)
  44. cmd = 'git checkout -q {}'.format(rev)
  45. print("Running '{}' in {}".format(cmd, layerdir))
  46. subprocess.check_output(cmd, shell=True, cwd=layerdir)
  47. parser = argparse.ArgumentParser(description="A self contained python script that fetches all the needed layers and sets them to correct revisions using data in a json format from a separate file. The json data can be created from an active build directory with 'bitbake-layers create-layers-setup destdir' and there's a sample file and a schema in meta/files/")
  48. parser.add_argument('--force-bootstraplayer-checkout', action='store_true',
  49. help='Force the checkout of the layer containing this file (by default it is presumed that as this script is in it, the layer is already in place).')
  50. try:
  51. defaultdest = os.path.dirname(subprocess.check_output('git rev-parse --show-toplevel', universal_newlines=True, shell=True, cwd=os.path.dirname(__file__)))
  52. except subprocess.CalledProcessError as e:
  53. defaultdest = os.path.abspath(".")
  54. parser.add_argument('--destdir', default=defaultdest, help='Where to check out the layers (default is {defaultdest}).'.format(defaultdest=defaultdest))
  55. parser.add_argument('--jsondata', default=__file__+".json", help='File containing the layer data in json format (default is {defaultjson}).'.format(defaultjson=__file__+".json"))
  56. args = parser.parse_args()
  57. with open(args.jsondata) as f:
  58. json = json.load(f)
  59. supported_versions = ["1.0"]
  60. if json["version"] not in supported_versions:
  61. raise Exception("File {} has version {}, which is not in supported versions: {}".format(args.jsondata, json["version"], supported_versions))
  62. _do_checkout(vars(args), json)