Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 """Writes a file that contains a define that approximates the build date. | 5 """Writes a file that contains a define that approximates the build date. |
| 6 | 6 |
| 7 For unofficial builds, the build date is set to the most recent first Sunday | 7 For unofficial builds, the build date is set to the most recent first Sunday |
| 8 of a month, in UTC time. | 8 of a month, in UTC time. |
| 9 | 9 |
| 10 For official builds, the build date is set to the current date (in UTC). | 10 For official builds, the build date is set to the current date (in UTC). |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 argument_parser.add_argument('output_file', help='The file to write to') | 68 argument_parser.add_argument('output_file', help='The file to write to') |
| 69 argument_parser.add_argument('build_type', help='The type of build', | 69 argument_parser.add_argument('build_type', help='The type of build', |
| 70 choices=('official', 'default')) | 70 choices=('official', 'default')) |
| 71 argument_parser.add_argument('build_date_override', nargs='?', | 71 argument_parser.add_argument('build_date_override', nargs='?', |
| 72 help='Optional override for the build date') | 72 help='Optional override for the build date') |
| 73 args = argument_parser.parse_args() | 73 args = argument_parser.parse_args() |
| 74 | 74 |
| 75 if args.build_date_override: | 75 if args.build_date_override: |
| 76 build_date = args.build_date_override | 76 build_date = args.build_date_override |
| 77 else: | 77 else: |
| 78 build_date = GetBuildDate(args.build_type, datetime.datetime.utcnow()) | 78 now = datetime.datetime.utcnow() |
| 79 if now.hour < 5: | |
| 80 # The time is locked at 5:00 am in UTC to cause the build cache | |
| 81 # invalidation to not happen exactly at midnight. Take the day before. | |
| 82 # See //base/build_time.cc. | |
|
Nico
2016/03/30 20:34:00
This should also refer to the script that has the
M-A Ruel
2016/03/30 20:38:09
Humm what about changing the script to output the
| |
| 83 now = now - datetime.timedelta(day=1) | |
| 84 build_date = GetBuildDate(args.build_type, now) | |
| 79 | 85 |
| 80 output = ('// Generated by //build/write_build_date_header.py\n' | 86 output = ('// Generated by //build/write_build_date_header.py\n' |
| 81 '#ifndef BUILD_DATE\n' | 87 '#ifndef BUILD_DATE\n' |
| 82 '#define BUILD_DATE "{}"\n' | 88 '#define BUILD_DATE "{}"\n' |
| 83 '#endif // BUILD_DATE\n'.format(build_date)) | 89 '#endif // BUILD_DATE\n'.format(build_date)) |
| 84 | 90 |
| 85 current_contents = '' | 91 current_contents = '' |
| 86 if os.path.isfile(args.output_file): | 92 if os.path.isfile(args.output_file): |
| 87 with open(args.output_file, 'r') as current_file: | 93 with open(args.output_file, 'r') as current_file: |
| 88 current_contents = current_file.read() | 94 current_contents = current_file.read() |
| 89 | 95 |
| 90 if current_contents != output: | 96 if current_contents != output: |
| 91 with open(args.output_file, 'w') as output_file: | 97 with open(args.output_file, 'w') as output_file: |
| 92 output_file.write(output) | 98 output_file.write(output) |
| 93 return 0 | 99 return 0 |
| 94 | 100 |
| 95 | 101 |
| 96 if __name__ == '__main__': | 102 if __name__ == '__main__': |
| 97 sys.exit(main()) | 103 sys.exit(main()) |
| OLD | NEW |