blob: 77388288b3bb70737d0fedace0702ed7c9d1d716 [file] [log] [blame]
zforman08d91b72016-02-12 06:23:421#!/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.
Nico Weber967d1f12018-08-17 02:42:025"""Takes a timestamp and writes it in as readable text to a .h file."""
zforman08d91b72016-02-12 06:23:426
7import argparse
zforman08d91b72016-02-12 06:23:428import datetime
9import os
10import sys
11
12
zforman08d91b72016-02-12 06:23:4213def main():
Nico Weber967d1f12018-08-17 02:42:0214 argument_parser = argparse.ArgumentParser()
zforman08d91b72016-02-12 06:23:4215 argument_parser.add_argument('output_file', help='The file to write to')
Greg Thompson05eb6e22018-11-05 12:14:5516 argument_parser.add_argument('timestamp')
zforman08d91b72016-02-12 06:23:4217 args = argument_parser.parse_args()
18
Greg Thompson05eb6e22018-11-05 12:14:5519 date = datetime.datetime.utcfromtimestamp(int(args.timestamp))
zforman08d91b72016-02-12 06:23:4220 output = ('// Generated by //build/write_build_date_header.py\n'
21 '#ifndef BUILD_DATE\n'
Nico Weber967d1f12018-08-17 02:42:0222 '#define BUILD_DATE "{:%b %d %Y %H:%M:%S}"\n'
23 '#endif // BUILD_DATE\n'.format(date))
zforman08d91b72016-02-12 06:23:4224
25 current_contents = ''
26 if os.path.isfile(args.output_file):
27 with open(args.output_file, 'r') as current_file:
28 current_contents = current_file.read()
29
30 if current_contents != output:
31 with open(args.output_file, 'w') as output_file:
32 output_file.write(output)
33 return 0
34
35
36if __name__ == '__main__':
37 sys.exit(main())