Skip to content

Commit 64e07e5

Browse files
committed
- fixed SCons build on Windows: only build static library (support static/dynamic at the same time requires significant changes)
- renamed SCons glob tool to globtool to avoid clash with python glob module. This prevented running the tests. - check target now works with SCons 1.x
1 parent 617270b commit 64e07e5

6 files changed

Lines changed: 56 additions & 30 deletions

File tree

SConstruct

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,29 @@ elif platform == 'msvc6':
137137
for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
138138
env.Tool( tool )
139139
env['CXXFLAGS']='-GR -GX /nologo /MT'
140+
env['SHARED_LIB_ENABLED'] = False
140141
elif platform == 'msvc70':
141142
env['MSVS_VERSION']='7.0'
142143
for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
143144
env.Tool( tool )
144145
env['CXXFLAGS']='-GR -GX /nologo /MT'
146+
env['SHARED_LIB_ENABLED'] = False
145147
elif platform == 'msvc71':
146148
env['MSVS_VERSION']='7.1'
147149
for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
148150
env.Tool( tool )
149151
env['CXXFLAGS']='-GR -GX /nologo /MT'
152+
env['SHARED_LIB_ENABLED'] = False
150153
elif platform == 'msvc80':
151154
env['MSVS_VERSION']='8.0'
152155
for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
153156
env.Tool( tool )
154157
env['CXXFLAGS']='-GR -EHsc /nologo /MT'
158+
env['SHARED_LIB_ENABLED'] = False
155159
elif platform == 'mingw':
156160
env.Tool( 'mingw' )
157161
env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] )
162+
env['SHARED_LIB_ENABLED'] = False
158163
elif platform.startswith('linux-gcc'):
159164
env.Tool( 'default' )
160165
env.Append( LIBS = ['pthread'], CCFLAGS = "-Wall" )
@@ -166,13 +171,16 @@ env.Tool('doxygen')
166171
env.Tool('substinfile')
167172
env.Tool('targz')
168173
env.Tool('srcdist')
169-
env.Tool('glob')
174+
env.Tool('globtool')
170175

171176
env.Append( CPPPATH = ['#include'],
172177
LIBPATH = lib_dir )
173178
short_platform = platform
174179
if short_platform.startswith('msvc'):
175180
short_platform = short_platform[2:]
181+
# Notes: on Windows you need to rebuild the source for each variant
182+
# Build script does not support that yet so we only build static libraries.
183+
env['SHARED_LIB_ENABLED'] = env.get('SHARED_LIB_ENABLED', True)
176184
env['LIB_PLATFORM'] = short_platform
177185
env['LIB_LINK_TYPE'] = 'lib' # static
178186
env['LIB_CRUNTIME'] = 'mt'
@@ -210,11 +218,12 @@ def buildJSONTests( env, target_sources, target_name ):
210218
def buildLibrary( env, target_sources, target_name ):
211219
static_lib = env.StaticLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
212220
source=target_sources )
213-
shared_lib = env.SharedLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
214-
source=target_sources )
215221
global lib_dir
216222
env.Install( lib_dir, static_lib )
217-
env.Install( lib_dir, shared_lib )
223+
if env['SHARED_LIB_ENABLED']:
224+
shared_lib = env.SharedLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
225+
source=target_sources )
226+
env.Install( lib_dir, shared_lib )
218227
env['SRCDIST_ADD']( source=[target_sources] )
219228

220229
Export( 'env env_testing buildJSONExample buildLibrary buildJSONTests' )
@@ -232,10 +241,10 @@ def runJSONTests_action( target, source = None, env = None ):
232241
jsontest_path = Dir( '#test' ).abspath
233242
sys.path.insert( 0, jsontest_path )
234243
import runjsontests
235-
return runjsontests.runAllTests( os.path.abspath(source), jsontest_path )
244+
return runjsontests.runAllTests( os.path.abspath(source[0].path), jsontest_path )
236245

237246
def runJSONTests_string( target, source = None, env = None ):
238-
return 'RunJSONTests("%s")' % source
247+
return 'RunJSONTests("%s")' % source[0]
239248

240249
import SCons.Action
241250
ActionFactory = SCons.Action.ActionFactory

scons-tools/doxygen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import os
1111
import os.path
12-
import glob
1312
from fnmatch import fnmatch
1413
import SCons
1514

scons-tools/srcdist.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import os.path
3-
import glob
43
from fnmatch import fnmatch
54
import targz
65

