Message ID | 20231107152641.1043-5-jermain.horsman@nedap.com |
---|---|
State | New |
Headers | show |
Series | bitbake-layers: Add update-layers-setup | expand |
On Tue, 7 Nov 2023 at 16:27, Jermain Horsman <jermain.horsman@nedap.com> wrote: > + def register_commands(self, sp): > + parser_update_layers = self.add_command(sp, 'update-layers-setup', self.do_update_setup, parserecipes=False) > + parser_update_layers.add_argument('json', > + help='File location of the setup-layers json config.') > + parser_update_layers.add_argument('repo', > + help='Name of the repository to be updated.') > + parser_update_layers.add_argument('--branch', '-b', > + help='store branch', > + action='store_true') I'm afraid I can't accept this. The UI should be: bitbake-layers create-layers-setup --update poky --reference <ref> where ref is a revision, tag or branch. A separate top level plugin is problematic because create-layers-setup has specifically a sub-plugin mechanism in itself to support various ways of writing layer setup, json writer is just one implementation, and all extensions should be contained there. Also --branch without parameters to say 'use current branch' is too limiting. It's better to explicitly provide the reference, and write it out into the json without validation for existence. Alex
-----Original Message----- From: Alexander Kanavin <alex.kanavin@gmail.com> Sent: Wednesday, November 8, 2023 11:39 AM > A separate top level plugin is problematic because create-layers-setup > has specifically a sub-plugin mechanism in itself to support various > ways of writing layer setup, json writer is just one implementation, > and all extensions should be contained there. You are absolutely right, I had considered including the writer, but decided to ignore that for now. > Also --branch without parameters to say 'use current branch' is too > limiting. It's better to explicitly provide the reference, and write > it out into the json without validation for existence. I was working with the assumption that not validating would not be acceptable. I guess it comes down to whether we (want to) trust the users to validate their input, or if we think it is more important to make sure that it is. Sincerely, Jermain Horsman
On Wed, 8 Nov 2023 at 16:22, Jermain Horsman <jermain.horsman@nedap.com> wrote: > I was working with the assumption that not validating would not be > acceptable. > I guess it comes down to whether we (want to) trust the users to validate > their input, or if we think it is more important to make sure that it is. I'm not even sure we can do useful validation, as what you have in a local checkout may not match what (sometimes much later) will be available in a remote repo. Branches get pruned. People forget to push. Tags get moved around or deleted. People force push by mistake and sometimes on purpose without thinking further. And so on. The only rock solid reference is the full hash of the commit id. Alex
diff --git a/meta/lib/bblayers/updatesetup.py b/meta/lib/bblayers/updatesetup.py new file mode 100644 index 0000000000..1f8760f2d3 --- /dev/null +++ b/meta/lib/bblayers/updatesetup.py @@ -0,0 +1,78 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: GPL-2.0-only +# + +import json +import logging +import os +import sys + +from bblayers.common import LayerPlugin + +logger = logging.getLogger('bitbake-layers') + +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) + +import oe.buildcfg + +def plugin_init(plugins): + return UpdateSetupPlugin() + +class UpdateSetupPlugin(LayerPlugin): + + def get_repo_path(self, args): + layers = (self.tinfoil.config_data.getVar("BBLAYERS") or "").split() + for layer in layers: + if os.path.basename(layer) == 'workspace': + continue + + repo_path = oe.buildcfg.get_metadata_git_toplevel(layer) + if os.path.basename(repo_path) != args.repo: + continue + + return repo_path + + def do_update_setup(self, args): + """ Modify an existing configuration file using current revisions. """ + with open(args.json, "r+") as json_file: + setup_layers_json = json.load(json_file) + if not 'sources' in setup_layers_json.keys(): + logger.error("File does not contain valid setup-layers config") + return + + sources = setup_layers_json['sources'] + if not args.repo in sources.keys(): + logger.error("Repository {} does not exist in setup-layers config".format(args.repo)) + return + + repo = self.get_repo_path(args) + + branch = oe.buildcfg.get_metadata_git_branch(repo) + + if args.branch: + rev = '' + describe = '' + else: + rev = oe.buildcfg.get_metadata_git_revision(repo) + describe = oe.buildcfg.get_metadata_git_describe(repo) + + layer_remote = setup_layers_json['sources'][args.repo]['git-remote'] + layer_remote['branch'] = branch + layer_remote['rev'] = rev + layer_remote['describe'] = describe + + json_file.seek(0) + json_file.truncate() + json.dump(setup_layers_json, json_file, sort_keys=True, indent=4) + + def register_commands(self, sp): + parser_update_layers = self.add_command(sp, 'update-layers-setup', self.do_update_setup, parserecipes=False) + parser_update_layers.add_argument('json', + help='File location of the setup-layers json config.') + parser_update_layers.add_argument('repo', + help='Name of the repository to be updated.') + parser_update_layers.add_argument('--branch', '-b', + help='store branch', + action='store_true')