merge-caf: clean up and reformat

Change-Id: Ie44f3f008247f55cfb69cab06735853bf36dddd7
This commit is contained in:
Anay Wadhera 2021-02-16 19:44:54 -08:00
parent d8141fb357
commit 9e4b9702e2
1 changed files with 67 additions and 39 deletions

View File

@ -33,7 +33,6 @@ import argparse
import os import os
import shutil import shutil
import subprocess import subprocess
import sys
import xml.etree.ElementTree as Et import xml.etree.ElementTree as Et
import git import git
@ -51,6 +50,7 @@ def nice_error():
""" Errors out in a non-ugly way. """ """ Errors out in a non-ugly way. """
print("Invalid repo, are you sure this repo is on the tag you're merging?") print("Invalid repo, are you sure this repo is on the tag you're merging?")
def get_manual_repos(args, is_system): def get_manual_repos(args, is_system):
""" Get all manually (optional) specified repos from arguments """ """ Get all manually (optional) specified repos from arguments """
ret_lst = {} ret_lst = {}
@ -68,14 +68,18 @@ def list_default_repos(is_system):
""" Gathers all repos from split system.xml and vendor.xml """ """ Gathers all repos from split system.xml and vendor.xml """
default_repos = {} default_repos = {}
if is_system: if is_system:
with open("{0}/.repo/manifests/system.xml".format(WORKING_DIR)) as system_manifest: with open(
"{0}/.repo/manifests/system.xml".format(WORKING_DIR)
) as system_manifest:
system_root = Et.parse(system_manifest).getroot() system_root = Et.parse(system_manifest).getroot()
for child in system_root: for child in system_root:
path = child.get("path") path = child.get("path")
if path: if path:
default_repos[path] = child.get("name") default_repos[path] = child.get("name")
else: else:
with open("{0}/.repo/manifests/vendor.xml".format(WORKING_DIR)) as vendor_manifest: with open(
"{0}/.repo/manifests/vendor.xml".format(WORKING_DIR)
) as vendor_manifest:
vendor_root = Et.parse(vendor_manifest).getroot() vendor_root = Et.parse(vendor_manifest).getroot()
for child in vendor_root: for child in vendor_root:
path = child.get("path") path = child.get("path")
@ -113,24 +117,23 @@ def force_sync(repo_lst):
shutil.rmtree("{}{}".format(WORKING_DIR, repo)) shutil.rmtree("{}{}".format(WORKING_DIR, repo))
cpu_count = str(os.cpu_count()) cpu_count = str(os.cpu_count())
if REPOS_TO_MERGE is repo_lst:
args = [ args = [
"repo", "sync", "-c", "--force-sync", "-f", "repo",
"--no-clone-bundle", "--no-tag", "-j", cpu_count, "-q", "sync",
] "-c",
args += repo_lst "--force-sync",
subprocess.run(args, check=False,) "-f",
else: "--no-clone-bundle",
for repo in repo_lst: "--no-tag",
"-j",
cpu_count,
"-q",
] + list(repo_lst.values())
subprocess.run( subprocess.run(
[ args,
"repo", "sync", "-c", "--force-sync", "-f",
"--no-clone-bundle", "--no-tag", "-j", cpu_count, "-q", repo,
],
check=False, check=False,
) )
def merge(repo_lst, branch): def merge(repo_lst, branch):
""" Merges the necessary repos and lists if a repo succeeds or fails """ """ Merges the necessary repos and lists if a repo succeeds or fails """
failures = [] failures = []
@ -155,21 +158,30 @@ def merge_manifest(is_system, branch):
tree = Et.parse(manifestxml) tree = Et.parse(manifestxml)
root = tree.getroot() root = tree.getroot()
if is_system: if is_system:
root.findall('default')[0].set('revision', branch) root.findall("default")[0].set("revision", branch)
else: else:
lst = root.findall('remote') lst = root.findall("remote")
remote = None remote = None
for elem in lst: for elem in lst:
if elem.attrib['name'] == "caf_vendor": if elem.attrib["name"] == "caf_vendor":
remote = elem remote = elem
break break
remote.set('revision', branch) remote.set("revision", branch)
tree.write("{0}/.repo/manifests/default.xml".format(WORKING_DIR)) tree.write("{0}/.repo/manifests/default.xml".format(WORKING_DIR))
cpu_count = str(os.cpu_count()) cpu_count = str(os.cpu_count())
subprocess.run( subprocess.run(
[ [
"repo", "sync", "-c", "--force-sync", "-f", "repo",
"--no-clone-bundle", "--no-tag", "-j", cpu_count, "-q", "-d", "sync",
"-c",
"--force-sync",
"-f",
"--no-clone-bundle",
"--no-tag",
"-j",
cpu_count,
"-q",
"-d",
], ],
check=False, check=False,
) )
@ -213,10 +225,26 @@ def main():
"""Gathers and merges all repos from CAF and """Gathers and merges all repos from CAF and
reports all repos that need to be fixed manually""" reports all repos that need to be fixed manually"""
parser = argparse.ArgumentParser(description='Merge a CAF revision.') parser = argparse.ArgumentParser(description="Merge a CAF revision.")
parser.add_argument('branch_to_merge', metavar='branch', type=str, help='a tag to merge from source.codeaurora.org') parser.add_argument(
parser.add_argument('--repos', dest='repos_to_merge', nargs='*', type=str, help='path of repos to merge') "branch_to_merge",
parser.add_argument('--merge-manifest', dest='merge_manifest', action="store_true", help='automatically update manifest before merging repos') metavar="branch",
type=str,
help="a tag to merge from source.codeaurora.org",
)
parser.add_argument(
"--repos",
dest="repos_to_merge",
nargs="*",
type=str,
help="path of repos to merge",
)
parser.add_argument(
"--merge-manifest",
dest="merge_manifest",
action="store_true",
help="automatically update manifest before merging repos",
)
args = parser.parse_args() args = parser.parse_args()
branch = "refs/tags/{}".format(args.branch_to_merge) branch = "refs/tags/{}".format(args.branch_to_merge)