|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import argparse |
| 4 | +import os.path |
| 5 | +import subprocess |
| 6 | +import sys |
| 7 | +import re |
| 8 | + |
| 9 | +parser = argparse.ArgumentParser( |
| 10 | + description="Generate a changelog for an engineering build or RC of ARC GNU Toolchain.") |
| 11 | +parser.add_argument("--src-dir", required=True, |
| 12 | + help="Root of toolchain source directories.") |
| 13 | +parser.add_argument("--tag", required=True, |
| 14 | + help="Git tag of a new build.") |
| 15 | +parser.add_argument("--max-commits", default=50, type=int, |
| 16 | + help="Maximum number of commits printed for one project.") |
| 17 | + |
| 18 | +args = parser.parse_args() |
| 19 | + |
| 20 | +repos = ["binutils", "gcc", "gdb", "newlib", "toolchain", "uClibc" ] |
| 21 | + |
| 22 | +new_tag = args.tag |
| 23 | + |
| 24 | +# Build an old tag. RC and eng build has different formats. |
| 25 | +build_num_m = re.search("\D*(\d+)$", new_tag) |
| 26 | +build_num = int(build_num_m.group(1)) |
| 27 | +old_tag = new_tag[0:build_num_m.start(1)] |
| 28 | +if old_tag.endswith("-eng"): |
| 29 | + old_tag += "{0:03}".format(build_num - 1) |
| 30 | +else: |
| 31 | + old_tag += str(build_num - 1) |
| 32 | + |
| 33 | +git="git" |
| 34 | + |
| 35 | +def git_command(*args): |
| 36 | + a = [git, git_dir] |
| 37 | + a.extend(args) |
| 38 | + return subprocess.check_output(a, universal_newlines=True) |
| 39 | + |
| 40 | +for repo in repos: |
| 41 | + git_dir = "--git-dir=" + os.path.join(args.src_dir, repo, ".git") |
| 42 | + # For GDB tag is different. |
| 43 | + new_tag_effective = new_tag if repo != "gdb" else new_tag + "-gdb" |
| 44 | + old_tag_effective = old_tag if repo != "gdb" else old_tag + "-gdb" |
| 45 | + |
| 46 | + # First get commit ids. Use ^{} to get an ID of an actual commit, not an ID of a tag. |
| 47 | + new_commit_id = git_command("rev-parse", new_tag_effective + "^{}") |
| 48 | + old_commit_id = git_command("rev-parse", old_tag_effective + "^{}") |
| 49 | + |
| 50 | + # Same? Nothing to do. |
| 51 | + if old_commit_id == new_commit_id: |
| 52 | + continue |
| 53 | + |
| 54 | + print() |
| 55 | + print(repo) |
| 56 | + # Underline the header. |
| 57 | + print('-' * max(len(repo), 7)) |
| 58 | + |
| 59 | + # Find the common base commit. |
| 60 | + merge_base_id = git_command("merge-base", new_tag_effective, old_tag_effective) |
| 61 | + |
| 62 | + # If it is the same as "old" then history is linear, no rebases, just use |
| 63 | + # normal `git log --oneline`. |
| 64 | + if merge_base_id == old_commit_id: |
| 65 | + log_cmd = ["log", "--oneline", "{0}..{1}".format(old_tag_effective, new_tag_effective)] |
| 66 | + else: |
| 67 | + log_cmd = ["show-branch", old_tag_effective, new_tag_effective] |
| 68 | + |
| 69 | + out = git_command(*log_cmd).splitlines() |
| 70 | + |
| 71 | + if len(out) < args.max_commits: |
| 72 | + print("\n".join(out)) |
| 73 | + else: |
| 74 | + print("!!!Output is too long and has been truncated!!!") |
| 75 | + print("\n".join(out[0:args.max_commits])) |
| 76 | + |
| 77 | +# vim: expandtab |
0 commit comments