Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 """Writes a file that contains a define that approximates the build date. | |
| 6 | |
| 7 The build date is set to the most recent first Sunday of a month, in UTC time, | |
| 8 or to the current date in an official build. | |
| 9 """ | |
| 10 | |
| 11 import argparse | |
| 12 import calendar | |
| 13 import datetime | |
| 14 import sys | |
| 15 | |
| 16 | |
| 17 def GetFirstSundayOfMonth(month, year): | |
| 18 """Returns the first sunday of the given month of the given year.""" | |
| 19 weeks = calendar.Calendar().monthdays2calendar(year, month) | |
| 20 # Return the first day in the first week that is a Sunday. | |
| 21 return [date_day[0] for date_day in weeks[0] if date_day[1] == 6][0] | |
| 22 | |
| 23 | |
| 24 def GetBuildDate(build_type): | |
| 25 """Gets the approximate build date given the specific build type.""" | |
| 26 gmt_now = datetime.datetime.utcnow() | |
| 27 day = gmt_now.day | |
| 28 month = gmt_now.month | |
| 29 year = gmt_now.year | |
| 30 if build_type != 'official': | |
| 31 first_sunday = GetFirstSundayOfMonth(month, year) | |
| 32 # If our build is after the first Sunday, we've already refreshed our build | |
| 33 # cache on a quiet day, so just use that day. | |
| 34 # Otherwise, take the first Sunday of the previous month. | |
| 35 if day >= first_sunday: | |
| 36 day = first_sunday | |
| 37 else: | |
| 38 month -= 1 | |
| 39 if month == 0: | |
| 40 month = 12 | |
| 41 year -= 1 | |
| 42 day = GetFirstSundayOfMonth(month, year) | |
| 43 return "{:%b %d %Y}".format(datetime.date(year, month, day)) | |
| 44 | |
| 45 | |
| 46 def main(): | |
| 47 argument_parser = argparse.ArgumentParser() | |
| 48 argument_parser.add_argument('output_file', help='The file to write to') | |
| 49 argument_parser.add_argument('build_date_override', nargs='?', | |
| 50 help='Optional override for the build date') | |
| 51 args = argument_parser.parse_args() | |
| 52 | |
| 53 official_build_date = GetBuildDate('official') | |
| 54 default_build_date = GetBuildDate('default') | |
| 55 if build_date_override: | |
| 56 official_build_date = default_build_date = build_date_override | |
| 57 | |
| 58 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
| |
| 59 output_file.write('// Generated by //build/write_build_date_header.py\n') | |
| 60 output_file.write('#ifndef BUILD_DATE\n') | |
| 61 output_file.write('#ifdef OFFICIAL_BUILD\n') | |
| 62 output_file.write('#define BUILD_DATE \"{}\"\n'.format(official_build_date)) | |
| 63 output_file.write('#else\n') | |
| 64 output_file.write('#define BUILD_DATE \"{}\"\n'.format(default_build_date)) | |
| 65 output_file.write('#endif // OFFICIAL_BUILD\n') | |
| 66 output_file.write('#endif // BUILD_DATE\n') | |
| 67 return 0 | |
| 68 | |
| 69 | |
| 70 if __name__ == '__main__': | |
| 71 sys.exit(main()) | |
| OLD | NEW |