Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: build/win/importlibs/create_importlib_win.py

Issue 13472015: Quench build spew. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/win/importlibs/create_import_lib.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 """Creates an import library from an import description file.""" 6 """Creates an import library from an import description file."""
7 import ast 7 import ast
8 import logging 8 import logging
9 import optparse 9 import optparse
10 import os 10 import os
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 # Create an .asm file to provide stdcall-like stub names to lib.exe. 109 # Create an .asm file to provide stdcall-like stub names to lib.exe.
110 asm_name = dll_name + '.asm' 110 asm_name = dll_name + '.asm'
111 _LOGGER.info('Writing asm file "%s".', asm_name) 111 _LOGGER.info('Writing asm file "%s".', asm_name)
112 with open(os.path.join(self._temp_dir, asm_name), 'wb') as stubs_file: 112 with open(os.path.join(self._temp_dir, asm_name), 'wb') as stubs_file:
113 self._WriteStubsFile(imports, stubs_file) 113 self._WriteStubsFile(imports, stubs_file)
114 114
115 # Invoke on the assembler to compile it to .obj. 115 # Invoke on the assembler to compile it to .obj.
116 obj_name = dll_name + '.obj' 116 obj_name = dll_name + '.obj'
117 cmdline = ['ml.exe', '/nologo', '/c', asm_name, '/Fo', obj_name] 117 cmdline = ['ml.exe', '/nologo', '/c', asm_name, '/Fo', obj_name]
118 self._Shell(cmdline, cwd=self._temp_dir) 118 self._Shell(cmdline, cwd=self._temp_dir, stdout=open(os.devnull))
119 119
120 return obj_name 120 return obj_name
121 121
122 def _CreateImportLib(self, dll_name, imports, architecture, output_file): 122 def _CreateImportLib(self, dll_name, imports, architecture, output_file):
123 """Creates an import lib binding imports to dll_name for architecture. 123 """Creates an import lib binding imports to dll_name for architecture.
124 124
125 On success, writes the import library to output file. 125 On success, writes the import library to output file.
126 """ 126 """
127 obj_file = None 127 obj_file = None
128 128
(...skipping 15 matching lines...) Expand all
144 # don't want those files potentially gunking the works. 144 # don't want those files potentially gunking the works.
145 dll_base_name, ext = os.path.splitext(dll_name) 145 dll_base_name, ext = os.path.splitext(dll_name)
146 lib_name = dll_base_name + '.lib' 146 lib_name = dll_base_name + '.lib'
147 cmdline = ['lib.exe', 147 cmdline = ['lib.exe',
148 '/machine:%s' % architecture, 148 '/machine:%s' % architecture,
149 '/def:%s' % def_name, 149 '/def:%s' % def_name,
150 '/out:%s' % lib_name] 150 '/out:%s' % lib_name]
151 if obj_file: 151 if obj_file:
152 cmdline.append(obj_file) 152 cmdline.append(obj_file)
153 153
154 self._Shell(cmdline, cwd=self._temp_dir) 154 self._Shell(cmdline, cwd=self._temp_dir, stdout=open(os.devnull))
155 155
156 # Copy the .lib file to the output directory. 156 # Copy the .lib file to the output directory.
157 shutil.copyfile(os.path.join(self._temp_dir, lib_name), output_file) 157 shutil.copyfile(os.path.join(self._temp_dir, lib_name), output_file)
158 _LOGGER.info('Created "%s".', output_file) 158 _LOGGER.info('Created "%s".', output_file)
159 159
160 def CreateImportLib(self, imports_file, output_file): 160 def CreateImportLib(self, imports_file, output_file):
161 # Read the imports file. 161 # Read the imports file.
162 imports = self._ReadImportsFile(imports_file) 162 imports = self._ReadImportsFile(imports_file)
163 163
164 # Creates the requested import library in the output directory. 164 # Creates the requested import library in the output directory.
165 self._CreateImportLib(imports['dll_name'], 165 self._CreateImportLib(imports['dll_name'],
166 imports['imports'], 166 imports['imports'],
167 imports.get('architecture', 'x86'), 167 imports.get('architecture', 'x86'),
168 output_file) 168 output_file)
169 169
170 170
171 def main(): 171 def main():
172 parser = optparse.OptionParser(usage=_USAGE) 172 parser = optparse.OptionParser(usage=_USAGE)
173 parser.add_option('-o', '--output-file', 173 parser.add_option('-o', '--output-file',
174 help='Specifies the output file path.') 174 help='Specifies the output file path.')
175 parser.add_option('-k', '--keep-temp-dir', 175 parser.add_option('-k', '--keep-temp-dir',
176 action='store_true', 176 action='store_true',
177 help='Keep the temporary directory.') 177 help='Keep the temporary directory.')
178 parser.add_option('-v', '--verbose', 178 parser.add_option('-v', '--verbose',
179 action='store_true', 179 action='store_true',
180 help='Verbose logging.') 180 help='Verbose logging.')
181 181
182 options, args = parser.parse_args() 182 options, args = parser.parse_args()
183 183
184 print args
185 if len(args) != 1: 184 if len(args) != 1:
186 parser.error('You must provide an imports file.') 185 parser.error('You must provide an imports file.')
187 186
188 if not options.output_file: 187 if not options.output_file:
189 parser.error('You must provide an output file.') 188 parser.error('You must provide an output file.')
190 189
191 options.output_file = os.path.abspath(options.output_file) 190 options.output_file = os.path.abspath(options.output_file)
192 191
193 if options.verbose: 192 if options.verbose:
194 logging.basicConfig(level=logging.INFO) 193 logging.basicConfig(level=logging.INFO)
195 else: 194 else:
196 logging.basicConfig(level=logging.WARN) 195 logging.basicConfig(level=logging.WARN)
197 196
198 197
199 temp_dir = tempfile.mkdtemp() 198 temp_dir = tempfile.mkdtemp()
200 _LOGGER.info('Created temporary directory "%s."', temp_dir) 199 _LOGGER.info('Created temporary directory "%s."', temp_dir)
201 try: 200 try:
202 # Create a generator and create the import lib. 201 # Create a generator and create the import lib.
203 generator = _ImportLibraryGenerator(temp_dir) 202 generator = _ImportLibraryGenerator(temp_dir)
204 203
205 ret = generator.CreateImportLib(args[0], options.output_file) 204 ret = generator.CreateImportLib(args[0], options.output_file)
206 except Exception, e: 205 except Exception, e:
207 _LOGGER.exception('Failed to create imports.') 206 _LOGGER.exception('Failed to create import lib.')
208 ret = 1 207 ret = 1
209 finally: 208 finally:
210 if not options.keep_temp_dir: 209 if not options.keep_temp_dir:
211 shutil.rmtree(temp_dir) 210 shutil.rmtree(temp_dir)
212 _LOGGER.info('Deleted temporary directory "%s."', temp_dir) 211 _LOGGER.info('Deleted temporary directory "%s."', temp_dir)
213 212
214 return ret 213 return ret
215 214
216 215
217 if __name__ == '__main__': 216 if __name__ == '__main__':
218 sys.exit(main()) 217 sys.exit(main())
OLDNEW
« no previous file with comments | « build/win/importlibs/create_import_lib.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698