5
5
import os
6
6
import sys
7
7
import tempfile
8
+ import hashlib
8
9
10
+ from shutil import copyfile
9
11
from .filetype import FileType
10
12
from .popenwrapper import Popen
11
13
from .arglistfilter import ArgumentListFilter
@@ -120,6 +122,13 @@ def attachBitcodePathToObject(bcPath, outFileName):
120
122
_logger .error ('objcopy failed with %s' , orc )
121
123
sys .exit (- 1 )
122
124
125
+ # loicg: If the environment variable WLLVM_BC_STORE is set, copy the bitcode
126
+ # file to that location, using a hash of the original bitcode path as a name
127
+ storeEnv = os .getenv ('WLLVM_BC_STORE' )
128
+ if storeEnv :
129
+ hashName = hashlib .sha256 (absBcPath ).hexdigest ()
130
+ copyfile (absBcPath , os .path .join (storeEnv , hashName ))
131
+
123
132
class BuilderBase (object ):
124
133
def __init__ (self , cmd , isCxx , prefixPath = None ):
125
134
self .cmd = cmd
@@ -140,16 +149,7 @@ def __init__(self, cmd, isCxx, prefixPath=None):
140
149
else :
141
150
self .prefixPath = ''
142
151
143
- #clang and dragonegg share the same taste in bitcode filenames.
144
- def getBitcodeFileName (self , argFilter ):
145
- (dirs , baseFile ) = os .path .split (argFilter .getOutputFilename ())
146
- bcfilename = os .path .join (dirs , '.{0}.bc' .format (baseFile ))
147
- return bcfilename
148
-
149
152
class ClangBuilder (BuilderBase ):
150
- def __init__ (self , cmd , isCxx , prefixPath = None ):
151
- super (ClangBuilder , self ).__init__ (cmd , isCxx , prefixPath )
152
-
153
153
def getBitcodeCompiler (self ):
154
154
cc = self .getCompiler ()
155
155
return cc + ['-emit-llvm' ]
@@ -159,31 +159,16 @@ def getCompiler(self):
159
159
cxx = os .getenv ('LLVM_CXX_NAME' )
160
160
if cxx :
161
161
return ['{0}{1}' .format (self .prefixPath , cxx )]
162
- else :
163
- return ['{0}clang++' .format (self .prefixPath )]
164
- else :
165
- cc = os .getenv ('LLVM_CC_NAME' )
166
- if cc :
167
- return ['{0}{1}' .format (self .prefixPath , cc )]
168
- else :
169
- return ['{0}clang' .format (self .prefixPath )]
162
+ return ['{0}clang++' .format (self .prefixPath )]
163
+ cc = os .getenv ('LLVM_CC_NAME' )
164
+ if cc :
165
+ return ['{0}{1}' .format (self .prefixPath , cc )]
166
+ return ['{0}clang' .format (self .prefixPath )]
170
167
171
168
def getBitcodeArglistFilter (self ):
172
169
return ClangBitcodeArgumentListFilter (self .cmd )
173
170
174
- def extraBitcodeArgs (self , argFilter ):
175
- bcPath = self .getBitcodeFileName (argFilter )
176
- return ['-o' , bcPath ]
177
-
178
- def attachBitcode (self , argFilter ):
179
- bcname = self .getBitcodeFileName (argFilter )
180
- outFile = argFilter .getOutputFilename ()
181
- attachBitcodePathToObject (bcname , outFile )
182
-
183
171
class DragoneggBuilder (BuilderBase ):
184
- def __init__ (self , cmd , isCxx , prefixPath = None ):
185
- super (DragoneggBuilder , self ).__init__ (cmd , isCxx , prefixPath )
186
-
187
172
def getBitcodeCompiler (self ):
188
173
pth = os .getenv ('LLVM_DRAGONEGG_PLUGIN' )
189
174
cc = self .getCompiler ()
@@ -201,21 +186,11 @@ def getCompiler(self):
201
186
202
187
if self .isCxx :
203
188
return ['{0}{1}g++' .format (self .prefixPath , pfx )]
204
- else :
205
- return ['{0}{1}gcc' .format (self .prefixPath , pfx )]
189
+ return ['{0}{1}gcc' .format (self .prefixPath , pfx )]
206
190
207
191
def getBitcodeArglistFilter (self ):
208
192
return ArgumentListFilter (self .cmd )
209
193
210
- # Don't need to do anything since the -B flag in the bitcode
211
- # compiler and the assembly stub handles it
212
- def attachBitcode (self , argFilter ):
213
- pass
214
-
215
- def extraBitcodeArgs (self , _ ):
216
- return []
217
-
218
-
219
194
def getBuilder (cmd , isCxx ):
220
195
compilerEnv = 'LLVM_COMPILER'
221
196
cstring = os .getenv (compilerEnv )
@@ -251,7 +226,7 @@ def buildAndAttachBitcode(builder):
251
226
252
227
af = builder .getBitcodeArglistFilter ()
253
228
254
- if len ( af .inputFiles ) == 0 or af .isEmitLLVM or af .isAssembly or af .isAssembleOnly or (af .isDependencyOnly and not af .isCompileOnly ) or af .isPreprocessOnly :
229
+ if not af .inputFiles or af .isEmitLLVM or af .isAssembly or af .isAssembleOnly or (af .isDependencyOnly and not af .isCompileOnly ) or af .isPreprocessOnly :
255
230
_logger .debug ('No work to do' )
256
231
_logger .debug (af .__dict__ )
257
232
return
@@ -271,9 +246,6 @@ def buildAndAttachBitcode(builder):
271
246
# maybe python-magic is in our future ...
272
247
srcFile = af .inputFiles [0 ]
273
248
(objFile , bcFile ) = af .getArtifactNames (srcFile , hidden )
274
- if af .outputFilename is not None :
275
- objFile = af .outputFilename
276
- bcFile = builder .getBitcodeFileName (af )
277
249
buildBitcodeFile (builder , srcFile , bcFile )
278
250
attachBitcodePathToObject (bcFile , objFile )
279
251
0 commit comments