@@ -236,6 +236,24 @@ def archiveFiles(pArgs, fileNames):
236
236
237
237
return retCode
238
238
239
+ def extract_from_thin_archive (inputFile ):
240
+ """Extracts the paths from the thin archive.
241
+
242
+ """
243
+ retval = None
244
+
245
+ arCmd = ['ar' , '-t' , inputFile ] #might be os dependent
246
+ arProc = Popen (arCmd , stdout = sp .PIPE )
247
+
248
+ arOutput = arProc .communicate ()[0 ]
249
+ if arProc .returncode != 0 :
250
+ _logger .error ('ar failed on %s' , inputFile )
251
+ sys .exit (- 1 )
252
+
253
+ lines = arOutput .splitlines ()
254
+ return lines
255
+
256
+
239
257
240
258
def handleExecutable (pArgs ):
241
259
@@ -253,10 +271,37 @@ def handleExecutable(pArgs):
253
271
return linkFiles (pArgs , fileNames )
254
272
255
273
274
+ def handleThinArchive (pArgs ):
275
+
276
+ if pArgs .bitcodeModuleFlag :
277
+ _logger .info ('Generating LLVM Bitcode module from an archive' )
278
+ else :
279
+ _logger .info ('Generating LLVM Bitcode archive from an archive' )
280
+
281
+ objectPaths = extract_from_thin_archive (pArgs .inputFile )
282
+
283
+ if not objectPaths :
284
+ return 1
285
+
286
+ bcFiles = []
287
+ for p in objectPaths :
288
+ _logger .info ('handleThinArchive: processing {0}' .format (p ))
289
+ contents = pArgs .extractor (p )
290
+ for c in contents :
291
+ if len (c ) > 0 :
292
+ _logger .info ('\t including {0}' .format (c ))
293
+ bcFiles .append (str (c ))
294
+
295
+ return buildArchive (pArgs , bcFiles )
256
296
257
297
258
298
def handleArchive (pArgs ):
259
299
300
+ if pArgs .bitcodeModuleFlag :
301
+ _logger .info ('Generating LLVM Bitcode module from an archive' )
302
+ else :
303
+ _logger .info ('Generating LLVM Bitcode archive from an archive' )
304
+
260
305
originalDir = os .getcwd () # This will be the destination
261
306
262
307
pArgs .arCmd .append (pArgs .inputFile )
@@ -314,17 +359,17 @@ def handleArchive(pArgs):
314
359
_logger .debug ('Deleting temporary folder "%s"' , tempDir )
315
360
shutil .rmtree (tempDir )
316
361
317
- #write the manifest file if asked for
318
- if pArgs .manifestFlag :
319
- writeManifest ('{0}.llvm.manifest' .format (pArgs .inputFile ), bitCodeFiles )
320
-
321
- # Build bitcode archive
362
+ # Build bitcode archive
322
363
os .chdir (originalDir )
323
364
324
365
return buildArchive (pArgs , bitCodeFiles )
325
366
326
367
def buildArchive (pArgs , bitCodeFiles ):
327
368
369
+ #write the manifest file if asked for
370
+ if pArgs .manifestFlag :
371
+ writeManifest ('{0}.llvm.manifest' .format (pArgs .inputFile ), bitCodeFiles )
372
+
328
373
if pArgs .bitcodeModuleFlag :
329
374
330
375
# Pick output file path if outputFile not set
@@ -355,7 +400,7 @@ def buildArchive(pArgs, bitCodeFiles):
355
400
356
401
def writeManifest (manifestFile , bitCodeFiles ):
357
402
with open (manifestFile , 'w' ) as output :
358
- for f in bitCodeFiles :
403
+ for f in sorted ( bitCodeFiles ) :
359
404
output .write ('{0}\n ' .format (f ))
360
405
sf = getStorePath (f )
361
406
if sf :
@@ -464,11 +509,9 @@ def process_file_unix(pArgs):
464
509
_logger .info ('Generating LLVM Bitcode module' )
465
510
return handleExecutable (pArgs )
466
511
elif ft == FileType .ARCHIVE :
467
- if pArgs .bitcodeModuleFlag :
468
- _logger .info ('Generating LLVM Bitcode module from an archive' )
469
- else :
470
- _logger .info ('Generating LLVM Bitcode archive from an archive' )
471
512
return handleArchive (pArgs )
513
+ elif ft == FileType .THIN_ARCHIVE :
514
+ return handleThinArchive (pArgs )
472
515
else :
473
516
_logger .error ('File "%s" of type %s cannot be used' , pArgs .inputFile , FileType .revMap [ft ])
474
517
return 1
@@ -488,10 +531,6 @@ def process_file_darwin(pArgs):
488
531
_logger .info ('Generating LLVM Bitcode module' )
489
532
return handleExecutable (pArgs )
490
533
elif ft == FileType .ARCHIVE :
491
- if pArgs .bitcodeModuleFlag :
492
- _logger .info ('Generating LLVM Bitcode module from an archive' )
493
- else :
494
- _logger .info ('Generating LLVM Bitcode archive from an archive' )
495
534
return handleArchive (pArgs )
496
535
else :
497
536
_logger .error ('File "%s" of type %s cannot be used' , pArgs .inputFile , FileType .revMap [ft ])
0 commit comments