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 """Takes a timestamp and writes it in as readable text to a .h file."""
14 argument_parser = argparse.ArgumentParser()
15 argument_parser.add_argument('output_file', help='The file to write to')
16 argument_parser.add_argument('timestamp')
17 args = argument_parser.parse_args()
19 date = datetime.datetime.utcfromtimestamp(int(args.timestamp))
20 output = ('// Generated by //build/write_build_date_header.py\n'
21 '#ifndef BUILD_DATE\n'
22 '#define BUILD_DATE "{:%b %d %Y %H:%M:%S}"\n'
23 '#endif // BUILD_DATE\n'.format(date))
26 if os.path.isfile(args.output_file):
27 with open(args.output_file, 'r') as current_file:
28 current_contents = current_file.read()
30 if current_contents != output:
31 with open(args.output_file, 'w') as output_file:
32 output_file.write(output)
36 if __name__ == '__main__':