diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/oe-setup-layers | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/scripts/oe-setup-layers b/scripts/oe-setup-layers new file mode 100755 index 0000000000..cbd2efb5c7 --- /dev/null +++ b/scripts/oe-setup-layers | |||
@@ -0,0 +1,88 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | # | ||
3 | # Copyright OpenEmbedded Contributors | ||
4 | # | ||
5 | # SPDX-License-Identifier: MIT | ||
6 | # | ||
7 | |||
8 | # This file was copied from poky(or oe-core)/scripts/oe-setup-layers by running | ||
9 | # | ||
10 | # bitbake-layers create-layers-setup destdir | ||
11 | # | ||
12 | # It is recommended that you do not modify this file directly, but rather re-run the above command to get the freshest upstream copy. | ||
13 | |||
14 | import argparse | ||
15 | import json | ||
16 | import os | ||
17 | import subprocess | ||
18 | |||
19 | def _do_checkout(args, json): | ||
20 | layers = json['sources'] | ||
21 | buildconfs = [] | ||
22 | oecorepath = "" | ||
23 | for l_name in layers: | ||
24 | l_data = layers[l_name] | ||
25 | layerdir = os.path.abspath(os.path.join(args['destdir'], l_data['path'])) | ||
26 | |||
27 | for ll_name in l_data['layers']: | ||
28 | if ll_name == 'meta': | ||
29 | oecorepath = layerdir | ||
30 | ll_data = l_data['layers'][ll_name] | ||
31 | if 'buildconfigs' in ll_data: | ||
32 | for c in ll_data['buildconfigs']: | ||
33 | buildconfs.append(os.path.join(layerdir, ll_data['subpath'], c)) | ||
34 | |||
35 | if 'contains_this_file' in l_data.keys(): | ||
36 | force_arg = 'force_bootstraplayer_checkout' | ||
37 | if not args[force_arg]: | ||
38 | print('Note: not checking out source {layer}, use {layerflag} to override.'.format(layer=l_name, layerflag='--force-bootstraplayer-checkout')) | ||
39 | continue | ||
40 | l_remote = l_data['git-remote'] | ||
41 | rev = l_remote['rev'] | ||
42 | desc = l_remote['describe'] | ||
43 | if not desc: | ||
44 | desc = rev[:10] | ||
45 | branch = l_remote['branch'] | ||
46 | remotes = l_remote['remotes'] | ||
47 | |||
48 | print('\nSetting up source {}, revision {}, branch {}'.format(l_name, desc, branch)) | ||
49 | cmd = 'git init -q {}'.format(layerdir) | ||
50 | print("Running '{}'".format(cmd)) | ||
51 | subprocess.check_output(cmd, shell=True) | ||
52 | |||
53 | for remote in remotes: | ||
54 | cmd = "git remote remove {} > /dev/null 2>&1; git remote add {} {}".format(remote, remote, remotes[remote]['uri']) | ||
55 | print("Running '{}' in {}".format(cmd, layerdir)) | ||
56 | subprocess.check_output(cmd, shell=True, cwd=layerdir) | ||
57 | |||
58 | cmd = "git fetch -q {} || true".format(remote) | ||
59 | print("Running '{}' in {}".format(cmd, layerdir)) | ||
60 | subprocess.check_output(cmd, shell=True, cwd=layerdir) | ||
61 | |||
62 | cmd = 'git checkout -q {}'.format(rev) | ||
63 | print("Running '{}' in {}".format(cmd, layerdir)) | ||
64 | subprocess.check_output(cmd, shell=True, cwd=layerdir) | ||
65 | |||
66 | 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/") | ||
67 | |||
68 | parser.add_argument('--force-bootstraplayer-checkout', action='store_true', | ||
69 | 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).') | ||
70 | |||
71 | try: | ||
72 | defaultdest = os.path.dirname(subprocess.check_output('git rev-parse --show-toplevel', universal_newlines=True, shell=True, cwd=os.path.dirname(__file__))) | ||
73 | except subprocess.CalledProcessError as e: | ||
74 | defaultdest = os.path.abspath(".") | ||
75 | |||
76 | parser.add_argument('--destdir', default=defaultdest, help='Where to check out the layers (default is {defaultdest}).'.format(defaultdest=defaultdest)) | ||
77 | parser.add_argument('--jsondata', default=__file__+".json", help='File containing the layer data in json format (default is {defaultjson}).'.format(defaultjson=__file__+".json")) | ||
78 | |||
79 | args = parser.parse_args() | ||
80 | |||
81 | with open(args.jsondata) as f: | ||
82 | json = json.load(f) | ||
83 | |||
84 | supported_versions = ["1.0"] | ||
85 | if json["version"] not in supported_versions: | ||
86 | raise Exception("File {} has version {}, which is not in supported versions: {}".format(args.jsondata, json["version"], supported_versions)) | ||
87 | |||
88 | _do_checkout(vars(args), json) | ||