36
36
from tools .shared import EMCC , EMXX , DEBUG , EMCONFIGURE , EMCMAKE
37
37
from tools .shared import get_canonical_temp_dir , path_from_root
38
38
from tools .utils import MACOS , WINDOWS , read_file , read_binary , write_binary , exit_with_error
39
+ from tools .settings import COMPILE_TIME_SETTINGS
39
40
from tools import shared , line_endings , building , config , utils
40
41
41
42
logger = logging .getLogger ('common' )
@@ -771,7 +772,7 @@ def require_jspi(self):
771
772
# emcc warns about stack switching being experimental, and we build with
772
773
# warnings-as-errors, so disable that warning
773
774
self .emcc_args += ['-Wno-experimental' ]
774
- self .emcc_args += [ '-sASYNCIFY=2' ]
775
+ self .set_setting ( 'ASYNCIFY' , 2 )
775
776
if not self .is_wasm ():
776
777
self .skipTest ('JSPI is not currently supported for WASM2JS' )
777
778
@@ -959,9 +960,11 @@ def has_changed_setting(self, key):
959
960
def clear_setting (self , key ):
960
961
self .settings_mods .pop (key , None )
961
962
962
- def serialize_settings (self ):
963
+ def serialize_settings (self , compile_only = False ):
963
964
ret = []
964
965
for key , value in self .settings_mods .items ():
966
+ if compile_only and key not in COMPILE_TIME_SETTINGS :
967
+ continue
965
968
if value == 1 :
966
969
ret .append (f'-s{ key } ' )
967
970
elif type (value ) is list :
@@ -995,15 +998,15 @@ def add_on_exit(self, code):
995
998
# param @main_file whether this is the main file of the test. some arguments
996
999
# (like --pre-js) do not need to be passed when building
997
1000
# libraries, for example
998
- def get_emcc_args (self , main_file = False , ldflags = True ):
1001
+ def get_emcc_args (self , main_file = False , compile_only = False ):
999
1002
def is_ldflag (f ):
1000
1003
return any (f .startswith (s ) for s in ['-sENVIRONMENT=' , '--pre-js=' , '--post-js=' ])
1001
1004
1002
- args = self .serialize_settings () + self .emcc_args
1003
- if ldflags :
1004
- args += self .ldflags
1005
- else :
1005
+ args = self .serialize_settings (compile_only ) + self .emcc_args
1006
+ if compile_only :
1006
1007
args = [a for a in args if not is_ldflag (a )]
1008
+ else :
1009
+ args += self .ldflags
1007
1010
if not main_file :
1008
1011
for i , arg in enumerate (args ):
1009
1012
if arg in ('--pre-js' , '--post-js' ):
@@ -1354,12 +1357,12 @@ def get_library(self, name, generated_libs, configure=['sh', './configure'], #
1354
1357
build_dir = self .get_build_dir ()
1355
1358
output_dir = self .get_dir ()
1356
1359
1357
- # get_library() is used to compile libraries, and not link executables,
1358
- # so we don't want to pass linker flags here (emscripten warns if you
1359
- # try to pass linker settings when compiling).
1360
1360
emcc_args = []
1361
1361
if not native :
1362
- emcc_args = self .get_emcc_args (ldflags = False )
1362
+ # get_library() is used to compile libraries, and not link executables,
1363
+ # so we don't want to pass linker flags here (emscripten warns if you
1364
+ # try to pass linker settings when compiling).
1365
+ emcc_args = self .get_emcc_args (compile_only = True )
1363
1366
1364
1367
hash_input = (str (emcc_args ) + ' $ ' + str (env_init )).encode ('utf-8' )
1365
1368
cache_name = name + ',' .join ([opt for opt in emcc_args if len (opt ) < 7 ]) + '_' + hashlib .md5 (hash_input ).hexdigest () + cache_name_extra
@@ -1408,7 +1411,7 @@ def run_process(self, cmd, check=True, **args):
1408
1411
self .fail (f'subprocess exited with non-zero return code({ e .returncode } ): `{ shared .shlex_join (cmd )} `' )
1409
1412
1410
1413
def emcc (self , filename , args = [], output_filename = None , ** kwargs ): # noqa
1411
- cmd = [compiler_for (filename ), filename ] + self .get_emcc_args (ldflags = '-c' not in args ) + args
1414
+ cmd = [compiler_for (filename ), filename ] + self .get_emcc_args (compile_only = '-c' in args ) + args
1412
1415
if output_filename :
1413
1416
cmd += ['-o' , output_filename ]
1414
1417
self .run_process (cmd , ** kwargs )
@@ -1662,10 +1665,6 @@ def get_freetype_library(self):
1662
1665
def get_poppler_library (self , env_init = None ):
1663
1666
freetype = self .get_freetype_library ()
1664
1667
1665
- # The fontconfig symbols are all missing from the poppler build
1666
- # e.g. FcConfigSubstitute
1667
- self .set_setting ('ERROR_ON_UNDEFINED_SYMBOLS' , 0 )
1668
-
1669
1668
self .emcc_args += [
1670
1669
'-I' + test_file ('third_party/freetype/include' ),
1671
1670
'-I' + test_file ('third_party/poppler/include' )
@@ -1681,6 +1680,9 @@ def get_poppler_library(self, env_init=None):
1681
1680
'-Wno-unknown-pragmas' ,
1682
1681
'-Wno-shift-negative-value' ,
1683
1682
'-Wno-dynamic-class-memaccess' ,
1683
+ # The fontconfig symbols are all missing from the poppler build
1684
+ # e.g. FcConfigSubstitute
1685
+ '-sERROR_ON_UNDEFINED_SYMBOLS=0' ,
1684
1686
# Avoid warning about ERROR_ON_UNDEFINED_SYMBOLS being used at compile time
1685
1687
'-Wno-unused-command-line-argument' ,
1686
1688
'-Wno-js-compiler' ,
@@ -2111,24 +2113,26 @@ def reftest(self, expected, manually_trigger=False):
2111
2113
setupRefTest();
2112
2114
''' % (reporting , basename , int (manually_trigger )))
2113
2115
2114
- def compile_btest (self , args , reporting = Reporting .FULL ):
2116
+ def compile_btest (self , filename , args , reporting = Reporting .FULL ):
2115
2117
# Inject support code for reporting results. This adds an include a header so testcases can
2116
2118
# use REPORT_RESULT, and also adds a cpp file to be compiled alongside the testcase, which
2117
2119
# contains the implementation of REPORT_RESULT (we can't just include that implementation in
2118
2120
# the header as there may be multiple files being compiled here).
2119
2121
if reporting != Reporting .NONE :
2120
2122
# For basic reporting we inject JS helper funtions to report result back to server.
2121
- args += ['-DEMTEST_PORT_NUMBER=%d' % self .port ,
2122
- '--pre-js' , test_file ('browser_reporting.js' )]
2123
+ args += ['--pre-js' , test_file ('browser_reporting.js' )]
2123
2124
if reporting == Reporting .FULL :
2124
- # If C reporting (i.e. REPORT_RESULT macro) is required
2125
- # also compile in report_result.c and forice-include report_result.h
2126
- args += ['-I' + TEST_ROOT ,
2127
- '-include' , test_file ('report_result.h' ),
2128
- test_file ('report_result.c' )]
2125
+ # If C reporting (i.e. the REPORT_RESULT macro) is required we
2126
+ # also include report_result.c and force-include report_result.h
2127
+ self .run_process ([EMCC , '-c' , '-I' + TEST_ROOT ,
2128
+ '-DEMTEST_PORT_NUMBER=%d' % self .port ,
2129
+ test_file ('report_result.c' )] + self .get_emcc_args (compile_only = True ))
2130
+ args += ['report_result.o' , '-include' , test_file ('report_result.h' )]
2129
2131
if EMTEST_BROWSER == 'node' :
2130
2132
args .append ('-DEMTEST_NODE' )
2131
- self .run_process ([EMCC ] + self .get_emcc_args () + args )
2133
+ if not os .path .exists (filename ):
2134
+ filename = test_file (filename )
2135
+ self .run_process ([compiler_for (filename ), filename ] + self .get_emcc_args () + args )
2132
2136
2133
2137
def btest_exit (self , filename , assert_returncode = 0 , * args , ** kwargs ):
2134
2138
"""Special case of btest that reports its result solely via exiting
@@ -2171,10 +2175,10 @@ def btest(self, filename, expected=None, reference=None,
2171
2175
# manual_reference only makes sense for reference tests
2172
2176
assert manual_reference is None
2173
2177
outfile = output_basename + '.html'
2174
- args += [filename , '-o' , outfile ]
2178
+ args += ['-o' , outfile ]
2175
2179
# print('all args:', args)
2176
2180
utils .delete_file (outfile )
2177
- self .compile_btest (args , reporting = reporting )
2181
+ self .compile_btest (filename , args , reporting = reporting )
2178
2182
self .assertExists (outfile )
2179
2183
if post_build :
2180
2184
post_build ()
0 commit comments