diff mbox series

[v2,1/2] oe-setup-layers: support inline URI

Message ID 20251215103312.902774-1-corentin.guillevic@smile.fr
State New
Headers show
Series [v2,1/2] oe-setup-layers: support inline URI | expand

Commit Message

Corentin Guillevic Dec. 15, 2025, 10:33 a.m. UTC
Most of the time, when we describe a remote, the layer data (also used by
the script bitbake-setup) looks like this:

"bitbake": {
    "git-remote": {
        "remotes": {
            "origin": {
                "uri": "https://git.openembedded.org/bitbake"
            }
        },
        ...
    }
}

i.e. an URI with the common name 'origin'. Alternatively, we could simplify this, by
using a shorter structure with the property 'uri' only:

"bitbake": {
    "git-remote": {
        "uri": "https://git.openembedded.org/bitbake

",
        ...
    }
}

These properties can be used together.

Signed-off-by: Corentin Guillevic <corentin.guillevic@smile.fr>
---

Changes in v2:
- The keys are complementary, rather than mutually exclusive
- Updated configuration in meta/files/layers.schema.json

 scripts/oe-setup-layers | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

Comments

Alexander Kanavin Dec. 15, 2025, 11:35 a.m. UTC | #1
On Mon, 15 Dec 2025 at 11:33, Corentin Guillevic via
lists.openembedded.org
<corentin.guillevic=smile.fr@lists.openembedded.org> wrote:
> +    if 'uri' in r_remote:
> +        r_name = ''
> +
> +        if 'remotes' in r_remote:
> +            if not 'bitbake-setup-uri' in r_remote['remotes']:
> +                r_name = 'bitbake-setup-uri'
> +            else:
> +                idx = 1
> +                while 'bitbake-setup-uri_{}'.format(idx) in r_remote['remotes']:
> +                    idx += 1
> +                r_name = 'bitbake-setup-uri_{}'.format(idx)
> +        else:
> +            r_name = 'bitbake-setup-uri'

This should not be using 'bitbake-setup-uri-xxx', just 'origin-xxx'.

Also I think it would be more pythonic to avoid incrementing an
integer by hand as shown here:

https://stackoverflow.com/questions/9884213/looping-from-1-to-infinity-in-python

e.g.

import itertools
for i in itertools.count(start=1):
    if there_is_a_reason_to_break(i):
        break

Alex
diff mbox series

Patch

diff --git a/scripts/oe-setup-layers b/scripts/oe-setup-layers
index 31cb963251..c8799fe265 100755
--- a/scripts/oe-setup-layers
+++ b/scripts/oe-setup-layers
@@ -60,6 +60,33 @@  def _write_layer_list(dest, repodirs):
     with open(layers_f, 'w') as f:
         json.dump({"version":"1.0","layers":layers}, f, sort_keys=True, indent=4)
 
+def _get_remotes(r_remote):
+    remotes = {}
+
+    if not 'remotes' in r_remote and not 'uri' in r_remote:
+        raise Exception("Expected key(s): 'remotes', 'uri'")
+
+    if 'remotes' in r_remote:
+        remotes = r_remote['remotes'].copy()
+
+    if 'uri' in r_remote:
+        r_name = ''
+
+        if 'remotes' in r_remote:
+            if not 'bitbake-setup-uri' in r_remote['remotes']:
+                r_name = 'bitbake-setup-uri'
+            else:
+                idx = 1
+                while 'bitbake-setup-uri_{}'.format(idx) in r_remote['remotes']:
+                    idx += 1
+                r_name = 'bitbake-setup-uri_{}'.format(idx)
+        else:
+            r_name = 'bitbake-setup-uri'
+
+        remotes.update({r_name: {'uri': r_remote['uri']}})
+
+    return remotes
+
 def _do_checkout(args, json):
     repos = json['sources']
     repodirs = []
@@ -80,7 +107,8 @@  def _do_checkout(args, json):
         if not desc:
             desc = rev[:10]
         branch = r_remote['branch']
-        remotes = r_remote['remotes']
+
+        remotes = _get_remotes(r_remote)
 
         print('\nSetting up source {}, revision {}, branch {}'.format(r_name, desc, branch))
         if not _is_repo_git_repo(repodir):