Home | History | Annotate | Download | only in build
      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.
      5 
      6 """
      7 appid.py -- Chromium appid header file generation utility.
      8 """
      9 
     10 import optparse
     11 import sys
     12 
     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";
     19 }
     20 """
     21 
     22 def GenerateAppIdHeader(opts):
     23   contents = GENERATED_APPID_INCLUDE_FILE_CONTENTS % opts.appid
     24 
     25   try:
     26     ofp = open(opts.output_file, 'r')
     27   except EnvironmentError:
     28     current_contents = None
     29   else:
     30     current_contents = ofp.read()
     31 
     32   if contents != current_contents:
     33     open(opts.output_file, 'w').write(contents)
     34 
     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')
     41 
     42   (opts, args) = parser.parse_args()
     43 
     44   if opts.appid is None or not opts.output_file:
     45     parser.print_help()
     46     return 1
     47 
     48   # Log a trace in the build output when we run.
     49   print "Generating appid header... ",
     50   GenerateAppIdHeader(opts)
     51 
     52   print "Done."
     53 
     54 
     55 if __name__ == '__main__':
     56   sys.exit(main())
     57