openbmc-autobump: use recipe branch for revision
Yocto recipes are now all required to have a branch in the
SRC_URI. Some openbmc repositories now use 'main' and some use
'master' so we need to use this information to determine the
correct branch reference to use for finding the latest revision.
Update the script to pull the "branch=" segment out of the SRC_URI
and utilize it for revision search.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I0313e2681625f9adbac1b9956fb66556e97fe1e0
diff --git a/openbmc-autobump/openbmc-autobump.py b/openbmc-autobump/openbmc-autobump.py
index ea6e2b8..57e18ac 100755
--- a/openbmc-autobump/openbmc-autobump.py
+++ b/openbmc-autobump/openbmc-autobump.py
@@ -40,25 +40,36 @@
git.reset("--hard", "FETCH_HEAD", _cwd=local_name)
-def extract_project_from_uris(uris):
+def extract_project_from_uris(uris, args):
# remove SRC_URI = and quotes (does not handle escaped quotes)
uris = uris.split('"')[1]
for uri in uris.split():
if "github.com/openbmc" not in uri:
continue
+ segments = uri.split(";")
+ branch = args.branch
+
+ for s in segments[1:]:
+ if "branch=" not in s:
+ continue
+ if "nobranch=" in s:
+ continue
+ branch = s.split("=")[1]
+
# remove fetcher arguments
- uri = uri.split(";")[0]
+ uri = segments[0]
# the project is the right-most path segment
- return uri.split("/")[-1].replace(".git", "")
+ return (uri.split("/")[-1].replace(".git", ""), branch)
return None
-def extract_sha_from_recipe(recipe):
+def extract_sha_from_recipe(recipe, args):
with open(recipe) as fp:
uris = ""
project = None
+ branch = None
sha = None
for line in fp:
@@ -71,14 +82,16 @@
# In uris we've gathered a complete (possibly multi-line)
# assignment to a bitbake variable that ends with _URI.
# Try to pull an OpenBMC project out of it.
- project = extract_project_from_uris(uris)
- if project is None:
+ uri = extract_project_from_uris(uris, args)
+ if uri is None:
# We didn't find a project. Unset uris and look for
# another bitbake variable that ends with _URI.
uris = ""
+ else:
+ (project, branch) = uri
- if project and sha:
- return (project, sha)
+ if project and branch and sha:
+ return (project, branch, sha)
raise RuntimeError("No SRCREV or URI found in {}".format(recipe))
@@ -94,7 +107,15 @@
match_suffixes = ("bb", "bbclass", "inc")
pathspecs = ("*.{}".format(x) for x in match_suffixes)
- grep_args = ("-l", "-e", "_URI", "--and", "-e", "github.com/openbmc")
+ grep_args = (
+ "--no-color",
+ "-l",
+ "-e",
+ "_URI",
+ "--and",
+ "-e",
+ "github.com/openbmc",
+ )
grep_args = (*grep_args, *pathspecs)
try:
return git.grep(*grep_args, _cwd=meta).stdout.decode("utf-8").split()
@@ -112,11 +133,13 @@
for recipe in candidate_recipes:
full_recipe_path = os.path.join(meta, recipe)
recipe_basename = os.path.basename(full_recipe_path)
- project_name, recipe_sha = extract_sha_from_recipe(full_recipe_path)
+ project_name, recipe_branch, recipe_sha = extract_sha_from_recipe(
+ full_recipe_path, args
+ )
remote_fmt_args = (args.ssh_config_host, project_name)
remote = "ssh://{}/openbmc/{}".format(*remote_fmt_args)
- ls_remote_args = [remote, "refs/heads/{}".format(args.branch)]
+ ls_remote_args = [remote, "refs/heads/{}".format(recipe_branch)]
try:
project_sha = git("ls-remote", *ls_remote_args)
project_sha = project_sha.stdout.decode("utf-8").split()[0]