PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/chrome/tools/build/win/scan_server_dlls.py

https://github.com/akesling/chromium
Python | 141 lines | 129 code | 3 blank | 9 comment | 1 complexity | bd1d82073df570a8644c07b9997f7367 MD5 | raw file
  1. #!/usr/bin/python
  2. # Copyright (c) 2006-2008 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. """Script used to scan for server DLLs at build time and build a header
  6. included by setup.exe. This header contains an array of the names of
  7. the DLLs that need registering at install time.
  8. """
  9. import ConfigParser
  10. import glob
  11. import optparse
  12. import os
  13. import sys
  14. CHROME_DIR = "Chrome-bin"
  15. SERVERS_DIR = "servers"
  16. GENERATED_DLL_INCLUDE_FILE_NAME = "registered_dlls.h"
  17. GENERATED_DLL_INCLUDE_FILE_CONTENTS = """
  18. // This file is automatically generated by scan_server_dlls.py.
  19. // It contains the list of COM server dlls that need registering at
  20. // install time.
  21. #include "base/basictypes.h"
  22. namespace {
  23. const wchar_t* kDllsToRegister[] = { %s };
  24. const int kNumDllsToRegister = %d;
  25. }
  26. """
  27. def Readconfig(output_dir, input_file):
  28. """Reads config information from input file after setting default value of
  29. global variabes.
  30. """
  31. variables = {}
  32. variables['ChromeDir'] = CHROME_DIR
  33. # Use a bogus version number, we don't really care what it is, we just
  34. # want to find the files that would get picked up from chrome.release,
  35. # and don't care where the installer archive task ends up putting them.
  36. variables['VersionDir'] = os.path.join(variables['ChromeDir'],
  37. '0.0.0.0')
  38. config = ConfigParser.SafeConfigParser(variables)
  39. print "Reading input_file: " + input_file
  40. config.read(input_file)
  41. return config
  42. def CreateRegisteredDllIncludeFile(registered_dll_list, header_output_dir):
  43. """ Outputs the header file included by the setup project that
  44. contains the names of the DLLs to be registered at installation
  45. time.
  46. """
  47. output_file = os.path.join(header_output_dir, GENERATED_DLL_INCLUDE_FILE_NAME)
  48. dll_array_string = ""
  49. for dll in registered_dll_list:
  50. dll.replace("\\", "\\\\")
  51. if dll_array_string:
  52. dll_array_string += ', '
  53. dll_array_string += "L\"%s\"" % dll
  54. f = open(output_file, 'w')
  55. try:
  56. if len(registered_dll_list) == 0:
  57. f.write(GENERATED_DLL_INCLUDE_FILE_CONTENTS % ("L\"\"", 0))
  58. else:
  59. f.write(GENERATED_DLL_INCLUDE_FILE_CONTENTS % (dll_array_string,
  60. len(registered_dll_list)))
  61. finally:
  62. f.close()
  63. def ScanServerDlls(config, distribution, output_dir):
  64. """Scans for DLLs in the specified section of config that are in the
  65. subdirectory of output_dir named SERVERS_DIR. Returns a list of only the
  66. filename components of the paths to all matching DLLs.
  67. """
  68. registered_dll_list = []
  69. ScanDllsInSection(config, 'GENERAL', output_dir, registered_dll_list)
  70. if distribution:
  71. if len(distribution) > 1 and distribution[0] == '_':
  72. distribution = distribution[1:]
  73. ScanDllsInSection(config, distribution.upper(), output_dir,
  74. registered_dll_list)
  75. return registered_dll_list
  76. def ScanDllsInSection(config, section, output_dir, registered_dll_list):
  77. """Scans for DLLs in the specified section of config that are in the
  78. subdirectory of output_dir named SERVERS_DIR. Appends the file name of all
  79. matching dlls to registered_dll_list.
  80. """
  81. for option in config.options(section):
  82. if option.endswith('dir'):
  83. continue
  84. dst = config.get(section, option)
  85. (x, src_folder) = os.path.split(dst)
  86. for file in glob.glob(os.path.join(output_dir, option)):
  87. if option.startswith(SERVERS_DIR):
  88. (x, file_name) = os.path.split(file)
  89. print "Found server DLL file: " + file_name
  90. registered_dll_list.append(file_name)
  91. def RunSystemCommand(cmd):
  92. if (os.system(cmd) != 0):
  93. raise "Error while running cmd: %s" % cmd
  94. def main(options):
  95. """Main method that reads input file, scans <build_output>\servers for
  96. matches to files described in the input file. A header file for the
  97. setup project is then generated.
  98. """
  99. config = Readconfig(options.output_dir, options.input_file)
  100. registered_dll_list = ScanServerDlls(config, options.distribution,
  101. options.output_dir)
  102. CreateRegisteredDllIncludeFile(registered_dll_list,
  103. options.header_output_dir)
  104. if '__main__' == __name__:
  105. option_parser = optparse.OptionParser()
  106. option_parser.add_option('-o', '--output_dir', help='Build Output directory')
  107. option_parser.add_option('-x', '--header_output_dir',
  108. help='Location where the generated header file will be placed.')
  109. option_parser.add_option('-i', '--input_file', help='Input file')
  110. option_parser.add_option('-d', '--distribution',
  111. help='Name of Chromium Distribution. Optional.')
  112. options, args = option_parser.parse_args()
  113. sys.exit(main(options))