16
16
# See NOTICE file for details.
17
17
#
18
18
# *****************************************************************************
19
+
19
20
import distutils .cmd
20
21
import distutils .log
21
22
import glob
@@ -43,7 +44,7 @@ class FeatureNotice(Warning):
43
44
""" indicate notices about features """
44
45
45
46
46
- class Makefile ( object ) :
47
+ class Makefile :
47
48
compiler_type = "unix"
48
49
49
50
def __init__ (self , actual ):
@@ -172,13 +173,21 @@ class BuildExtCommand(build_ext):
172
173
"""
173
174
174
175
user_options = build_ext .user_options + [
176
+ ('enable-build-jar' , None , 'Build the java jar portion' ),
177
+ ('enable-tracing' , None , 'Set for tracing for debugging' ),
178
+ ('enable-coverage' , None , 'Instrument c++ code for code coverage measuring' ),
179
+
175
180
('android' , None , 'configure for android' ),
176
181
('makefile' , None , 'Build a makefile for extensions' ),
177
182
('jar' , None , 'Build the jar only' ),
178
183
]
179
184
180
185
def initialize_options (self , * args ):
181
186
"""omit -Wstrict-prototypes from CFLAGS since its only valid for C code."""
187
+ self .enable_tracing = False
188
+ self .enable_build_jar = False
189
+ self .enable_coverage = False
190
+
182
191
self .android = False
183
192
self .makefile = False
184
193
self .jar = False
@@ -195,8 +204,7 @@ def initialize_options(self, *args):
195
204
continue
196
205
197
206
args = v .split ()
198
- for r in remove_args :
199
- args = list (filter (r .__ne__ , args ))
207
+ args = [arg for arg in args if arg not in remove_args ]
200
208
201
209
cfg_vars [k ] = " " .join (args )
202
210
super ().initialize_options ()
@@ -205,12 +213,12 @@ def _set_cflags(self):
205
213
# set compiler flags
206
214
c = self .compiler .compiler_type
207
215
jpypeLib = [i for i in self .extensions if i .name == '_jpype' ][0 ]
208
- if c == 'unix' and self .distribution . enable_coverage :
216
+ if c == 'unix' and self .enable_coverage :
209
217
jpypeLib .extra_compile_args .extend (
210
218
['-ggdb' , '--coverage' , '-ftest-coverage' ])
211
219
jpypeLib .extra_compile_args = ['-O0' if x == '-O2' else x for x in jpypeLib .extra_compile_args ]
212
220
jpypeLib .extra_link_args .extend (['--coverage' ])
213
- if c == 'unix' and self .distribution . enable_tracing :
221
+ if c == 'unix' and self .enable_tracing :
214
222
jpypeLib .extra_compile_args = ['-O0' if x == '-O2' else x for x in jpypeLib .extra_compile_args ]
215
223
216
224
def build_extensions (self ):
@@ -219,16 +227,12 @@ def build_extensions(self):
219
227
self .force = True
220
228
221
229
jpypeLib = [i for i in self .extensions if i .name == '_jpype' ][0 ]
222
- tracing = self .distribution .enable_tracing
223
230
self ._set_cflags ()
224
- if tracing :
231
+ if self . enable_tracing :
225
232
jpypeLib .define_macros .append (('JP_TRACING_ENABLE' , 1 ))
226
- coverage = self .distribution .enable_coverage
227
- if coverage :
233
+ if self .enable_coverage :
228
234
jpypeLib .define_macros .append (('JP_INSTRUMENTATION' , 1 ))
229
235
230
- # has to be last call
231
- print ("Call build extensions" )
232
236
super ().build_extensions ()
233
237
234
238
def build_extension (self , ext ):
@@ -266,7 +270,7 @@ def copy_extensions_to_source(self):
266
270
267
271
def build_java_ext (self , ext ):
268
272
"""Run command."""
269
- java = self .distribution . enable_build_jar
273
+ java = self .enable_build_jar
270
274
271
275
javac = "javac"
272
276
try :
@@ -296,8 +300,6 @@ def build_java_ext(self, ext):
296
300
distutils .log .info (
297
301
"Jar cache is missing, using --enable-build-jar to recreate it." )
298
302
299
- coverage = self .distribution .enable_coverage
300
-
301
303
target_version = "1.8"
302
304
# build the jar
303
305
try :
@@ -309,9 +311,7 @@ def build_java_ext(self, ext):
309
311
cmd1 = shlex .split ('%s -cp "%s" -d "%s" -g:none -source %s -target %s -encoding UTF-8' %
310
312
(javac , classpath , build_dir , target_version , target_version ))
311
313
cmd1 .extend (ext .sources )
312
- debug = "-g:none"
313
- if coverage :
314
- debug = "-g:lines,vars,source"
314
+
315
315
os .makedirs ("build/classes" , exist_ok = True )
316
316
self .announce (" %s" % " " .join (cmd1 ), level = distutils .log .INFO )
317
317
subprocess .check_call (cmd1 )
0 commit comments