summaryrefslogtreecommitdiff
path: root/util/update_release_branch.py
diff options
context:
space:
mode:
authorYH Lin <yueherngl@google.com>2022-11-30 21:44:08 +0000
committerYH Lin <yueherngl@google.com>2022-11-30 21:44:08 +0000
commitaf25602b15b22b9ef5821dcba9934311f2157c48 (patch)
treed0c89ae8814c2ba35c238c6c0644ec6b1602c63a /util/update_release_branch.py
parent54462f034b635260dd09173b3d082e47fc960ef3 (diff)
parentaa40b859b3a73e5a205bc561c1a29eff38485461 (diff)
downloadchrome-ec-af25602b15b22b9ef5821dcba9934311f2157c48.tar.gz
Merge remote-tracking branch cros/main into factory-brya-14517.B-main
Generated by: util/update_release_branch.py --baseboard brya --relevant_paths_file baseboard/brya/relevant-paths.txt factory-brya-14517.B-main Relevant changes: git log --oneline 54462f034b..aa40b859b3 -- baseboard/brya board/agah board/anahera board/banshee board/brya board/crota board/felwinter board/gimble board/kano board/mithrax board/osiris board/primus board/redrix board/taeko board/taniks board/vell board/volmar driver/bc12/pi3usb9201_public.* driver/charger/bq25710.* driver/ppc/nx20p348x.* driver/ppc/syv682x_public.* driver/retimer/bb_retimer_public.* driver/tcpm/nct38xx.* driver/tcpm/ps8xxx_public.* driver/tcpm/tcpci.* include/power/alderlake* include/intel_x86.h power/alderlake* power/intel_x86.c util/getversion.sh e6da633c38 driver: Sort header files 234a87ae2d tcpci: Add FRS enable to driver structure a56be59ccd tcpm_header: add test for tcpm_dump_registers 57b3256963 Rename CONFIG_CHARGER_INPUT_CURRENT to _CHARGER_DEFAULT_CURRENT_LIMIT e420c8ff9a marasov: Modify TypeC and TypeA configuration. 43b53e0045 Add default implementation of board_set_charge_limit b75dc90677 Add CONFIG_CHARGER_MIN_INPUT_CURRENT_LIMIT f1b563c350 baseboard: Sort header files 7d01b1e58d driver/retimer/ps8818.h: Add I2C ADDR FLAGS 0x30, 0x58, 0x70 ec31407993 Add CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 8f89f69a5b crota: disable lid angle sensor for clamshell BRANCH=None BUG=b:259002141 b:255184961 b:247100970 b:259354679 b:260630630 BUG=b:163093572 b:254328661 TEST=`emerge-brya chromeos-ec` Force-Relevant-Builds: all Change-Id: Ia85a701fbf6b8e67ec214b9e25e0e55e980a6f47 Signed-off-by: YH Lin <yueherngl@google.com>
Diffstat (limited to 'util/update_release_branch.py')
-rwxr-xr-xutil/update_release_branch.py354
1 files changed, 233 insertions, 121 deletions
diff --git a/util/update_release_branch.py b/util/update_release_branch.py
index 0a871724fe..939d572dc4 100755
--- a/util/update_release_branch.py
+++ b/util/update_release_branch.py
@@ -42,11 +42,11 @@ def git_commit_msg(cros_main, branch, head, merge_head, rel_paths, cmd):
A String containing the git commit message with the exception of the
Signed-Off-By field and Change-ID field.
"""
- relevant_commits_cmd, relevant_commits = get_relevant_commits(
+ relevant_commits_cmd, relevant_commits, relevant_hdr = get_relevant_commits(
head, merge_head, "--oneline", rel_paths
)
- _, relevant_bugs = get_relevant_commits(head, merge_head, "", rel_paths)
+ _, relevant_bugs, _ = get_relevant_commits(head, merge_head, "", rel_paths)
relevant_bugs = set(re.findall("BUG=(.*)", relevant_bugs))
# Filter out "none" from set of bugs
filtered = []
@@ -65,7 +65,7 @@ Merge remote-tracking branch {CROS_MAIN} into {BRANCH}
Generated by: {COMMAND_LINE}
-Relevant changes:
+{RELEVANT_COMMITS_HEADER}
{RELEVANT_COMMITS_CMD}
@@ -93,6 +93,7 @@ Force-Relevant-Builds: all
BRANCH=branch,
RELEVANT_COMMITS_CMD=relevant_commits_cmd,
RELEVANT_COMMITS=relevant_commits,
+ RELEVANT_COMMITS_HEADER=relevant_hdr,
BUG_FIELD=bug_field,
COMMAND_LINE=cmd,
)
@@ -135,8 +136,10 @@ def get_relevant_commits(head, merge_head, fmt, relevant_paths):
Returns:
A tuple containing the arguments passed to the git log command and
- stdout.
+ stdout, and the header for the message
"""
+ if not relevant_paths:
+ return "", "", ""
if fmt:
cmd = [
"git",
@@ -156,7 +159,129 @@ def get_relevant_commits(head, merge_head, fmt, relevant_paths):
proc = subprocess.run(
cmd, stdout=subprocess.PIPE, encoding="utf-8", check=True, shell=True
)
- return "".join(proc.args), proc.stdout
+ return "".join(proc.args), proc.stdout, "Relevant changes:"
+
+
+def merge_repo(
+ base, cros_main, cmd_checkout, strategy, cmd, prunelist, relevant_paths
+):
+ """Merge changes from ToT into this repo's branch.
+
+ For this repo, merge the changes from ToT to the branch set
+ in the merge command.
+
+ Args:
+ base: String indicating the Source directory of repo.
+ cros_main: String indicating the origin branch name
+ cmd_checkout: String list containing the checkout command to use.
+ strategy: String list containing the merge strategy,
+ cmd: String containing the command line
+ prunelist: String list containing the files to remove.
+ relevant_paths: String containing all the relevant paths for this
+ particular baseboard or board.
+ """
+ # Change directory to the repo being merged
+ print('Starting merge in "%s"' % base)
+ print('Checkout command: "%s"' % " ".join(cmd_checkout))
+ os.chdir(base)
+ # Check if we are already in merge process
+ result = subprocess.run(
+ ["git", "rev-parse", "--quiet", "--verify", "MERGE_HEAD"],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ check=False,
+ )
+
+ if result.returncode:
+ # Let's perform the merge
+ print("Updating remote...")
+ subprocess.run(["git", "remote", "update"], check=True)
+ subprocess.run(cmd_checkout, check=True)
+ cmd_merge = [
+ "git",
+ "merge",
+ "--no-ff",
+ "--no-commit",
+ cros_main,
+ "-s",
+ ]
+ cmd_merge.extend(strategy)
+ print('Merge command: "%s"' % " ".join(cmd_merge))
+ try:
+ subprocess.run(cmd_merge, check=True)
+ except subprocess.CalledProcessError:
+ # We've likely encountered a merge conflict due to new OWNERS file
+ # modifications. If we're removing the owners, we'll delete them.
+ if prunelist:
+ # Find the unmerged files
+ unmerged = (
+ subprocess.run(
+ ["git", "diff", "--name-only", "--diff-filter=U"],
+ stdout=subprocess.PIPE,
+ encoding="utf-8",
+ check=True,
+ )
+ .stdout.rstrip()
+ .split()
+ )
+
+ # Prune OWNERS files
+ for file in unmerged:
+ if file in prunelist:
+ subprocess.run(["git", "rm", file], check=False)
+ unmerged.remove(file)
+
+ print("Removed non-root OWNERS files.")
+ if unmerged:
+ print(
+ "Unmerged files still exist! You need to manually resolve this."
+ )
+ print("\n".join(unmerged))
+ sys.exit(1)
+ else:
+ raise
+ else:
+ print(
+ "We have already started merge process.",
+ "Attempt to generate commit.",
+ )
+ # Check whether any commit is needed.
+ changes = subprocess.run(
+ ["git", "status", "--porcelain"],
+ stdout=subprocess.PIPE,
+ encoding="utf-8",
+ check=True,
+ ).stdout.rstrip()
+ if not changes:
+ print("No changes have been found, skipping commit.")
+ return
+
+ print("Generating commit message...")
+ branch = subprocess.run(
+ ["git", "rev-parse", "--abbrev-ref", "HEAD"],
+ stdout=subprocess.PIPE,
+ encoding="utf-8",
+ check=True,
+ ).stdout.rstrip()
+ head = subprocess.run(
+ ["git", "rev-parse", "--short", "HEAD"],
+ stdout=subprocess.PIPE,
+ encoding="utf-8",
+ check=True,
+ ).stdout.rstrip()
+ merge_head = subprocess.run(
+ ["git", "rev-parse", "--short", "MERGE_HEAD"],
+ stdout=subprocess.PIPE,
+ encoding="utf-8",
+ check=True,
+ ).stdout.rstrip()
+
+ print("Typing as fast as I can...")
+ commit_msg = git_commit_msg(
+ cros_main, branch, head, merge_head, relevant_paths, cmd
+ )
+ subprocess.run(["git", "commit", "--signoff", "-m", commit_msg], check=True)
+ subprocess.run(["git", "commit", "--amend"], check=True)
def main(argv):
@@ -186,7 +311,11 @@ def main(argv):
parser.add_argument("--baseboard")
parser.add_argument("--board")
parser.add_argument(
- "release_branch", help=("The name of the target release" " branch")
+ "release_branch",
+ help=(
+ "The name of the target release branch, "
+ "without the trailing '-main'."
+ ),
)
parser.add_argument(
"--remote_prefix",
@@ -197,6 +326,11 @@ def main(argv):
default="cros",
)
parser.add_argument(
+ "--srcbase",
+ help=("The base directory where the src tree exists."),
+ default="/mnt/host/source/",
+ )
+ parser.add_argument(
"--relevant_paths_file",
help=(
"A path to a text file which includes other "
@@ -213,7 +347,7 @@ def main(argv):
parser.add_argument(
"--strategy_option",
"-X",
- help=("The strategy option for the chosen merge " "strategy"),
+ help=("The strategy option for the chosen merge strategy"),
)
parser.add_argument(
"--remove_owners",
@@ -221,6 +355,12 @@ def main(argv):
action=("store_true"),
help=("Remove non-root OWNERS level files if present"),
)
+ parser.add_argument(
+ "--zephyr",
+ "-z",
+ action=("store_true"),
+ help=("If set, treat the board as a Zephyr based program"),
+ )
opts = parser.parse_args(argv[1:])
@@ -228,17 +368,24 @@ def main(argv):
board_dir = ""
if opts.baseboard:
+ # If a zephyr board, no baseboard allowed
+ if opts.zephyr:
+ raise Exception("--baseboard not allowed for Zephyr boards")
# Dereference symlinks so "git log" works as expected.
baseboard_dir = os.path.relpath("baseboard/" + opts.baseboard)
baseboard_dir = os.path.relpath(os.path.realpath(baseboard_dir))
boards = get_relevant_boards(opts.baseboard)
elif opts.board:
- board_dir = os.path.relpath("board/" + opts.board)
+ if opts.zephyr:
+ board_dir = os.path.relpath("zephyr/program/" + opts.board)
+ else:
+ board_dir = os.path.relpath("board/" + opts.board)
board_dir = os.path.relpath(os.path.realpath(board_dir))
boards = [opts.board]
else:
- boards = []
+ # With no board or baseboard, not sure whether this should proceed
+ raise Exception("no board or baseboard specified")
print("Gathering relevant paths...")
relevant_paths = []
@@ -247,10 +394,12 @@ def main(argv):
elif opts.board:
relevant_paths.append(board_dir)
- for board in boards:
- relevant_paths.append("board/" + board)
+ if not opts.zephyr:
+ for board in boards:
+ relevant_paths.append("board/" + board)
# Check for the existence of a file that has other paths of interest.
+ # Also check for 'relevant-paths.txt' in the board directory
if opts.relevant_paths_file and os.path.exists(opts.relevant_paths_file):
with open(opts.relevant_paths_file, "r") as relevant_paths_file:
for line in relevant_paths_file:
@@ -260,17 +409,9 @@ def main(argv):
relevant_paths.append("util/getversion.sh")
relevant_paths = " ".join(relevant_paths)
- # Check if we are already in merge process
- result = subprocess.run(
- ["git", "rev-parse", "--quiet", "--verify", "MERGE_HEAD"],
- stdout=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
- check=False,
- )
-
# Prune OWNERS files if desired
+ prunelist = []
if opts.remove_owners:
- prunelist = []
for root, dirs, files in os.walk("."):
for name in dirs:
if "build" in name:
@@ -291,112 +432,83 @@ def main(argv):
for path in prunelist:
print(" " + path)
- if result.returncode:
- # Let's perform the merge
- print("Updating remote...")
- subprocess.run(["git", "remote", "update"], check=True)
- subprocess.run(
- [
- "git",
- "checkout",
- "-B",
- opts.release_branch,
- opts.remote_prefix + "/" + opts.release_branch,
- ],
- check=True,
- )
- print("Attempting git merge...")
- if opts.merge_strategy == "recursive" and not opts.strategy_option:
- opts.strategy_option = "theirs"
- print(
- 'Using "%s" merge strategy' % opts.merge_strategy,
- (
- "with strategy option '%s'" % opts.strategy_option
- if opts.strategy_option
- else ""
- ),
- )
- cros_main = opts.remote_prefix + "/" + "main"
- arglist = [
+ # Create the merge and checkout commands to use.
+ cmd_checkout = [
+ "git",
+ "checkout",
+ "-B",
+ opts.release_branch,
+ opts.remote_prefix + "/" + opts.release_branch,
+ ]
+ if opts.merge_strategy == "recursive" and not opts.strategy_option:
+ opts.strategy_option = "theirs"
+ print(
+ 'Using "%s" merge strategy' % opts.merge_strategy,
+ (
+ "with strategy option '%s'" % opts.strategy_option
+ if opts.strategy_option
+ else ""
+ ),
+ )
+ cros_main = opts.remote_prefix + "/" + "main"
+ strategy = [
+ opts.merge_strategy,
+ ]
+ if opts.strategy_option:
+ strategy.append("-X" + opts.strategy_option)
+ cmd = " ".join(argv)
+
+ # Merge each of the repos
+ merge_repo(
+ os.path.join(opts.srcbase, "src/platform/ec"),
+ cros_main,
+ cmd_checkout,
+ strategy,
+ cmd,
+ prunelist,
+ relevant_paths,
+ )
+ if opts.zephyr:
+ # Strip off any trailing -main or -master from branch name
+ if opts.release_branch.endswith("-main"):
+ opts.release_branch = opts.release_branch[:-5]
+ if opts.release_branch.endswith("-master"):
+ opts.release_branch = opts.release_branch[:-7]
+ cmd_checkout = [
"git",
- "merge",
- "--no-ff",
- "--no-commit",
- cros_main,
- "-s",
- opts.merge_strategy,
+ "checkout",
+ "-B",
+ opts.release_branch,
+ opts.remote_prefix + "/" + opts.release_branch,
]
- if opts.strategy_option:
- arglist.append("-X" + opts.strategy_option)
- try:
- subprocess.run(arglist, check=True)
- except:
- # We've likely encountered a merge conflict due to new OWNERS file
- # modifications. If we're removing the owners, we'll delete them.
- if opts.remove_owners and prunelist:
- # Find the unmerged files
- unmerged = (
- subprocess.run(
- ["git", "diff", "--name-only", "--diff-filter=U"],
- stdout=subprocess.PIPE,
- encoding="utf-8",
- check=True,
- )
- .stdout.rstrip()
- .split()
- )
-
- # Prune OWNERS files
- for file in unmerged:
- if file in prunelist:
- subprocess.run(["git", "rm", file], check=False)
- unmerged.remove(file)
-
- print("Removed non-root OWNERS files.")
- if unmerged:
- print(
- "Unmerged files still exist! You need to manually resolve this."
- )
- print("\n".join(unmerged))
- sys.exit(1)
- else:
- raise
- else:
- print(
- "We have already started merge process.",
- "Attempt to generate commit.",
+ prunelist = []
+ if opts.remove_owners:
+ # Remove the top level OWNERS file from the list
+ # to avoid any conflict with the modified branch file.
+ prunelist.append("OWNERS")
+ merge_repo(
+ os.path.join(opts.srcbase, "src/third_party/zephyr/main"),
+ cros_main,
+ cmd_checkout,
+ strategy,
+ cmd,
+ prunelist,
+ [],
+ )
+ # cmsis repo has different remote
+ cros_main = opts.remote_prefix + "/" + "chromeos-main"
+ merge_repo(
+ os.path.join(opts.srcbase, "src/third_party/zephyr/cmsis"),
+ cros_main,
+ cmd_checkout,
+ strategy,
+ cmd,
+ prunelist,
+ [],
)
-
- print("Generating commit message...")
- branch = subprocess.run(
- ["git", "rev-parse", "--abbrev-ref", "HEAD"],
- stdout=subprocess.PIPE,
- encoding="utf-8",
- check=True,
- ).stdout.rstrip()
- head = subprocess.run(
- ["git", "rev-parse", "--short", "HEAD"],
- stdout=subprocess.PIPE,
- encoding="utf-8",
- check=True,
- ).stdout.rstrip()
- merge_head = subprocess.run(
- ["git", "rev-parse", "--short", "MERGE_HEAD"],
- stdout=subprocess.PIPE,
- encoding="utf-8",
- check=True,
- ).stdout.rstrip()
-
- cmd = " ".join(argv)
- print("Typing as fast as I can...")
- commit_msg = git_commit_msg(
- cros_main, branch, head, merge_head, relevant_paths, cmd
- )
- subprocess.run(["git", "commit", "--signoff", "-m", commit_msg], check=True)
- subprocess.run(["git", "commit", "--amend"], check=True)
print(
(
- "Finished! **Please review the commit to see if it's to your "
+ "Finished! **Please review the commit(s) to see if they're to your "
"liking.**"
)
)