@@ -833,6 +833,11 @@ def setUp(self):
833833 self .js_engines = config .JS_ENGINES .copy ()
834834 self .settings_mods = {}
835835 self .emcc_args = ['-Wclosure' , '-Werror' , '-Wno-limited-postlink-optimizations' ]
836+ # TODO(https://github.com/emscripten-core/emscripten/issues/11121)
837+ # For historical reasons emcc compiles and links as C++ by default.
838+ # However we want to run our tests in a more strict manner. We can
839+ # remove this if the issue above is ever fixed.
840+ self .set_setting ('NO_DEFAULT_TO_CXX' )
836841 self .ldflags = []
837842 # Increate stack trace limit to maximise usefulness of test failure reports
838843 self .node_args = ['--stack-trace-limit=50' ]
@@ -954,9 +959,13 @@ def has_changed_setting(self, key):
954959 def clear_setting (self , key ):
955960 self .settings_mods .pop (key , None )
956961
957- def serialize_settings (self ):
962+ def serialize_settings (self , ldflags = True ):
958963 ret = []
964+ # Incomplete list of link-only settings
965+ link_only_settings = ['NO_DEFAULT_TO_CXX' , 'DEFAULT_LIBRARY_FUNCS_TO_INCLUDE' , 'MINIMAL_RUNTIME' ]
959966 for key , value in self .settings_mods .items ():
967+ if not ldflags and key in link_only_settings :
968+ continue
960969 if value == 1 :
961970 ret .append (f'-s{ key } ' )
962971 elif type (value ) is list :
@@ -994,7 +1003,7 @@ def get_emcc_args(self, main_file=False, ldflags=True):
9941003 def is_ldflag (f ):
9951004 return any (f .startswith (s ) for s in ['-sENVIRONMENT=' , '--pre-js=' , '--post-js=' ])
9961005
997- args = self .serialize_settings () + self .emcc_args
1006+ args = self .serialize_settings (ldflags ) + self .emcc_args
9981007 if ldflags :
9991008 args += self .ldflags
10001009 else :
@@ -2106,24 +2115,26 @@ def reftest(self, expected, manually_trigger=False):
21062115 setupRefTest();
21072116''' % (reporting , basename , int (manually_trigger )))
21082117
2109- def compile_btest (self , args , reporting = Reporting .FULL ):
2118+ def compile_btest (self , filename , args , reporting = Reporting .FULL ):
21102119 # Inject support code for reporting results. This adds an include a header so testcases can
21112120 # use REPORT_RESULT, and also adds a cpp file to be compiled alongside the testcase, which
21122121 # contains the implementation of REPORT_RESULT (we can't just include that implementation in
21132122 # the header as there may be multiple files being compiled here).
21142123 if reporting != Reporting .NONE :
21152124 # For basic reporting we inject JS helper funtions to report result back to server.
2116- args += ['-DEMTEST_PORT_NUMBER=%d' % self .port ,
2117- '--pre-js' , test_file ('browser_reporting.js' )]
2125+ args += ['--pre-js' , test_file ('browser_reporting.js' )]
21182126 if reporting == Reporting .FULL :
21192127 # If C reporting (i.e. REPORT_RESULT macro) is required
21202128 # also compile in report_result.c and forice-include report_result.h
2121- args += ['-I' + TEST_ROOT ,
2122- '-include' , test_file ('report_result.h' ),
2123- test_file ('report_result.c' )]
2129+ self .run_process ([EMCC , '-c' , '-I' + TEST_ROOT ,
2130+ '-DEMTEST_PORT_NUMBER=%d' % self .port ,
2131+ test_file ('report_result.c' )] + self .get_emcc_args (ldflags = False ))
2132+ args += ['report_result.o' , '-include' , test_file ('report_result.h' )]
21242133 if EMTEST_BROWSER == 'node' :
21252134 args .append ('-DEMTEST_NODE' )
2126- self .run_process ([EMCC ] + self .get_emcc_args () + args )
2135+ if not os .path .exists (filename ):
2136+ filename = test_file (filename )
2137+ self .run_process ([compiler_for (filename ), filename ] + self .get_emcc_args () + args )
21272138
21282139 def btest_exit (self , filename , assert_returncode = 0 , * args , ** kwargs ):
21292140 """Special case of btest that reports its result solely via exiting
@@ -2166,10 +2177,10 @@ def btest(self, filename, expected=None, reference=None,
21662177 # manual_reference only makes sense for reference tests
21672178 assert manual_reference is None
21682179 outfile = output_basename + '.html'
2169- args += [filename , '-o' , outfile ]
2180+ args += ['-o' , outfile ]
21702181 # print('all args:', args)
21712182 utils .delete_file (outfile )
2172- self .compile_btest (args , reporting = reporting )
2183+ self .compile_btest (filename , args , reporting = reporting )
21732184 self .assertExists (outfile )
21742185 if post_build :
21752186 post_build ()
0 commit comments