Skip to content

Commit c677c93

Browse files
committed
[test] Pass filename explicitly to compile_btest helper. NFC
This allows us to use `compiler_for` to determine whether to run `EMCC` or `EMXX` appropriately.
1 parent edc1a75 commit c677c93

File tree

4 files changed

+91
-91
lines changed

4 files changed

+91
-91
lines changed

test/common.py

+24-19
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from tools.shared import EMCC, EMXX, DEBUG, EMCONFIGURE, EMCMAKE
3737
from tools.shared import get_canonical_temp_dir, path_from_root
3838
from tools.utils import MACOS, WINDOWS, read_file, read_binary, write_binary, exit_with_error
39+
from tools.settings import COMPILE_TIME_SETTINGS
3940
from tools import shared, line_endings, building, config, utils
4041

4142
logger = logging.getLogger('common')
@@ -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'):
@@ -1359,7 +1362,7 @@ def get_library(self, name, generated_libs, configure=['sh', './configure'], #
13591362
# try to pass linker settings when compiling).
13601363
emcc_args = []
13611364
if not native:
1362-
emcc_args = self.get_emcc_args(ldflags=False)
1365+
emcc_args = self.get_emcc_args(compile_only=False)
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)
@@ -2111,24 +2114,26 @@ def reftest(self, expected, manually_trigger=False):
21112114
setupRefTest();
21122115
''' % (reporting, basename, int(manually_trigger)))
21132116

2114-
def compile_btest(self, args, reporting=Reporting.FULL):
2117+
def compile_btest(self, filename, args, reporting=Reporting.FULL):
21152118
# Inject support code for reporting results. This adds an include a header so testcases can
21162119
# use REPORT_RESULT, and also adds a cpp file to be compiled alongside the testcase, which
21172120
# contains the implementation of REPORT_RESULT (we can't just include that implementation in
21182121
# the header as there may be multiple files being compiled here).
21192122
if reporting != Reporting.NONE:
21202123
# 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')]
21232125
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')]
21292132
if EMTEST_BROWSER == 'node':
21302133
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)
21322137

21332138
def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):
21342139
"""Special case of btest that reports its result solely via exiting
@@ -2171,10 +2176,10 @@ def btest(self, filename, expected=None, reference=None,
21712176
# manual_reference only makes sense for reference tests
21722177
assert manual_reference is None
21732178
outfile = output_basename + '.html'
2174-
args += [filename, '-o', outfile]
2179+
args += ['-o', outfile]
21752180
# print('all args:', args)
21762181
utils.delete_file(outfile)
2177-
self.compile_btest(args, reporting=reporting)
2182+
self.compile_btest(filename, args, reporting=reporting)
21782183
self.assertExists(outfile)
21792184
if post_build:
21802185
post_build()

0 commit comments

Comments
 (0)