blob: a4fb78eb428e745f549dffd751df2b27009d85ce [file] [log] [blame]
Yun Penga50635d2016-07-26 13:29:03 +00001# pylint: disable=g-bad-file-header
2# Copyright 2015 The Bazel Authors. All rights reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15"""This tool convert Bazel's changelog file to debian changelog format."""
16
17from datetime import datetime
18import sys
19
20
Damien Martin-Guillerez332b61f2016-12-20 07:47:35 +000021def main(input_file, changelog_file, output_file):
Yun Penga50635d2016-07-26 13:29:03 +000022 changelog_out = open(output_file, "w")
Damien Martin-Guillerez332b61f2016-12-20 07:47:35 +000023 changelog = None
24 version = None
25 with open(input_file, "r") as status_file:
26 for line in status_file:
Yun Penga50635d2016-07-26 13:29:03 +000027 line = line.strip()
28
Damien Martin-Guillerez332b61f2016-12-20 07:47:35 +000029 if line.startswith("RELEASE_NOTES"):
30 changelog = line[14:].strip().replace("\f", "\n")
31 elif line.startswith("RELEASE_NAME"):
32 version = line[13:].strip()
Yun Penga50635d2016-07-26 13:29:03 +000033
Damien Martin-Guillerez332b61f2016-12-20 07:47:35 +000034 if changelog:
35 time_stamp = None
36 lines = changelog.split("\n")
37 header = lines[0]
38 lines = lines[4:] # Skip the header
39 if lines[0] == "Cherry picks:":
40 # Skip cherry picks list
41 i = 1
42 while lines[i].strip():
43 i += 1
44 lines = lines[i + 1:]
Yun Penga50635d2016-07-26 13:29:03 +000045
Damien Martin-Guillerez332b61f2016-12-20 07:47:35 +000046 # Process header
47 parts = header.split(" ")
48 time_stamp = datetime.strptime(
49 parts[2], "(%Y-%m-%d)").strftime("%a, %d %b %Y %H:%M:%S +0100")
50 changelog_out.write("bazel (%s) unstable; urgency=low\n" % version)
51
52 for line in lines:
53 if line.startswith("+") or line.startswith("-"):
Yun Penga50635d2016-07-26 13:29:03 +000054 parts = line.split(" ")
55 line = "*" + line[1:]
56 changelog_out.write(" %s\n" % line)
57
58 elif line.endswith(":"):
59 changelog_out.write("\n %s\n" % line)
60
61 elif line:
62 changelog_out.write(" %s\n" % line)
63
64 if time_stamp:
65 changelog_out.write(
66 "\n -- The Bazel Authors <bazel-dev@googlegroups.com> %s\n\n" %
67 time_stamp)
Damien Martin-Guillerez332b61f2016-12-20 07:47:35 +000068 else:
69 # Develeopment version, generate a changelog from the change log file
70 with open(changelog_file, "r") as changelog_in:
71 for line in changelog_in:
72 line = line.strip()
73 if line.startswith("## Release"):
74 parts = line.split(" ")
75 version = parts[2]
76 time_stamp = datetime.strptime(
77 parts[3], "(%Y-%m-%d)").strftime("%a, %d %b %Y %H:%M:%S +0100")
78 changelog_out.write("bazel (%s~HEAD) unstable; urgency=low\n" %
79 version)
80 changelog_out.write(" Development version\n")
81 changelog_out.write(
82 "\n -- The Bazel Authors <bazel-dev@googlegroups.com> %s\n\n" %
83 time_stamp)
84 # Stop after parsing latest release
85 return
Yun Penga50635d2016-07-26 13:29:03 +000086
John Caterb0308d42017-01-30 17:49:26 +000087
Yun Penga50635d2016-07-26 13:29:03 +000088if __name__ == "__main__":
Damien Martin-Guillerez332b61f2016-12-20 07:47:35 +000089 main(sys.argv[1], sys.argv[2], sys.argv[3])