Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3458)

Unified Diff: build/write_build_date_header.py

Issue 1641413002: Makes GetBuildTime behave identically on all build types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Hook based approach Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/write_build_date_header.py
diff --git a/build/write_build_date_header.py b/build/write_build_date_header.py
new file mode 100755
index 0000000000000000000000000000000000000000..497f845d651d6a74170e9d081e080746dddabb82
--- /dev/null
+++ b/build/write_build_date_header.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+# Copyright (c) 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Writes a file that contains a define that approximates the build date.
+
+The build date is set to the most recent first Sunday of a month, in UTC time,
+or to the current date in an official build.
+"""
+
+import argparse
+import calendar
+import datetime
+import sys
+
+
+def GetFirstSundayOfMonth(month, year):
+ """Returns the first sunday of the given month of the given year."""
+ weeks = calendar.Calendar().monthdays2calendar(year, month)
+ # Return the first day in the first week that is a Sunday.
+ return [date_day[0] for date_day in weeks[0] if date_day[1] == 6][0]
+
+
+def GetBuildDate(build_type):
+ """Gets the approximate build date given the specific build type."""
+ gmt_now = datetime.datetime.utcnow()
+ day = gmt_now.day
+ month = gmt_now.month
+ year = gmt_now.year
+ if build_type != 'official':
+ first_sunday = GetFirstSundayOfMonth(month, year)
+ # If our build is after the first Sunday, we've already refreshed our build
+ # cache on a quiet day, so just use that day.
+ # Otherwise, take the first Sunday of the previous month.
+ if day >= first_sunday:
+ day = first_sunday
+ else:
+ month -= 1
+ if month == 0:
+ month = 12
+ year -= 1
+ day = GetFirstSundayOfMonth(month, year)
+ return "{:%b %d %Y}".format(datetime.date(year, month, day))
+
+
+def main():
+ argument_parser = argparse.ArgumentParser()
+ argument_parser.add_argument('output_file', help='The file to write to')
+ argument_parser.add_argument('build_date_override', nargs='?',
+ help='Optional override for the build date')
+ args = argument_parser.parse_args()
+
+ official_build_date = GetBuildDate('official')
+ default_build_date = GetBuildDate('default')
+ if build_date_override:
+ official_build_date = default_build_date = build_date_override
+
+ with open(args.output_file, 'w') as output_file:
M-A Ruel 2016/02/05 19:16:37 Change to: - construct the content - read the fil
Zachary Forman 2016/02/09 00:02:04 Done
+ output_file.write('// Generated by //build/write_build_date_header.py\n')
+ output_file.write('#ifndef BUILD_DATE\n')
+ output_file.write('#ifdef OFFICIAL_BUILD\n')
+ output_file.write('#define BUILD_DATE \"{}\"\n'.format(official_build_date))
+ output_file.write('#else\n')
+ output_file.write('#define BUILD_DATE \"{}\"\n'.format(default_build_date))
+ output_file.write('#endif // OFFICIAL_BUILD\n')
+ output_file.write('#endif // BUILD_DATE\n')
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())

Powered by Google App Engine
This is Rietveld 408576698