From: Jermain Horsman <[email protected]>

This uses an existing setup-layers configuration and modifies one
or more repositories using a reference provided by the user.

This is a very minimal implementation, no validation of this reference
is done and it is left to the user to provide a valid value.

Signed-off-by: Jermain Horsman <[email protected]>
---
 .../bblayers/setupwriters/oe-setup-layers.py  | 71 +++++++++++++++++--
 1 file changed, 64 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..a4bd9c8c3d 100644
--- a/meta/lib/bblayers/setupwriters/oe-setup-layers.py
+++ b/meta/lib/bblayers/setupwriters/oe-setup-layers.py
@@ -31,16 +31,64 @@ class OeSetupLayersWriter():
         with open(output, 'w') as f:
             json.dump(repos, f, sort_keys=True, indent=4)
 
+    def _read_repo_config(self, json_path):
+        with open(json_path) as f:
+            json_config = json.load(f)
+
+        supported_versions = ["1.0"]
+        if json_config["version"] not in supported_versions:
+            raise Exception("File {} has version {}, which is not in supported 
versions: {}".format(json_path, json_config["version"], supported_versions))
+
+        return json_config
+
+    def _modify_repo_config(self, json_config, args):
+        sources = json_config['sources']
+        for repo in args.repository:
+            if not repo in sources.keys():
+                raise Exception("Repository {} does not exist in setup-layers 
config".format(repo))
+
+            layer_remote = json_config['sources'][repo]['git-remote']
+            layer_remote['rev'] = args.reference
+            # Clear describe
+            layer_remote['describe'] = ''
+
     def do_write(self, parent, args):
         """ Writes out a python script and a json config that replicate the 
directory structure and revisions of the layers in a current build. """
-        if not os.path.exists(args.destdir):
-            os.makedirs(args.destdir)
-        repos = parent.make_repo_config(args.destdir)
-        json = {"version":"1.0","sources":repos}
-        if not repos:
-            raise Exception("Could not determine layer sources")
         output = args.output_prefix or "setup-layers"
-        output = os.path.join(os.path.abspath(args.destdir),output)
+        output = os.path.join(os.path.abspath(args.destdir), output)
+
+        if args.update:
+            # Modify existing layers setup
+            if args.repository is None:
+                logger.error("No repository specified. Please provide one 
using '--repository REPOSITORY'.")
+                raise Exception("No repository specified. Please provide one 
using '--repository REPOSITORY'.")
+            if args.reference is None:
+                logger.error("No reference specified. Please provide one using 
'--reference REFERENCE'.")
+                raise Exception("No reference specified. Please provide one 
using '--reference REFERENCE'.")
+
+            json = self._read_repo_config(output + ".json")
+            if not 'sources' in json.keys():
+                raise Exception("File {}.json does not contain valid layer 
sources.".format(output))
+
+        else:
+            # Create new layers setup
+            if args.repository is not None:
+                if args.reference is None:
+                    logger.error("No reference specified. Please provide one 
using '--reference REFERENCE'.")
+                    raise Exception("No reference specified. Please provide 
one using '--reference REFERENCE'.")
+            elif args.reference is not None:
+                logger.warning("Reference specified, but no repository, this 
has no effect.")
+
+            if not os.path.exists(args.destdir):
+                os.makedirs(args.destdir)
+            repos = parent.make_repo_config(args.destdir)
+            json = {"version":"1.0","sources":repos}
+            if not repos:
+                raise Exception("Could not determine layer sources")
+
+        if args.repository is not None:
+            self._modify_repo_config(json, args)
+
         self._write_json(json, output + ".json")
         logger.info('Created {}.json'.format(output))
         if not args.json_only:
@@ -50,3 +98,12 @@ class OeSetupLayersWriter():
     def register_arguments(self, parser):
         parser.add_argument('--json-only', action='store_true',
             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.')
+
+        parser.add_argument('--update', '-u',
+            action='store_true',
+            help='Updates an existing layers setup.')
+        parser.add_argument('--repository', '-p',
+            action='append',
+            help='Repository to customize, this requires a reference to be 
specified.\nThis option can be used multiple times.')
+        parser.add_argument('--reference', '-r',
+            help="Reference to use when updating repositories.\nThe value can 
be any git reference, however it is up to the user to provide a valid 
value.\nThis option is only useful when using '--update'.")
-- 
2.42.0.windows.2

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#193408): 
https://lists.openembedded.org/g/openembedded-core/message/193408
Mute This Topic: https://lists.openembedded.org/mt/103598114/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to