Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / tools / build / appid.py
blobd052bc322bd83e7525e2aa78403057f78bbf3913
1 #!/usr/bin/env python
2 # Copyright (c) 2011 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.
6 """
7 appid.py -- Chromium appid header file generation utility.
8 """
10 import optparse
11 import sys
13 GENERATED_APPID_INCLUDE_FILE_CONTENTS = """
14 // This file is automatically generated by appid.py.
15 // It contains the Google Update Appid used for this build. Note that
16 // the Appid will be empty for non Google Chrome builds.
17 namespace google_update {
18 const wchar_t kChromeGuid[] = L"%s";
20 """
22 def GenerateAppIdHeader(opts):
23 contents = GENERATED_APPID_INCLUDE_FILE_CONTENTS % opts.appid
25 try:
26 ofp = open(opts.output_file, 'r')
27 except EnvironmentError:
28 current_contents = None
29 else:
30 current_contents = ofp.read()
32 if contents != current_contents:
33 open(opts.output_file, 'w').write(contents)
35 def main():
36 parser = optparse.OptionParser()
37 parser.add_option('-a', '--appid',
38 help='The Google Update App Id of the Chrome being built.')
39 parser.add_option('-o', '--output_file',
40 help='The path to the generated output header file')
42 (opts, args) = parser.parse_args()
44 if opts.appid is None or not opts.output_file:
45 parser.print_help()
46 return 1
48 # Log a trace in the build output when we run.
49 print "Generating appid header... ",
50 GenerateAppIdHeader(opts)
52 print "Done."
55 if __name__ == '__main__':
56 sys.exit(main())