Every git URI into SRC_URI variable should have a revision. However, if
the revision is missing (SRCREV), BitBake will perform a query on the
remote repository every time it parses a recipe.

This check will raise an error if a git URI is not provided alongside a 
revision.

Signed-off-by: Corentin Guillevic <[email protected]>
---
 meta/classes-global/insane.bbclass | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/meta/classes-global/insane.bbclass 
b/meta/classes-global/insane.bbclass
index aeffee7983..349da3a65d 100644
--- a/meta/classes-global/insane.bbclass
+++ b/meta/classes-global/insane.bbclass
@@ -1493,7 +1493,34 @@ python do_recipe_qa() {
                 error_msg = "%s: invalid PACKAGECONFIG(s): %s" % (pn, " 
".join(sorted(invalid_pkgconfigs)))
                 oe.qa.handle_error("invalid-packageconfig", error_msg, d)
 
+    def test_git_missing_srcrev(pn, d):
+        sha1_re = re.compile(r'^[0-9a-f]{40}$')
+        for uri in d.getVar('SRC_URI').split():
+            # Get tokens for the current URI
+            params = bb.fetch2.decodeurl(uri)
+
+            if params[0] != 'git':
+                continue
+
+            name = params[5].get('name', '')
+            rev = params[5].get('rev', '')
+
+            # Revision is provided as a 'rev' parameter
+            if rev:
+                # Prevent any revision that doesn't look like a SHA-1
+                if not sha1_re.match(rev or ''):
+                    oe.qa.handle_error("missing-srcrev", "%s: ;rev=%s URL 
parameter doesn't look like a SHA-1" % (pn, rev), d)
+            # git URI has a "name" parameter
+            elif name:
+                rev = d.getVar('SRCREV_' + name)
+                if not rev:
+                    oe.qa.handle_error("missing-srcrev", "%s: no revision (%s) 
defined for URI %s" % (pn, 'SRCREV_' + name, uri), d)
+            else:
+                if d.getVar('SRCREV') == "INVALID":
+                    oe.qa.handle_error("missing-srcrev", "%s: no revision 
(SRCREV) defined for URI %s" % (pn, uri), d)
+
     pn = d.getVar('PN')
+    test_git_missing_srcrev(pn, d)
     test_naming(pn, d)
     test_missing_metadata(pn, d)
     test_missing_maintainer(pn, d)
-- 
2.51.0

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

Reply via email to