OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Script used to scan for server DLLs at build time and build a header | 6 """Script used to scan for server DLLs at build time and build a header |
7 included by setup.exe. This header contains an array of the names of | 7 included by setup.exe. This header contains an array of the names of |
8 the DLLs that need registering at install time. | 8 the DLLs that need registering at install time. |
9 | 9 |
10 """ | 10 """ |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 """ | 57 """ |
58 output_file = os.path.join(header_output_dir, GENERATED_DLL_INCLUDE_FILE_NAME) | 58 output_file = os.path.join(header_output_dir, GENERATED_DLL_INCLUDE_FILE_NAME) |
59 | 59 |
60 dll_array_string = "" | 60 dll_array_string = "" |
61 for dll in registered_dll_list: | 61 for dll in registered_dll_list: |
62 dll.replace("\\", "\\\\") | 62 dll.replace("\\", "\\\\") |
63 if dll_array_string: | 63 if dll_array_string: |
64 dll_array_string += ', ' | 64 dll_array_string += ', ' |
65 dll_array_string += "L\"%s\"" % dll | 65 dll_array_string += "L\"%s\"" % dll |
66 | 66 |
67 f = open(output_file, 'w') | 67 if len(registered_dll_list) == 0: |
68 contents = GENERATED_DLL_INCLUDE_FILE_CONTENTS % ("L\"\"", 0) | |
69 else: | |
70 contents = GENERATED_DLL_INCLUDE_FILE_CONTENTS % (dll_array_string, | |
71 len(registered_dll_list)) | |
72 | |
73 # Don't rewrite the header file if we don't need to. | |
68 try: | 74 try: |
69 if len(registered_dll_list) == 0: | 75 old_file = open(output_file, 'r') |
70 f.write(GENERATED_DLL_INCLUDE_FILE_CONTENTS % ("L\"\"", 0)) | 76 except EnvironmentError: |
71 else: | 77 old_contents = None |
72 f.write(GENERATED_DLL_INCLUDE_FILE_CONTENTS % (dll_array_string, | 78 else: |
73 len(registered_dll_list))) | 79 old_contents = old_file.read() |
74 finally: | 80 |
kuchhal
2009/09/10 17:08:23
old_file.close() here somewhere
robertshield
2009/09/10 17:30:46
Added, thanks!
| |
75 f.close() | 81 if contents != old_contents: |
82 print 'Updating server dll header: ' + str(output_file) | |
83 open(output_file, 'w').write(contents) | |
76 | 84 |
77 | 85 |
78 def ScanServerDlls(config, distribution, output_dir): | 86 def ScanServerDlls(config, distribution, output_dir): |
79 """Scans for DLLs in the specified section of config that are in the | 87 """Scans for DLLs in the specified section of config that are in the |
80 subdirectory of output_dir named SERVERS_DIR. Returns a list of only the | 88 subdirectory of output_dir named SERVERS_DIR. Returns a list of only the |
81 filename components of the paths to all matching DLLs. | 89 filename components of the paths to all matching DLLs. |
82 """ | 90 """ |
83 | 91 |
92 print "Scanning for server DLLs in " + output_dir | |
93 | |
84 registered_dll_list = [] | 94 registered_dll_list = [] |
85 ScanDllsInSection(config, 'GENERAL', output_dir, registered_dll_list) | 95 ScanDllsInSection(config, 'GENERAL', output_dir, registered_dll_list) |
86 if distribution: | 96 if distribution: |
87 if len(distribution) > 1 and distribution[0] == '_': | 97 if len(distribution) > 1 and distribution[0] == '_': |
88 distribution = distribution[1:] | 98 distribution = distribution[1:] |
89 ScanDllsInSection(config, distribution.upper(), output_dir, | 99 ScanDllsInSection(config, distribution.upper(), output_dir, |
90 registered_dll_list) | 100 registered_dll_list) |
91 | 101 |
92 return registered_dll_list | 102 return registered_dll_list |
93 | 103 |
94 | 104 |
95 def ScanDllsInSection(config, section, output_dir, registered_dll_list): | 105 def ScanDllsInSection(config, section, output_dir, registered_dll_list): |
96 """Scans for DLLs in the specified section of config that are in the | 106 """Scans for DLLs in the specified section of config that are in the |
97 subdirectory of output_dir named SERVERS_DIR. Appends the file name of all | 107 subdirectory of output_dir named SERVERS_DIR. Appends the file name of all |
98 matching dlls to registered_dll_list. | 108 matching dlls to registered_dll_list. |
99 """ | 109 """ |
100 for option in config.options(section): | 110 for option in config.options(section): |
101 if option.endswith('dir'): | 111 if option.endswith('dir'): |
102 continue | 112 continue |
103 | 113 |
104 dst = config.get(section, option) | 114 dst = config.get(section, option) |
105 (x, src_folder) = os.path.split(dst) | 115 (x, src_folder) = os.path.split(dst) |
106 | 116 |
107 for file in glob.glob(os.path.join(output_dir, option)): | 117 for file in glob.glob(os.path.join(output_dir, option)): |
108 if option.startswith(SERVERS_DIR): | 118 if option.startswith(SERVERS_DIR): |
109 (x, file_name) = os.path.split(file) | 119 (x, file_name) = os.path.split(file) |
110 print "Found server DLL file: " + file_name | 120 if file_name.lower().endswith('.dll'): |
111 registered_dll_list.append(file_name) | 121 print "Found server DLL file: " + file_name |
122 registered_dll_list.append(file_name) | |
112 | 123 |
113 | 124 |
114 def RunSystemCommand(cmd): | 125 def RunSystemCommand(cmd): |
115 if (os.system(cmd) != 0): | 126 if (os.system(cmd) != 0): |
116 raise "Error while running cmd: %s" % cmd | 127 raise "Error while running cmd: %s" % cmd |
117 | 128 |
118 | 129 |
119 def main(options): | 130 def main(options): |
120 """Main method that reads input file, scans <build_output>\servers for | 131 """Main method that reads input file, scans <build_output>\servers for |
121 matches to files described in the input file. A header file for the | 132 matches to files described in the input file. A header file for the |
(...skipping 10 matching lines...) Expand all Loading... | |
132 option_parser = optparse.OptionParser() | 143 option_parser = optparse.OptionParser() |
133 option_parser.add_option('-o', '--output_dir', help='Build Output directory') | 144 option_parser.add_option('-o', '--output_dir', help='Build Output directory') |
134 option_parser.add_option('-x', '--header_output_dir', | 145 option_parser.add_option('-x', '--header_output_dir', |
135 help='Location where the generated header file will be placed.') | 146 help='Location where the generated header file will be placed.') |
136 option_parser.add_option('-i', '--input_file', help='Input file') | 147 option_parser.add_option('-i', '--input_file', help='Input file') |
137 option_parser.add_option('-d', '--distribution', | 148 option_parser.add_option('-d', '--distribution', |
138 help='Name of Chromium Distribution. Optional.') | 149 help='Name of Chromium Distribution. Optional.') |
139 | 150 |
140 options, args = option_parser.parse_args() | 151 options, args = option_parser.parse_args() |
141 sys.exit(main(options)) | 152 sys.exit(main(options)) |
OLD | NEW |