diff options
-rw-r--r-- | meta/lib/oeqa/selftest/cases/bblayers.py | 26 | ||||
-rw-r--r-- | scripts/.oe-layers.json | 7 | ||||
-rwxr-xr-x | scripts/oe-setup-build | 122 | ||||
-rwxr-xr-x | scripts/oe-setup-layers | 10 |
4 files changed, 163 insertions, 2 deletions
diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py index f2460cb451..e2009496ad 100644 --- a/meta/lib/oeqa/selftest/cases/bblayers.py +++ b/meta/lib/oeqa/selftest/cases/bblayers.py | |||
@@ -152,12 +152,12 @@ class BitbakeLayers(OESelftestTestCase): | |||
152 | self.validate_layersjson(jsonfile) | 152 | self.validate_layersjson(jsonfile) |
153 | 153 | ||
154 | # The revision-under-test may not necessarily be available on the remote server, | 154 | # The revision-under-test may not necessarily be available on the remote server, |
155 | # so replace it with a revision that has a yocto-4.0 tag. | 155 | # so replace it with a revision that has a yocto-4.1 tag. |
156 | import json | 156 | import json |
157 | with open(jsonfile) as f: | 157 | with open(jsonfile) as f: |
158 | data = json.load(f) | 158 | data = json.load(f) |
159 | for s in data['sources']: | 159 | for s in data['sources']: |
160 | data['sources'][s]['git-remote']['rev'] = '00cfdde791a0176c134f31e5a09eff725e75b905' | 160 | data['sources'][s]['git-remote']['rev'] = '5200799866b92259e855051112520006e1aaaac0' |
161 | with open(jsonfile, 'w') as f: | 161 | with open(jsonfile, 'w') as f: |
162 | json.dump(data, f) | 162 | json.dump(data, f) |
163 | 163 | ||
@@ -165,3 +165,25 @@ class BitbakeLayers(OESelftestTestCase): | |||
165 | result = runCmd('{}/setup-layers --destdir {}'.format(self.testlayer_path, testcheckoutdir)) | 165 | result = runCmd('{}/setup-layers --destdir {}'.format(self.testlayer_path, testcheckoutdir)) |
166 | layers_json = os.path.join(testcheckoutdir, ".oe-layers.json") | 166 | layers_json = os.path.join(testcheckoutdir, ".oe-layers.json") |
167 | self.assertTrue(os.path.exists(layers_json), "File {} not found in test layer checkout".format(layers_json)) | 167 | self.assertTrue(os.path.exists(layers_json), "File {} not found in test layer checkout".format(layers_json)) |
168 | |||
169 | # As setup-layers checkout out an old revision of poky, there is no setup-build symlink, | ||
170 | # and we need to run oe-setup-build directly from the current poky tree under test | ||
171 | oe_setup_build = os.path.join(get_bb_var('COREBASE'), 'scripts/oe-setup-build') | ||
172 | oe_setup_build_l = os.path.join(testcheckoutdir, 'setup-build') | ||
173 | os.symlink(oe_setup_build,oe_setup_build_l) | ||
174 | |||
175 | cmd = '{} --layerlist {} list -v'.format(oe_setup_build_l, layers_json) | ||
176 | result = runCmd(cmd) | ||
177 | cond = "conf/templates/default" in result.output | ||
178 | self.assertTrue(cond, "Incorrect output from {}: {}".format(cmd, result.output)) | ||
179 | |||
180 | # rather than hardcode the build setup cmdline here, let's actually run what the tool suggests to the user | ||
181 | conf = None | ||
182 | if 'poky-default' in result.output: | ||
183 | conf = 'poky-default' | ||
184 | elif 'meta-default' in result.output: | ||
185 | conf = 'meta-default' | ||
186 | self.assertIsNotNone(conf, "Could not find the configuration to set up a build in the output: {}".format(result.output)) | ||
187 | |||
188 | cmd = '{} --layerlist {} setup -c {} --no-shell'.format(oe_setup_build_l, layers_json, conf) | ||
189 | result = runCmd(cmd) | ||
diff --git a/scripts/.oe-layers.json b/scripts/.oe-layers.json new file mode 100644 index 0000000000..1b00a84b54 --- /dev/null +++ b/scripts/.oe-layers.json | |||
@@ -0,0 +1,7 @@ | |||
1 | { | ||
2 | "layers": [ | ||
3 | "../meta-poky", | ||
4 | "../meta" | ||
5 | ], | ||
6 | "version": "1.0" | ||
7 | } | ||
diff --git a/scripts/oe-setup-build b/scripts/oe-setup-build new file mode 100755 index 0000000000..5364f2b481 --- /dev/null +++ b/scripts/oe-setup-build | |||
@@ -0,0 +1,122 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | # | ||
3 | # Copyright OpenEmbedded Contributors | ||
4 | # | ||
5 | # SPDX-License-Identifier: MIT | ||
6 | # | ||
7 | |||
8 | import argparse | ||
9 | import json | ||
10 | import os | ||
11 | import subprocess | ||
12 | |||
13 | def defaultlayers(): | ||
14 | return os.path.abspath(os.path.join(os.path.dirname(__file__), '.oe-layers.json')) | ||
15 | |||
16 | def makebuildpath(topdir, template): | ||
17 | return os.path.join(topdir, "build-{}".format(template)) | ||
18 | |||
19 | def discover_templates(layers_file): | ||
20 | if not os.path.exists(layers_file): | ||
21 | print("List of layers {} does not exist; were the layers set up using the setup-layers script?".format(layers_file)) | ||
22 | return None | ||
23 | |||
24 | templates = [] | ||
25 | layers_list = json.load(open(layers_file))["layers"] | ||
26 | for layer in layers_list: | ||
27 | template_dir = os.path.join(os.path.dirname(layers_file), layer, 'conf','templates') | ||
28 | if os.path.exists(template_dir): | ||
29 | for d in sorted(os.listdir(template_dir)): | ||
30 | templatepath = os.path.join(template_dir,d) | ||
31 | if not os.path.isfile(os.path.join(templatepath,'local.conf.sample')): | ||
32 | continue | ||
33 | layer_base = os.path.basename(layer) | ||
34 | templatename = "{}-{}".format(layer_base[5:] if layer_base.startswith("meta-") else layer_base, d) | ||
35 | buildpath = makebuildpath(os.getcwd(), templatename) | ||
36 | notespath = os.path.join(template_dir, d, 'conf-notes.txt') | ||
37 | try: notes = open(notespath).read() | ||
38 | except: notes = None | ||
39 | try: summary = open(os.path.join(template_dir, d, 'conf-summary.txt')).read() | ||
40 | except: summary = None | ||
41 | templates.append({"templatename":templatename,"templatepath":templatepath,"buildpath":buildpath,"notespath":notespath,"notes":notes,"summary":summary}) | ||
42 | |||
43 | return templates | ||
44 | |||
45 | def print_templates(templates, verbose): | ||
46 | print("Available build configurations:\n") | ||
47 | |||
48 | for i in range(len(templates)): | ||
49 | t = templates[i] | ||
50 | print("{}. {}".format(i+1, t["templatename"])) | ||
51 | print("{}".format(t["summary"].strip() if t["summary"] else "This configuration does not have a summary.")) | ||
52 | if verbose: | ||
53 | print("Configuration template path:", t["templatepath"]) | ||
54 | print("Build path:", t["buildpath"]) | ||
55 | print("Usage notes:", t["notespath"] if t["notes"] else "This configuration does not have usage notes.") | ||
56 | print("") | ||
57 | if not verbose: | ||
58 | print("Re-run with 'list -v' to see additional information.") | ||
59 | |||
60 | def list_templates(args): | ||
61 | templates = discover_templates(args.layerlist) | ||
62 | if not templates: | ||
63 | return | ||
64 | |||
65 | verbose = args.v | ||
66 | print_templates(templates, verbose) | ||
67 | |||
68 | def find_template(template_name, templates): | ||
69 | print_templates(templates, False) | ||
70 | if not template_name: | ||
71 | n_s = input("Please choose a configuration by its number: ") | ||
72 | try: return templates[int(n_s) - 1] | ||
73 | except: | ||
74 | print("Invalid selection, please try again.") | ||
75 | return None | ||
76 | else: | ||
77 | for t in templates: | ||
78 | if t["templatename"] == template_name: | ||
79 | return t | ||
80 | print("Configuration {} is not one of {}, please try again.".format(tempalte_name, [t["templatename"] for t in templates])) | ||
81 | return None | ||
82 | |||
83 | def setup_build_env(args): | ||
84 | templates = discover_templates(args.layerlist) | ||
85 | if not templates: | ||
86 | return | ||
87 | |||
88 | template = find_template(args.c, templates) | ||
89 | if not template: | ||
90 | return | ||
91 | builddir = args.b if args.b else template["buildpath"] | ||
92 | no_shell = args.no_shell | ||
93 | coredir = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) | ||
94 | cmd = "TEMPLATECONF={} . {} {}".format(template["templatepath"], os.path.join(coredir, 'oe-init-build-env'), builddir) | ||
95 | if not no_shell: | ||
96 | cmd = cmd + " && {}".format(os.environ['SHELL']) | ||
97 | print("Running:", cmd) | ||
98 | subprocess.run(cmd, shell=True, executable=os.environ['SHELL']) | ||
99 | |||
100 | parser = argparse.ArgumentParser(description="A script that discovers available build configurations and sets up a build environment based on one of them. Run without arguments to choose one interactively.") | ||
101 | parser.add_argument("--layerlist", default=defaultlayers(), help='Where to look for available layers (as written out by setup-layers script) (default is {}).'.format(defaultlayers())) | ||
102 | |||
103 | subparsers = parser.add_subparsers() | ||
104 | parser_list_templates = subparsers.add_parser('list', help='List available configurations') | ||
105 | parser_list_templates.add_argument('-v', action='store_true', | ||
106 | help='Print detailed information and usage notes for each available build configuration.') | ||
107 | parser_list_templates.set_defaults(func=list_templates) | ||
108 | |||
109 | parser_setup_env = subparsers.add_parser('setup', help='Set up a build environment and open a shell session with it, ready to run builds.') | ||
110 | parser_setup_env.add_argument('-c', metavar='configuration_name', help="Use a build configuration configuration_name to set up a build environment (run this script with 'list' to see what is available)") | ||
111 | parser_setup_env.add_argument('-b', metavar='build_path', help="Set up a build directory in build_path (run this script with 'list -v' to see where it would be by default)") | ||
112 | parser_setup_env.add_argument('--no-shell', action='store_true', | ||
113 | help='Create a build directory but do not start a shell session with the build environment from it.') | ||
114 | parser_setup_env.set_defaults(func=setup_build_env) | ||
115 | |||
116 | args = parser.parse_args() | ||
117 | |||
118 | if 'func' in args: | ||
119 | args.func(args) | ||
120 | else: | ||
121 | from argparse import Namespace | ||
122 | setup_build_env(Namespace(layerlist=args.layerlist, c=None, b=None, no_shell=False)) | ||
diff --git a/scripts/oe-setup-layers b/scripts/oe-setup-layers index bee4ef0fec..6fbfefd656 100755 --- a/scripts/oe-setup-layers +++ b/scripts/oe-setup-layers | |||
@@ -63,6 +63,7 @@ def _write_layer_list(dest, repodirs): | |||
63 | def _do_checkout(args, json): | 63 | def _do_checkout(args, json): |
64 | repos = json['sources'] | 64 | repos = json['sources'] |
65 | repodirs = [] | 65 | repodirs = [] |
66 | oesetupbuild = None | ||
66 | for r_name in repos: | 67 | for r_name in repos: |
67 | r_data = repos[r_name] | 68 | r_data = repos[r_name] |
68 | repodir = os.path.abspath(os.path.join(args['destdir'], r_data['path'])) | 69 | repodir = os.path.abspath(os.path.join(args['destdir'], r_data['path'])) |
@@ -108,9 +109,18 @@ def _do_checkout(args, json): | |||
108 | 109 | ||
109 | if _contains_submodules(repodir): | 110 | if _contains_submodules(repodir): |
110 | print("Repo {} contains submodules, use 'git submodule update' to ensure they are up to date".format(repodir)) | 111 | print("Repo {} contains submodules, use 'git submodule update' to ensure they are up to date".format(repodir)) |
112 | if os.path.exists(os.path.join(repodir, 'scripts/oe-setup-build')): | ||
113 | oesetupbuild = os.path.join(repodir, 'scripts/oe-setup-build') | ||
111 | 114 | ||
112 | _write_layer_list(args['destdir'], repodirs) | 115 | _write_layer_list(args['destdir'], repodirs) |
113 | 116 | ||
117 | if oesetupbuild: | ||
118 | oesetupbuild_symlink = os.path.join(args['destdir'], 'setup-build') | ||
119 | if os.path.exists(oesetupbuild_symlink): | ||
120 | os.remove(oesetupbuild_symlink) | ||
121 | os.symlink(os.path.relpath(oesetupbuild,args['destdir']),oesetupbuild_symlink) | ||
122 | print("\nRun '{}' to list available build configuration templates and set up a build from one of them.".format(oesetupbuild_symlink)) | ||
123 | |||
114 | 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/") | 124 | 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/") |
115 | 125 | ||
116 | parser.add_argument('--force-bootstraplayer-checkout', action='store_true', | 126 | parser.add_argument('--force-bootstraplayer-checkout', action='store_true', |