@@ -248,10 +248,9 @@ def extract_from_thin_archive(inputFile):
248
248
arOutput = arProc .communicate ()[0 ]
249
249
if arProc .returncode != 0 :
250
250
_logger .error ('ar failed on %s' , inputFile )
251
- sys .exit (- 1 )
252
-
253
- lines = arOutput .splitlines ()
254
- return lines
251
+ else :
252
+ retval = arOutput .splitlines ()
253
+ return retval
255
254
256
255
257
256
@@ -280,17 +279,17 @@ def handleThinArchive(pArgs):
280
279
281
280
bcFiles = []
282
281
for p in objectPaths :
283
- _logger .info ('handleThinArchive: processing {0}' . format ( p ) )
282
+ _logger .info ('handleThinArchive: processing %s' , p )
284
283
contents = pArgs .extractor (p )
285
284
for c in contents :
286
- if len ( c ) > 0 :
287
- _logger .info ('\t including {0}' . format ( c ) )
285
+ if c :
286
+ _logger .info ('\t including %s' , c )
288
287
bcFiles .append (str (c ))
289
288
290
289
return buildArchive (pArgs , bcFiles )
291
290
292
291
#iam: do we want to preserve the order in the archive? if so we need to return both the list and the dict.
293
- def fetchTOC (pArgs , inputFile ):
292
+ def fetchTOC (inputFile ):
294
293
toc = {}
295
294
296
295
arCmd = ['ar' , '-t' , inputFile ] #iam: check if this might be os dependent
@@ -333,11 +332,11 @@ def handleArchive(pArgs):
333
332
334
333
originalDir = os .getcwd () # We want to end up back where we started.
335
334
336
- toc = fetchTOC (pArgs , inputFile )
335
+ toc = fetchTOC (inputFile )
337
336
338
337
if not toc :
339
338
_logger .warning ('No files found, so nothing to be done.' )
340
- return
339
+ return 0
341
340
342
341
bitCodeFiles = []
343
342
@@ -353,31 +352,31 @@ def handleArchive(pArgs):
353
352
arP = Popen (arCmd )
354
353
except Exception as e :
355
354
_logger .error (e )
356
- return
355
+ return 1
357
356
358
357
arPE = arP .wait ()
359
358
360
359
if arPE != 0 :
361
360
errorMsg = 'Failed to execute archiver with command {0}' .format (arCmd )
362
361
_logger .error (errorMsg )
363
- return
362
+ return 1
364
363
365
364
# Extract bitcode locations from object
366
365
contents = pArgs .extractor (filename )
367
- _logger .debug ('From instance {0} of {1} in {2} we extracted\n \t {3} \n ' . format ( i , filename , inputFile , contents ) )
366
+ _logger .debug ('From instance %s of %s in %s we extracted\n \t %s \n ' , i , filename , inputFile , contents )
368
367
if contents :
369
368
for path in contents :
370
369
if path :
371
370
bitCodeFiles .append (path )
372
371
else :
373
- _logger .debug ('From instance {0} of {1} in {2} we extracted NOTHING\n ' . format ( i , filename , inputFile ) )
372
+ _logger .debug ('From instance %s of %s in %s we extracted NOTHING\n ' , i , filename , inputFile )
374
373
375
374
finally :
376
375
# Delete the temporary folder
377
376
_logger .debug ('Deleting temporary folder "%s"' , tempDir )
378
377
shutil .rmtree (tempDir )
379
378
380
- _logger .debug ('From instance {0} we extracted\n \t {1} \n ' . format ( inputFile , bitCodeFiles ) )
379
+ _logger .debug ('From instance %s we extracted\n \t %s \n ' , inputFile , bitCodeFiles )
381
380
382
381
# Build bitcode archive
383
382
os .chdir (originalDir )
@@ -599,7 +598,7 @@ def extract_bc_args():
599
598
600
599
601
600
def process_file_unix (pArgs ):
602
-
601
+ retval = 1
603
602
ft = FileType .getFileType (pArgs .inputFile )
604
603
_logger .debug ('Detected file type is %s' , FileType .revMap [ft ])
605
604
@@ -609,19 +608,19 @@ def process_file_unix(pArgs):
609
608
610
609
if ft == FileType .ELF_EXECUTABLE or ft == FileType .ELF_SHARED or ft == FileType .ELF_OBJECT :
611
610
_logger .info ('Generating LLVM Bitcode module' )
612
- return handleExecutable (pArgs )
611
+ retval = handleExecutable (pArgs )
613
612
elif ft == FileType .ARCHIVE :
614
- return handleArchive (pArgs )
613
+ retval = handleArchive (pArgs )
615
614
elif ft == FileType .THIN_ARCHIVE :
616
- return handleThinArchive (pArgs )
615
+ retval = handleThinArchive (pArgs )
617
616
else :
618
617
_logger .error ('File "%s" of type %s cannot be used' , pArgs .inputFile , FileType .revMap [ft ])
619
- return 1
618
+ return retval
620
619
621
620
622
621
623
622
def process_file_darwin (pArgs ):
624
-
623
+ retval = 1
625
624
ft = FileType .getFileType (pArgs .inputFile )
626
625
_logger .debug ('Detected file type is %s' , FileType .revMap [ft ])
627
626
@@ -631,9 +630,9 @@ def process_file_darwin(pArgs):
631
630
632
631
if ft == FileType .MACH_EXECUTABLE or ft == FileType .MACH_SHARED or ft == FileType .MACH_OBJECT :
633
632
_logger .info ('Generating LLVM Bitcode module' )
634
- return handleExecutable (pArgs )
633
+ retval = handleExecutable (pArgs )
635
634
elif ft == FileType .ARCHIVE :
636
- return handleArchive (pArgs )
635
+ retval = handleArchive (pArgs )
637
636
else :
638
637
_logger .error ('File "%s" of type %s cannot be used' , pArgs .inputFile , FileType .revMap [ft ])
639
- return 1
638
+ return retval
0 commit comments