Skip to contentSkip to conversation

bitbake: layerindex: use branch when specified

PATCH In review Mark Hatle 2 participants 2 messages Dec 19, 2019

lore
Share & tools
lore

Mark Hatle

author
#0 lore raw

PATCH v2 1/1 bitbake: layerindex: use branch when specified

From: Jon Mason <[email protected]>

When currently specified, the branch is used to verify the versioning of the meta layer, but the master branch is checked out. This change allows for the branch to be specified. Now it is easy to specify all of the meta layers being added are of the same version, without having to do it in each individual git tree. Also, it will error if there are branches without a matching version. Finally, this allows for meta layer git trees without a master branch.

Minor rework of the patch to use the layerBranch actual_branch since the layerindex referenced branch may be different then the overall release branch.

Also adjust the patch to use the default git checkout branch instead of master if no branch was specified. (Some repositories don't have a master branch.)

---
 lib/bblayers/layerindex.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
lib/bblayers/layerindex.py +9 -4
index 57cd9027..aa3b682d 100644
@@ -24,7 +24,7 @@ class LayerIndexPlugin(ActionPlugin):
     This class inherits ActionPlugin to get do_add_layer.
     """
 
-    def get_fetch_layer(self, fetchdir, url, subdir, fetch_layer):
+    def get_fetch_layer(self, fetchdir, url, subdir, fetch_layer, branch):
         layername = self.get_layer_name(url)
         if os.path.splitext(layername)[1] == '.git':
             layername = os.path.splitext(layername)[0]
@@ -32,9 +32,13 @@ class LayerIndexPlugin(ActionPlugin):
         layerdir = os.path.join(repodir, subdir)
         if not os.path.exists(repodir):
             if fetch_layer:
-                result = subprocess.call(['git', 'clone', url, repodir])
+                cmd = ['git', 'clone', '-b' , branch, url, repodir]
+                if not branch:
+                    # Branch really shouldn't be empty, but use the repo default if it is
+                    cmd = ['git', 'clone', url, repodir]
+                result = subprocess.call(cmd)
                 if result:
-                    logger.error("Failed to download %s" % url)
+                    logger.error("Failed to download %s (%s)" % (url, branch))
                     return None, None, None
                 else:
                     return subdir, layername, layerdir
@@ -171,7 +175,8 @@ class LayerIndexPlugin(ActionPlugin):
                 subdir, name, layerdir = self.get_fetch_layer(fetchdir,
                                                       layerBranch.layer.vcs_url,
                                                       layerBranch.vcs_subdir,
-                                                      not args.show_only)
+                                                      not args.show_only,
+                                                      layerBranch.actual_branch)
                 if not name:
                     # Error already shown
                     return 1
Signature · 1 line
2.17.1
#1 lore raw
Quoted 17 lines · Mark Hatle

From: Jon Mason <[email protected]>

When currently specified, the branch is used to verify the versioning of the meta layer, but the master branch is checked out. This change allows for the branch to be specified. Now it is easy to specify all of the meta layers being added are of the same version, without having to do it in each individual git tree. Also, it will error if there are branches without a matching version. Finally, this allows for meta layer git trees without a master branch.

Minor rework of the patch to use the layerBranch actual_branch since the layerindex referenced branch may be different then the overall release branch.

Quoted 5 lines

Also adjust the patch to use the default git checkout branch instead of master if no branch was specified. (Some repositories don't have a master branch.)

Looks good to me!

Thanks,
Jon

Quoted 46 lines
---
 lib/bblayers/layerindex.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
lib/bblayers/layerindex.py +9 -5
index 57cd9027..aa3b682d 100644
@@ -24,7 +24,7 @@ class LayerIndexPlugin(ActionPlugin):
     This class inherits ActionPlugin to get do_add_layer.
     """
 
-    def get_fetch_layer(self, fetchdir, url, subdir, fetch_layer):
+    def get_fetch_layer(self, fetchdir, url, subdir, fetch_layer, branch):
         layername = self.get_layer_name(url)
         if os.path.splitext(layername)[1] == '.git':
             layername = os.path.splitext(layername)[0]
@@ -32,9 +32,13 @@ class LayerIndexPlugin(ActionPlugin):
         layerdir = os.path.join(repodir, subdir)
         if not os.path.exists(repodir):
             if fetch_layer:
-                result = subprocess.call(['git', 'clone', url, repodir])
+                cmd = ['git', 'clone', '-b' , branch, url, repodir]
+                if not branch:
+                    # Branch really shouldn't be empty, but use the repo default if it is
+                    cmd = ['git', 'clone', url, repodir]
+                result = subprocess.call(cmd)
                 if result:
-                    logger.error("Failed to download %s" % url)
+                    logger.error("Failed to download %s (%s)" % (url, branch))
                     return None, None, None
                 else:
                     return subdir, layername, layerdir
@@ -171,7 +175,8 @@ class LayerIndexPlugin(ActionPlugin):
                 subdir, name, layerdir = self.get_fetch_layer(fetchdir,
                                                       layerBranch.layer.vcs_url,
                                                       layerBranch.vcs_subdir,
-                                                      not args.show_only)
+                                                      not args.show_only,
+                                                      layerBranch.actual_branch)
                 if not name:
                     # Error already shown
                     return 1
--

2.17.1