test/jsontestrunner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ def valueTreeToString( fout, value, path = '.' ):
4444
assert False and "Unexpected value type"
4545

4646
def parseAndSaveValueTree( input, actual_path ):
47-
root = json.read( input )
47+
root = json.loads( input )
4848
fout = file( actual_path, 'wt' )
4949
valueTreeToString( fout, root )
5050
fout.close()
5151
return root
5252

5353
def rewriteValueTree( value, rewrite_path ):
54-
rewrite = json.write( value )
55-
rewrite = rewrite[1:-1] # Somehow the string is quoted ! jsonpy bug ?
54+
rewrite = json.dumps( value )
55+
#rewrite = rewrite[1:-1] # Somehow the string is quoted ! jsonpy bug ?
5656
file( rewrite_path, 'wt').write( rewrite + '\n' )
5757
return rewrite
5858

test/runjsontests.py

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
import os
33
import os.path
4-
import glob
4+
from glob import glob
55

66

77
def compareOutputs( expected, actual, message ):
@@ -38,30 +38,49 @@ def safeReadFile( path ):
3838
def runAllTests( jsontest_executable_path, input_dir = None ):
3939
if not input_dir:
4040
input_dir = os.getcwd()
41-
tests = glob.glob( os.path.join( input_dir, '*.json' ) )
41+
tests = glob( os.path.join( input_dir, '*.json' ) )
42+
test_jsonchecker = glob( os.path.join( input_dir, 'jsonchecker', '*.json' ) )
4243
failed_tests = []
43-
for input_path in tests:
44+
for input_path in tests + test_jsonchecker:
45+
is_json_checker_test = input_path in test_jsonchecker
4446
print 'TESTING:', input_path,
45-
pipe = os.popen( "%s %s" % (jsontest_executable_path, input_path) )
47+
options = is_json_checker_test and '--json-checker' or ''
48+
pipe = os.popen( "%s %s %s" % (jsontest_executable_path, options,
49+
input_path) )
4650
process_output = pipe.read()
4751
status = pipe.close()
48-
base_path = os.path.splitext(input_path)[0]
49-
actual_output = safeReadFile( base_path + '.actual' )
50-
actual_rewrite_output = safeReadFile( base_path + '.actual-rewrite' )
51-
file(base_path + '.process-output','wt').write( process_output )
52-
if status:
53-
print 'parsing failed'
54-
failed_tests.append( (input_path, 'Parsing failed:\n' + process_output) )
52+
if is_json_checker_test:
53+
expect_failure = os.path.basename( input_path ).startswith( 'fail' )
54+
if expect_failure:
55+
if status is None:
56+
print 'FAILED'
57+
failed_tests.append( (input_path, 'Parsing should have failed') )
58+
else:
59+
print 'OK'
60+
else:
61+
if status is not None:
62+
print 'FAILED'
63+
failed_tests.append( (input_path, 'Parsing failed:\n' + process_output) )
64+
else:
65+
print 'OK'
5566
else:
56-
expected_output_path = os.path.splitext(input_path)[0] + '.expected'
57-
expected_output = file( expected_output_path, 'rt' ).read()
58-
detail = ( compareOutputs( expected_output, actual_output, 'input' )
59-
or compareOutputs( expected_output, actual_rewrite_output, 'rewrite' ) )
60-
if detail:
61-
print 'FAILED'
62-
failed_tests.append( (input_path, detail) )
67+
base_path = os.path.splitext(input_path)[0]
68+
actual_output = safeReadFile( base_path + '.actual' )
69+
actual_rewrite_output = safeReadFile( base_path + '.actual-rewrite' )
70+
file(base_path + '.process-output','wt').write( process_output )
71+
if status:
72+
print 'parsing failed'
73+
failed_tests.append( (input_path, 'Parsing failed:\n' + process_output) )
6374
else:
64-
print 'OK'
75+
expected_output_path = os.path.splitext(input_path)[0] + '.expected'
76+
expected_output = file( expected_output_path, 'rt' ).read()
77+
detail = ( compareOutputs( expected_output, actual_output, 'input' )
78+
or compareOutputs( expected_output, actual_rewrite_output, 'rewrite' ) )
79+
if detail:
80+
print 'FAILED'
81+
failed_tests.append( (input_path, detail) )
82+
else:
83+
print 'OK'
6584

6685
if failed_tests:
6786
print

0 commit comments

Comments
 (0)