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

Side by Side 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: Addresses comments (#85-#89) 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 unified diff | Download patch
« no previous file with comments | « build/config/posix/BUILD.gn ('k') | components/ssl_errors/error_classification.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 For unofficial builds, the build date is set to the most recent first Sunday
8 of a month, in UTC time.
9
10 For official builds, the build date is set to the current date (in UTC).
11
12 It is also possible to explicitly set a build date to be used.
13
14 The reason for using the first Sunday of a month for unofficial builds is that
15 it is a time where invalidating the build cache shouldn't have major
16 reprecussions (due to lower load).
17 """
18
19 import argparse
20 import calendar
21 import datetime
22 import os
23 import sys
24
25
26 def GetFirstSundayOfMonth(month, year):
27 """Returns the first sunday of the given month of the given year."""
28 weeks = calendar.Calendar().monthdays2calendar(year, month)
29 # Return the first day in the first week that is a Sunday.
30 return [date_day[0] for date_day in weeks[0] if date_day[1] == 6][0]
31
32
33 def GetBuildDate(build_type):
34 """Gets the approximate build date given the specific build type."""
35 gmt_now = datetime.datetime.utcnow()
36 day = gmt_now.day
37 month = gmt_now.month
38 year = gmt_now.year
39 if build_type != 'official':
40 first_sunday = GetFirstSundayOfMonth(month, year)
41 # If our build is after the first Sunday, we've already refreshed our build
42 # cache on a quiet day, so just use that day.
43 # Otherwise, take the first Sunday of the previous month.
44 if day >= first_sunday:
45 day = first_sunday
46 else:
47 month -= 1
48 if month == 0:
49 month = 12
50 year -= 1
51 day = GetFirstSundayOfMonth(month, year)
52 return "{:%b %d %Y}".format(datetime.date(year, month, day))
M-A Ruel 2016/02/09 21:00:58 single quote
Zachary Forman 2016/02/09 22:12:53 Fixed
53
54
55 def main():
56 argument_parser = argparse.ArgumentParser()
57 argument_parser.add_argument('output_file', help='The file to write to')
58 argument_parser.add_argument('build_type', help='The type of build',
59 choices=("official", "default"))
60 argument_parser.add_argument('build_date_override', nargs='?',
61 help='Optional override for the build date')
62 args = argument_parser.parse_args()
63
64 if args.build_date_override:
65 build_date = args.build_date_override
66 else:
67 build_date = GetBuildDate(args.build_type)
68
69 output = ('// Generated by //build/write_build_date_header.py\n'
70 '#ifndef BUILD_DATE\n'
71 '#define BUILD_DATE "{}"\n'
72 '#endif // BUILD_DATE\n'.format(build_date))
73
74 current_contents = ""
M-A Ruel 2016/02/09 21:00:58 single quote
Zachary Forman 2016/02/09 22:12:53 Fixed
75 if os.path.isfile(args.output_file):
76 with open(args.output_file, 'r') as current_file:
77 current_contents = current_file.read()
78
79 if current_contents != output:
80 with open(args.output_file, 'w') as output_file:
81 output_file.write(output)
82 return 0
83
84
85 if __name__ == '__main__':
86 sys.exit(main())
OLDNEW
« no previous file with comments | « build/config/posix/BUILD.gn ('k') | components/ssl_errors/error_classification.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698