| 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 build_type impacts the timestamp generated: | 7 build_type impacts the timestamp generated: |
| 8 - default: the build date is set to the most recent first Sunday of a month at | 8 - default: the build date is set to the most recent first Sunday of a month at |
| 9 5:00am. The reason is that it is a time where invalidating the build cache | 9 5:00am. The reason is that it is a time where invalidating the build cache |
| 10 shouldn't have major reprecussions (due to lower load). | 10 shouldn't have major reprecussions (due to lower load). |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 if args.build_date_override: | 87 if args.build_date_override: |
| 88 # Format is expected to be "Mmm DD YYYY HH:MM:SS". | 88 # Format is expected to be "Mmm DD YYYY HH:MM:SS". |
| 89 build_date = args.build_date_override | 89 build_date = args.build_date_override |
| 90 else: | 90 else: |
| 91 now = datetime.datetime.utcnow() | 91 now = datetime.datetime.utcnow() |
| 92 if now.hour < 5: | 92 if now.hour < 5: |
| 93 # The time is locked at 5:00 am in UTC to cause the build cache | 93 # The time is locked at 5:00 am in UTC to cause the build cache |
| 94 # invalidation to not happen exactly at midnight. Use the same calculation | 94 # invalidation to not happen exactly at midnight. Use the same calculation |
| 95 # as the day before. | 95 # as the day before. |
| 96 # See //base/build_time.cc. | 96 # See //base/build_time.cc. |
| 97 now = now - datetime.timedelta(day=1) | 97 now = now - datetime.timedelta(days=1) |
| 98 now = datetime.datetime(now.year, now.month, now.day, 5, 0, 0) | 98 now = datetime.datetime(now.year, now.month, now.day, 5, 0, 0) |
| 99 build_date = GetBuildDate(args.build_type, now) | 99 build_date = GetBuildDate(args.build_type, now) |
| 100 | 100 |
| 101 output = ('// Generated by //build/write_build_date_header.py\n' | 101 output = ('// Generated by //build/write_build_date_header.py\n' |
| 102 '#ifndef BUILD_DATE\n' | 102 '#ifndef BUILD_DATE\n' |
| 103 '#define BUILD_DATE "{}"\n' | 103 '#define BUILD_DATE "{}"\n' |
| 104 '#endif // BUILD_DATE\n'.format(build_date)) | 104 '#endif // BUILD_DATE\n'.format(build_date)) |
| 105 | 105 |
| 106 current_contents = '' | 106 current_contents = '' |
| 107 if os.path.isfile(args.output_file): | 107 if os.path.isfile(args.output_file): |
| 108 with open(args.output_file, 'r') as current_file: | 108 with open(args.output_file, 'r') as current_file: |
| 109 current_contents = current_file.read() | 109 current_contents = current_file.read() |
| 110 | 110 |
| 111 if current_contents != output: | 111 if current_contents != output: |
| 112 with open(args.output_file, 'w') as output_file: | 112 with open(args.output_file, 'w') as output_file: |
| 113 output_file.write(output) | 113 output_file.write(output) |
| 114 return 0 | 114 return 0 |
| 115 | 115 |
| 116 | 116 |
| 117 if __name__ == '__main__': | 117 if __name__ == '__main__': |
| 118 sys.exit(main()) | 118 sys.exit(main()) |
| OLD | NEW |