Chromium Code Reviews| Index: build/write_build_date_header.py |
| diff --git a/build/write_build_date_header.py b/build/write_build_date_header.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..9ad8eaafa55625166b72e01b0c137bb7f608cc8b |
| --- /dev/null |
| +++ b/build/write_build_date_header.py |
| @@ -0,0 +1,38 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +# Writes a file that contains a define that approximates the build date. |
|
M-A Ruel
2016/02/01 17:52:28
Convert to docstring.
Zachary Forman
2016/02/02 06:30:38
Done!
|
| +# argv[1] is the location to write the file. |
| +# If argv[2] == "--official", returns the current date in UTC. |
| +# Otherwise, returns the first day of the current month (in UTC). |
| +# If argv[2] == "--override", use argv[3] as the build date. |
| + |
| +import sys |
| +from datetime import datetime |
| + |
|
M-A Ruel
2016/02/01 17:52:28
2 lines between file level symbols.
Zachary Forman
2016/02/02 06:30:38
Done!
|
| +def BuildDate(build_type): |
| + if build_type == "--official": |
|
M-A Ruel
2016/02/01 17:52:28
use single quotes everywhere.
Zachary Forman
2016/02/02 06:30:38
Done!
|
| + format = "{:%b %d %Y}" |
| + else: |
| + format = "{:%b 01 %Y}" |
|
M-A Ruel
2016/02/01 17:52:28
I thought about it more and I'd want a slightly mo
Zachary Forman
2016/02/02 06:30:38
I like this idea. I'd want it to switch on Sunday
|
| + return format.format(datetime.utcnow()) |
| + |
| +def main(arguments): |
| + output_location = arguments[1]; |
|
M-A Ruel
2016/02/01 17:52:28
No trailing ;
Zachary Forman
2016/02/02 06:30:38
Done
|
| + build_type = arguments[2] if len(arguments) > 2 else "default" |
|
M-A Ruel
2016/02/01 17:52:28
Please use argparse. It's going to make the script
Zachary Forman
2016/02/02 06:30:38
Done!
|
| + if len(arguments) > 2 and arguments[2] == "--override": |
| + build_date = arguments[3] |
| + else: |
| + build_date = BuildDate(build_type) |
| + with open(output_location, "w") as output_file: |
| + output_file.write("// Generated by //build/write_build_date_header.py\n") |
| + output_file.write("#ifndef BUILD_DATE\n") |
| + output_file.write("#define BUILD_DATE \"{}\"\n".format(build_date)) |
| + output_file.write("#endif // BUILD_DATE\n") |
| + return 0 |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv)) |