3636from tools .shared import EMCC , EMXX , DEBUG , EMCONFIGURE , EMCMAKE
3737from tools .shared import get_canonical_temp_dir , path_from_root
3838from tools .utils import MACOS , WINDOWS , read_file , read_binary , write_binary , exit_with_error
39+ from tools .settings import COMPILE_TIME_SETTINGS
3940from tools import shared , line_endings , building , config , utils
4041
4142logger = logging .getLogger ('common' )
@@ -771,7 +772,7 @@ def require_jspi(self):
771772 # emcc warns about stack switching being experimental, and we build with
772773 # warnings-as-errors, so disable that warning
773774 self .emcc_args += ['-Wno-experimental' ]
774- self .emcc_args += [ '-sASYNCIFY=2' ]
775+ self .set_setting ( 'ASYNCIFY' , 2 )
775776 if not self .is_wasm ():
776777 self .skipTest ('JSPI is not currently supported for WASM2JS' )
777778
@@ -959,9 +960,11 @@ def has_changed_setting(self, key):
959960 def clear_setting (self , key ):
960961 self .settings_mods .pop (key , None )
961962
962- def serialize_settings (self ):
963+ def serialize_settings (self , compile_only = False ):
963964 ret = []
964965 for key , value in self .settings_mods .items ():
966+ if compile_only and key not in COMPILE_TIME_SETTINGS :
967+ continue
965968 if value == 1 :
966969 ret .append (f'-s{ key } ' )
967970 elif type (value ) is list :
@@ -995,15 +998,15 @@ def add_on_exit(self, code):
995998 # param @main_file whether this is the main file of the test. some arguments
996999 # (like --pre-js) do not need to be passed when building
9971000 # 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 ):
9991002 def is_ldflag (f ):
10001003 return any (f .startswith (s ) for s in ['-sENVIRONMENT=' , '--pre-js=' , '--post-js=' ])
10011004
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 :
10061007 args = [a for a in args if not is_ldflag (a )]
1008+ else :
1009+ args += self .ldflags
10071010 if not main_file :
10081011 for i , arg in enumerate (args ):
10091012 if arg in ('--pre-js' , '--post-js' ):
@@ -1354,12 +1357,12 @@ def get_library(self, name, generated_libs, configure=['sh', './configure'], #
13541357 build_dir = self .get_build_dir ()
13551358 output_dir = self .get_dir ()
13561359
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).
13601360 emcc_args = []
13611361 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 )
13631366
13641367 hash_input = (str (emcc_args ) + ' $ ' + str (env_init )).encode ('utf-8' )
13651368 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):
14081411 self .fail (f'subprocess exited with non-zero return code({ e .returncode } ): `{ shared .shlex_join (cmd )} `' )
14091412
14101413 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
14121415 if output_filename :
14131416 cmd += ['-o' , output_filename ]
14141417 self .run_process (cmd , ** kwargs )
@@ -1662,10 +1665,6 @@ def get_freetype_library(self):
16621665 def get_poppler_library (self , env_init = None ):
16631666 freetype = self .get_freetype_library ()
16641667
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-
16691668 self .emcc_args += [
16701669 '-I' + test_file ('third_party/freetype/include' ),
16711670 '-I' + test_file ('third_party/poppler/include' )
@@ -1681,6 +1680,9 @@ def get_poppler_library(self, env_init=None):
16811680 '-Wno-unknown-pragmas' ,
16821681 '-Wno-shift-negative-value' ,
16831682 '-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' ,
16841686 # Avoid warning about ERROR_ON_UNDEFINED_SYMBOLS being used at compile time
16851687 '-Wno-unused-command-line-argument' ,
16861688 '-Wno-js-compiler' ,
@@ -2111,24 +2113,26 @@ def reftest(self, expected, manually_trigger=False):
21112113 setupRefTest();
21122114''' % (reporting , basename , int (manually_trigger )))
21132115
2114- def compile_btest (self , args , reporting = Reporting .FULL ):
2116+ def compile_btest (self , filename , args , reporting = Reporting .FULL ):
21152117 # Inject support code for reporting results. This adds an include a header so testcases can
21162118 # use REPORT_RESULT, and also adds a cpp file to be compiled alongside the testcase, which
21172119 # contains the implementation of REPORT_RESULT (we can't just include that implementation in
21182120 # the header as there may be multiple files being compiled here).
21192121 if reporting != Reporting .NONE :
21202122 # 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' )]
21232124 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' )]
21292131 if EMTEST_BROWSER == 'node' :
21302132 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 )
21322136
21332137 def btest_exit (self , filename , assert_returncode = 0 , * args , ** kwargs ):
21342138 """Special case of btest that reports its result solely via exiting
@@ -2171,10 +2175,10 @@ def btest(self, filename, expected=None, reference=None,
21712175 # manual_reference only makes sense for reference tests
21722176 assert manual_reference is None
21732177 outfile = output_basename + '.html'
2174- args += [filename , '-o' , outfile ]
2178+ args += ['-o' , outfile ]
21752179 # print('all args:', args)
21762180 utils .delete_file (outfile )
2177- self .compile_btest (args , reporting = reporting )
2181+ self .compile_btest (filename , args , reporting = reporting )
21782182 self .assertExists (outfile )
21792183 if post_build :
21802184 post_build ()
0 commit comments