1
- import logging , collections , os , re , sys
1
+ import logging
2
+ import collections
3
+ import os
4
+ import re
5
+ import sys
2
6
3
7
# Internal logger
4
8
_logger = logging .getLogger (__name__ )
@@ -123,8 +127,8 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
123
127
# Debug
124
128
'-g' : (0 , ArgumentListFilter .compileUnaryCallback ),
125
129
'-g0' : (0 , ArgumentListFilter .compileUnaryCallback ), #iam: clang not gcc
126
- '-ggdb' : (0 , ArgumentListFilter .compileUnaryCallback ),
127
- '-ggdb3' : (0 , ArgumentListFilter .compileUnaryCallback ),
130
+ '-ggdb' : (0 , ArgumentListFilter .compileUnaryCallback ),
131
+ '-ggdb3' : (0 , ArgumentListFilter .compileUnaryCallback ),
128
132
'-gdwarf-2' : (0 , ArgumentListFilter .compileUnaryCallback ),
129
133
'-gdwarf-3' : (0 , ArgumentListFilter .compileUnaryCallback ),
130
134
'-gline-tables-only' : (0 , ArgumentListFilter .compileUnaryCallback ),
@@ -185,7 +189,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
185
189
# (the Darwin ld is a bit single minded)
186
190
#
187
191
# 1) compilation with -fvisibility=hidden causes trouble when we try to
188
- # attach bitcode filenames to an object file. The global symbols in object
192
+ # attach bitcode filenames to an object file. The global symbols in object
189
193
# files get turned into local symbols when we invoke 'ld -r'
190
194
#
191
195
# 2) all stripping commands (e.g., -dead_strip) remove the __LLVM segment after
@@ -195,8 +199,8 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
195
199
# calling ld -r.
196
200
#
197
201
'-Wl,-dead_strip' : (0 , ArgumentListFilter .darwinWarningLinkUnaryCallback ),
198
-
199
- }
202
+
203
+ }
200
204
201
205
#
202
206
# Patterns for other command-line arguments:
@@ -227,15 +231,15 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
227
231
r'^--sysroot=.+$' : (0 , ArgumentListFilter .compileUnaryCallback ),
228
232
r'^-print-prog-name=.*$' : (0 , ArgumentListFilter .compileUnaryCallback ),
229
233
r'^-print-file-name=.*$' : (0 , ArgumentListFilter .compileUnaryCallback ),
230
-
234
+
231
235
}
232
236
233
237
#iam: try and keep track of the files, input object, and output
234
238
self .inputList = inputList
235
239
self .inputFiles = []
236
240
self .objectFiles = []
237
241
self .outputFilename = None
238
-
242
+
239
243
#iam: try and split the args into linker and compiler switches
240
244
self .compileArgs = []
241
245
self .linkArgs = []
@@ -256,10 +260,10 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
256
260
self ._inputArgs = collections .deque (inputList )
257
261
258
262
#iam: parse the cmd line, bailing if we discover that there will be no second phase.
259
- while ( len (self ._inputArgs ) > 0 and
260
- not (self .isAssembly or
261
- self .isAssembleOnly or
262
- self .isPreprocessOnly ) ):
263
+ while (len (self ._inputArgs ) > 0 and
264
+ not (self .isAssembly or
265
+ self .isAssembleOnly or
266
+ self .isPreprocessOnly ) ):
263
267
# Get the next argument
264
268
currentItem = self ._inputArgs .popleft ()
265
269
_logger .debug ('Trying to match item ' + currentItem )
@@ -281,7 +285,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
281
285
# If no action has been specified, this is a zero-argument
282
286
# flag that we should just keep.
283
287
if not matched :
284
- _logger .warning ('Did not recognize the compiler flag "{0}"' . format ( currentItem ) )
288
+ _logger .warning ('Did not recognize the compiler flag "%s"' , currentItem )
285
289
self .compileUnaryCallback (currentItem )
286
290
287
291
if DUMPING :
@@ -296,69 +300,83 @@ def _shiftArgs(self, nargs):
296
300
return ret
297
301
298
302
def abortUnaryCallback (self , flag ):
299
- _logger .warning ('Out of context experience: "{0}"' . format ( str (self .inputList )) )
303
+ _logger .warning ('Out of context experience: "%s" "%s"' , str (self .inputList ), flag )
300
304
sys .exit (1 )
301
305
302
306
def inputFileCallback (self , infile ):
303
- _logger .debug ('Input file: ' + infile )
307
+ _logger .debug ('Input file: %s' , infile )
304
308
self .inputFiles .append (infile )
305
309
if re .search ('\\ .(s|S)$' , infile ):
306
310
self .isAssembly = True
307
311
308
312
def outputFileCallback (self , flag , filename ):
313
+ _logger .debug ('outputFileCallback: %s %s' , flag , filename )
309
314
self .outputFilename = filename
310
315
311
316
def objectFileCallback (self , objfile ):
317
+ _logger .debug ('objectFileCallback: %s' , objfile )
312
318
self .objectFiles .append (objfile )
313
319
314
320
def preprocessOnlyCallback (self , flag ):
321
+ _logger .debug ('preprocessOnlyCallback: %s' , flag )
315
322
self .isPreprocessOnly = True
316
323
317
324
def dependencyOnlyCallback (self , flag ):
325
+ _logger .debug ('dependencyOnlyCallback: %s' , flag )
318
326
self .isDependencyOnly = True
319
327
self .compileArgs .append (flag )
320
328
321
329
def assembleOnlyCallback (self , flag ):
330
+ _logger .debug ('assembleOnlyCallback: %s' , flag )
322
331
self .isAssembleOnly = True
323
332
324
333
def verboseFlagCallback (self , flag ):
334
+ _logger .debug ('verboseFlagCallback: %s' , flag )
325
335
self .isVerbose = True
326
336
327
337
def compileOnlyCallback (self , flag ):
338
+ _logger .debug ('compileOnlyCallback: %s' , flag )
328
339
self .isCompileOnly = True
329
340
330
341
def linkUnaryCallback (self , flag ):
342
+ _logger .debug ('linkUnaryCallback: %s' , flag )
331
343
self .linkArgs .append (flag )
332
344
333
345
def compileUnaryCallback (self , flag ):
346
+ _logger .debug ('compileUnaryCallback: %s' , flag )
334
347
self .compileArgs .append (flag )
335
348
336
349
def darwinWarningLinkUnaryCallback (self , flag ):
350
+ _logger .debug ('darwinWarningLinkUnaryCallback: %s' , flag )
337
351
if sys .platform .startswith ('darwin' ):
338
- _logger .warning ('The flag "{0} " cannot be used with this tool' . format ( flag ) )
352
+ _logger .warning ('The flag "%s " cannot be used with this tool' , flag )
339
353
sys .exit (1 )
340
354
else :
341
355
self .linkArgs .append (flag )
342
356
343
357
def defaultBinaryCallback (self , flag , arg ):
344
- _logger .warning ('Ignoring compiler arg pair: "{0} {1}"' . format ( flag , arg ) )
358
+ _logger .warning ('Ignoring compiler arg pair: "%s %s"' , flag , arg )
345
359
346
360
def dependencyBinaryCallback (self , flag , arg ):
361
+ _logger .debug ('dependencyBinaryCallback: %s %s' , flag , arg )
347
362
self .isDependencyOnly = True
348
363
self .compileArgs .append (flag )
349
364
self .compileArgs .append (arg )
350
365
351
366
def compileBinaryCallback (self , flag , arg ):
367
+ _logger .debug ('compileBinaryCallback: %s %s' , flag , arg )
352
368
self .compileArgs .append (flag )
353
369
self .compileArgs .append (arg )
354
370
355
371
356
372
def linkBinaryCallback (self , flag , arg ):
373
+ _logger .debug ('linkBinaryCallback: %s %s' , flag , arg )
357
374
self .linkArgs .append (flag )
358
375
self .linkArgs .append (arg )
359
376
360
377
#flags common to both linking and compiling (coverage for example)
361
378
def compileLinkUnaryCallback (self , flag ):
379
+ _logger .debug ('compileLinkUnaryCallback: %s' , flag )
362
380
self .compileArgs .append (flag )
363
381
self .linkArgs .append (flag )
364
382
@@ -367,8 +385,8 @@ def getOutputFilename(self):
367
385
return self .outputFilename
368
386
elif self .isCompileOnly :
369
387
#iam: -c but no -o, therefore the obj should end up in the cwd.
370
- (path , base ) = os .path .split (self .inputFiles [0 ])
371
- (root , ext ) = os .path .splitext (base )
388
+ (_ , base ) = os .path .split (self .inputFiles [0 ])
389
+ (root , _ ) = os .path .splitext (base )
372
390
return '{0}.o' .format (root )
373
391
else :
374
392
return 'a.out'
@@ -378,8 +396,8 @@ def getOutputFilename(self):
378
396
# bitcodeFile is (starts with a '.'), use the logging level & DUMPING flag to get a sense
379
397
# of what is being written out.
380
398
def getArtifactNames (self , srcFile , hidden = False ):
381
- (srcpath , srcbase ) = os .path .split (srcFile )
382
- (srcroot , srcext ) = os .path .splitext (srcbase )
399
+ (_ , srcbase ) = os .path .split (srcFile )
400
+ (srcroot , _ ) = os .path .splitext (srcbase )
383
401
if hidden :
384
402
objbase = '.{0}.o' .format (srcroot )
385
403
else :
@@ -392,15 +410,11 @@ def getArtifactNames(self, srcFile, hidden=False):
392
410
393
411
#iam: for printing our partitioning of the args
394
412
def dump (self ):
395
- _logger .debug ('compileArgs: {0}' .format (self .compileArgs ))
396
- _logger .debug ('inputFiles: {0}' .format (self .inputFiles ))
397
- _logger .debug ('linkArgs: {0}' .format (self .linkArgs ))
398
- _logger .debug ('objectFiles: {0}' .format (self .objectFiles ))
399
- _logger .debug ('outputFilename: {0}' .format (self .outputFilename ))
413
+ _logger .debug ('compileArgs: %s\n inputFiles: %s\n linkArgs: %s' ,
414
+ self .compileArgs , self .inputFiles , self .linkArgs )
415
+ _logger .debug ('objectFiles: %s\n outputFilename: %s' ,
416
+ self .objectFiles , self .outputFilename )
400
417
for srcFile in self .inputFiles :
401
- _logger .debug ('srcFile: {0}' . format ( srcFile ) )
418
+ _logger .debug ('srcFile: %s' , srcFile )
402
419
(objFile , bcFile ) = self .getArtifactNames (srcFile )
403
- _logger .debug ('{0} ===> ({1}, {2})' .format (srcFile , objFile , bcFile ))
404
-
405
-
406
-
420
+ _logger .debug ('%s ===> (%s, %s)' , srcFile , objFile , bcFile )
0 commit comments