summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJermain Horsman <jermain.horsman@nedap.com>2024-02-08 14:50:28 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-02-19 11:47:53 +0000
commitdd2ed0c3630adfcf9f1be22d8608fbc871a7e0eb (patch)
treebaaafc8906e3bbb0ed72c300bb4f7139f859e945
parentc390b2e615930b60db0d7f3e72d056e0c67ef5bc (diff)
downloadpoky-dd2ed0c3630adfcf9f1be22d8608fbc871a7e0eb.tar.gz
bitbake-layers: Add ability to update the reference of repositories
This creates a new layers setup with, or, modifies an existing layers setup using, one or more repositories where the references are provided by the user. This is a very minimal implementation, no validation of any reference is done and it is left to the user to provide a valid value. (From OE-Core rev: e69444de713e1ec7959c71f9cdf965d3b5a1c6be) Signed-off-by: Jermain Horsman <jermain.horsman@nedap.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/bblayers/setupwriters/oe-setup-layers.py79
1 files changed, 72 insertions, 7 deletions
diff --git a/meta/lib/bblayers/setupwriters/oe-setup-layers.py b/meta/lib/bblayers/setupwriters/oe-setup-layers.py
index bd71ca1f51..59ca968ff3 100644
--- a/meta/lib/bblayers/setupwriters/oe-setup-layers.py
+++ b/meta/lib/bblayers/setupwriters/oe-setup-layers.py
@@ -31,16 +31,69 @@ class OeSetupLayersWriter():
31 with open(output, 'w') as f: 31 with open(output, 'w') as f:
32 json.dump(repos, f, sort_keys=True, indent=4) 32 json.dump(repos, f, sort_keys=True, indent=4)
33 33
34 def _read_repo_config(self, json_path):
35 with open(json_path) as f:
36 json_config = json.load(f)
37
38 supported_versions = ["1.0"]
39 if json_config["version"] not in supported_versions:
40 err = "File {} has version {}, which is not in supported versions: {}".format(json_path, json_config["version"], supported_versions)
41 logger.error(err)
42 raise Exception(err)
43
44 return json_config
45
46 def _modify_repo_config(self, json_config, args):
47 sources = json_config['sources']
48 for pair in args.custom_references:
49 try:
50 repo, rev = pair.split(':', maxsplit=1)
51 except ValueError:
52 err = "Invalid custom reference specified: '{}'. Provide one using 'REPOSITORY:REFERENCE'.".format(pair)
53 logger.error(err)
54 raise Exception(err)
55 if not repo in sources.keys():
56 err = "Repository {} does not exist in setup-layers config".format(repo)
57 logger.error(err)
58 raise Exception(err)
59
60 layer_remote = json_config['sources'][repo]['git-remote']
61 layer_remote['rev'] = rev
62 # Clear describe
63 layer_remote['describe'] = ''
64
34 def do_write(self, parent, args): 65 def do_write(self, parent, args):
35 """ Writes out a python script and a json config that replicate the directory structure and revisions of the layers in a current build. """ 66 """ Writes out a python script and a json config that replicate the directory structure and revisions of the layers in a current build. """
36 if not os.path.exists(args.destdir):
37 os.makedirs(args.destdir)
38 repos = parent.make_repo_config(args.destdir)
39 json = {"version":"1.0","sources":repos}
40 if not repos:
41 raise Exception("Could not determine layer sources")
42 output = args.output_prefix or "setup-layers" 67 output = args.output_prefix or "setup-layers"
43 output = os.path.join(os.path.abspath(args.destdir),output) 68 output = os.path.join(os.path.abspath(args.destdir), output)
69
70 if args.update:
71 # Modify existing layers setup
72 if args.custom_references is None:
73 err = "No custom reference specified. Please provide one using '--use-custom-reference REPOSITORY:REFERENCE'."
74 logger.error(err)
75 raise Exception(err)
76
77 json = self._read_repo_config(output + ".json")
78 if not 'sources' in json.keys():
79 err = "File {}.json does not contain valid layer sources.".format(output)
80 logger.error(err)
81 raise Exception(err)
82
83 else:
84 # Create new layers setup
85 if not os.path.exists(args.destdir):
86 os.makedirs(args.destdir)
87 repos = parent.make_repo_config(args.destdir)
88 json = {"version":"1.0","sources":repos}
89 if not repos:
90 err = "Could not determine layer sources"
91 logger.error(err)
92 raise Exception(err)
93
94 if args.custom_references is not None:
95 self._modify_repo_config(json, args)
96
44 self._write_json(json, output + ".json") 97 self._write_json(json, output + ".json")
45 logger.info('Created {}.json'.format(output)) 98 logger.info('Created {}.json'.format(output))
46 if not args.json_only: 99 if not args.json_only:
@@ -50,3 +103,15 @@ class OeSetupLayersWriter():
50 def register_arguments(self, parser): 103 def register_arguments(self, parser):
51 parser.add_argument('--json-only', action='store_true', 104 parser.add_argument('--json-only', action='store_true',
52 help='When using the oe-setup-layers writer, write only the layer configuruation in json format. Otherwise, also a copy of scripts/oe-setup-layers (from oe-core or poky) is provided, which is a self contained python script that fetches all the needed layers and sets them to correct revisions using the data from the json.') 105 help='When using the oe-setup-layers writer, write only the layer configuruation in json format. Otherwise, also a copy of scripts/oe-setup-layers (from oe-core or poky) is provided, which is a self contained python script that fetches all the needed layers and sets them to correct revisions using the data from the json.')
106
107 parser.add_argument('--update', '-u',
108 action='store_true',
109 help=("Instead of writing a new json file, update an existing layer setup json file with custom references provided via the '--use-custom-reference' option."
110 "\nThis will only update repositories for which a custom reference is specified, all other repositores will be left unchanged."))
111 parser.add_argument('--use-custom-reference', '-r',
112 action='append',
113 dest='custom_references',
114 metavar='REPOSITORY:REFERENCE',
115 help=("A pair consisting of a repository and a custom reference to use for it (by default the currently checked out commit id would be written out)."
116 "\nThis value can be any reference that 'git checkout' would accept, and is not checked for validity."
117 "\nThis option can be used multiple times."))