From 9012bf1676bd6426229625e2567bfa399f89dabe Mon Sep 17 00:00:00 2001 From: Damien Martin-Guillerez Date: Fri, 16 Dec 2016 16:34:40 +0000 Subject: Fix scripts/packages/convert_changelog to read the changelog correctly Partial fix of #2256 To cherry-pick for #2246 -- Change-Id: Ib25cc1dd85fd4af59b36eb2ac215ebd31d4d9eaa Reviewed-on: https://cr.bazel.build/7975 PiperOrigin-RevId: 142262764 MOS_MIGRATED_REVID=142262764 --- scripts/packages/BUILD | 5 +++-- scripts/packages/convert_changelog.py | 39 ++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 16 deletions(-) (limited to 'scripts/packages') diff --git a/scripts/packages/BUILD b/scripts/packages/BUILD index f324e3a3e9..42d3adf494 100644 --- a/scripts/packages/BUILD +++ b/scripts/packages/BUILD @@ -186,10 +186,11 @@ genrule( name = "generate-changelog-file", srcs = [ "convert_changelog.py", - "//:changelog-file", + "//:bazel-srcs", # Force a rebuild on source change ], outs = ["changelog"], - cmd = "python $(location convert_changelog.py) $(location //:changelog-file) $(location changelog)", + cmd = "python $(location convert_changelog.py) bazel-out/volatile-status.txt $(location changelog)", + stamp = 1, ) genrule( diff --git a/scripts/packages/convert_changelog.py b/scripts/packages/convert_changelog.py index 78edbda914..4868b40d9d 100644 --- a/scripts/packages/convert_changelog.py +++ b/scripts/packages/convert_changelog.py @@ -20,26 +20,37 @@ import sys def main(input_file, output_file): changelog_out = open(output_file, "w") - time_stamp = None + changelog = None + version = None with open(input_file, "r") as changelog_in: for line in changelog_in: line = line.strip() - if line.startswith("```") or line.startswith("Baseline"): - continue + if line.startswith("RELEASE_NOTES"): + changelog = line[14:].strip().replace("\f", "\n") + elif line.startswith("RELEASE_NAME"): + version = line[13:].strip() - if line.startswith("## Release"): - if time_stamp: - changelog_out.write( - "\n -- The Bazel Authors %s\n\n" % - time_stamp) - parts = line.split(" ") - version = parts[2] - time_stamp = datetime.strptime( - parts[3], "(%Y-%m-%d)").strftime("%a, %d %b %Y %H:%M:%S +0100") - changelog_out.write("bazel (%s) unstable; urgency=low\n" % version) + if changelog: + time_stamp = None + lines = changelog.split("\n") + header = lines[0] + lines = lines[4:] # Skip the header + if lines[0] == "Cherry picks:": + # Skip cherry picks list + i = 1 + while lines[i].strip(): + i += 1 + lines = lines[i + 1:] + + # Process header + parts = header.split(" ") + time_stamp = datetime.strptime( + parts[2], "(%Y-%m-%d)").strftime("%a, %d %b %Y %H:%M:%S +0100") + changelog_out.write("bazel (%s) unstable; urgency=low\n" % version) - elif line.startswith("+") or line.startswith("-"): + for line in lines: + if line.startswith("+") or line.startswith("-"): parts = line.split(" ") line = "*" + line[1:] changelog_out.write(" %s\n" % line) -- cgit v1.2.3