#NEWLINE# def attachBitcodePathToObject( bcPath , outFileName ) : #NEWLINE# #INDENT# ( root , ext ) = os . path . splitext ( outFileName ) #NEWLINE# _logger . debug ( 'attachBitcodePathToObject: {0}  ===> {1} [ext = {2}]\n' . format ( bcPath , outFileName , ext ) ) #NEWLINE# if ( ext not in ( '.o' , '.lo' , '.os' , '.So' , '.po' ) ) : #NEWLINE# #INDENT# _logger . warning ( 'Cannot attach bitcode path to "{0} of type {1}"' . format ( outFileName , FileType . getFileType ( outFileName ) ) ) #NEWLINE# return #NEWLINE# #UNINDENT# f = tempfile . NamedTemporaryFile ( mode = 'w+b' , delete = False ) #NEWLINE# absBcPath = os . path . abspath ( bcPath ) #NEWLINE# f . write ( absBcPath . encode ( ) ) #NEWLINE# f . write ( '\n' . encode ( ) ) #NEWLINE# _logger . debug ( pprint . pformat ( 'Wrote "{0}" to file "{1}"' . format ( absBcPath , f . name ) ) ) #NEWLINE# f . flush ( ) #NEWLINE# os . fsync ( f . fileno ( ) ) #NEWLINE# f . close ( ) #NEWLINE# if sys . platform . startswith ( 'darwin' ) : #NEWLINE# #INDENT# objcopyCmd = [ 'ld' , '-r' , '-keep_private_externs' , outFileName , '-sectcreate' , darwinSegmentName , darwinSectionName , f . name , '-o' , outFileName ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# objcopyCmd = [ 'objcopy' , '--add-section' , '{0}={1}' . format ( elfSectionName , f . name ) , outFileName ] #NEWLINE# #UNINDENT# orc = 0 #NEWLINE# try : #NEWLINE# #INDENT# if ( os . path . getsize ( outFileName ) > 0 ) : #NEWLINE# #INDENT# objProc = Popen ( objcopyCmd ) #NEWLINE# orc = objProc . wait ( ) #NEWLINE# #UNINDENT# #UNINDENT# except OSError : #NEWLINE# #INDENT# os . remove ( ext . name ) #NEWLINE# sys . exit ( 0 ) #NEWLINE# #UNINDENT# os . remove ( f . name ) #NEWLINE# if ( orc != 0 ) : #NEWLINE# #INDENT# _logger . error ( 'objcopy failed with {0}' . format ( orc ) ) #NEWLINE# sys . exit ( ( - 1 ) )