|
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')
|
@@ -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'):
|
@@ -1359,7 +1362,7 @@ def get_library(self, name, generated_libs, configure=['sh', './configure'], #
|
1359 | 1362 | # try to pass linker settings when compiling).
|
1360 | 1363 | emcc_args = []
|
1361 | 1364 | if not native:
|
1362 |
| - emcc_args = self.get_emcc_args(ldflags=False) |
| 1365 | + emcc_args = self.get_emcc_args(compile_only=False) |
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)
|
@@ -2111,24 +2114,26 @@ def reftest(self, expected, manually_trigger=False):
|
2111 | 2114 | setupRefTest();
|
2112 | 2115 | ''' % (reporting, basename, int(manually_trigger)))
|
2113 | 2116 |
|
2114 |
| - def compile_btest(self, args, reporting=Reporting.FULL): |
| 2117 | + def compile_btest(self, filename, args, reporting=Reporting.FULL): |
2115 | 2118 | # Inject support code for reporting results. This adds an include a header so testcases can
|
2116 | 2119 | # use REPORT_RESULT, and also adds a cpp file to be compiled alongside the testcase, which
|
2117 | 2120 | # contains the implementation of REPORT_RESULT (we can't just include that implementation in
|
2118 | 2121 | # the header as there may be multiple files being compiled here).
|
2119 | 2122 | if reporting != Reporting.NONE:
|
2120 | 2123 | # 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')] |
| 2124 | + args += ['--pre-js', test_file('browser_reporting.js')] |
2123 | 2125 | 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')] |
| 2126 | + # If C reporting (i.e. the REPORT_RESULT macro) is required we |
| 2127 | + # also include report_result.c and force-include report_result.h |
| 2128 | + self.run_process([EMCC, '-c', '-I' + TEST_ROOT, |
| 2129 | + '-DEMTEST_PORT_NUMBER=%d' % self.port, |
| 2130 | + test_file('report_result.c')] + self.get_emcc_args(compile_only=True)) |
| 2131 | + args += ['report_result.o', '-include', test_file('report_result.h')] |
2129 | 2132 | if EMTEST_BROWSER == 'node':
|
2130 | 2133 | args.append('-DEMTEST_NODE')
|
2131 |
| - self.run_process([EMCC] + self.get_emcc_args() + args) |
| 2134 | + if not os.path.exists(filename): |
| 2135 | + filename = test_file(filename) |
| 2136 | + self.run_process([compiler_for(filename), filename] + self.get_emcc_args() + args) |
2132 | 2137 |
|
2133 | 2138 | def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):
|
2134 | 2139 | """Special case of btest that reports its result solely via exiting
|
@@ -2171,10 +2176,10 @@ def btest(self, filename, expected=None, reference=None,
|
2171 | 2176 | # manual_reference only makes sense for reference tests
|
2172 | 2177 | assert manual_reference is None
|
2173 | 2178 | outfile = output_basename + '.html'
|
2174 |
| - args += [filename, '-o', outfile] |
| 2179 | + args += ['-o', outfile] |
2175 | 2180 | # print('all args:', args)
|
2176 | 2181 | utils.delete_file(outfile)
|
2177 |
| - self.compile_btest(args, reporting=reporting) |
| 2182 | + self.compile_btest(filename, args, reporting=reporting) |
2178 | 2183 | self.assertExists(outfile)
|
2179 | 2184 | if post_build:
|
2180 | 2185 | post_build()
|
|
0 commit comments