Skip to content

Commit f4a55f6

Browse files
committed
Move compiler paths out of top level of shared.py. NFC
This is a step towards separating the import of python modules from the initialization of the compiler. The goal here is to remove top level code (i.e. Remove side effects from importing).
1 parent 8a64c36 commit f4a55f6

22 files changed

+140
-132
lines changed

emar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212
from tools import shared
1313

14-
shared.exec_process([shared.LLVM_AR] + sys.argv[1:])
14+
shared.exec_process([shared.paths.LLVM_AR] + sys.argv[1:])

emcc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from tools.cmdline import CLANG_FLAGS_WITH_ARGS, options
4444
from tools.response_file import substitute_response_files
4545
from tools.settings import COMPILE_TIME_SETTINGS, default_setting, settings, user_settings
46-
from tools.shared import DEBUG, DYLIB_EXTENSIONS, in_temp
46+
from tools.shared import DEBUG, DYLIB_EXTENSIONS, in_temp, paths
4747
from tools.toolchain_profiler import ToolchainProfiler
4848
from tools.utils import exit_with_error, get_file_suffix, read_file, unsuffixed_basename
4949

@@ -168,9 +168,9 @@ def make_relative(filename):
168168
@ToolchainProfiler.profile()
169169
def main(args):
170170
if shared.run_via_emxx:
171-
clang = shared.CLANG_CXX
171+
clang = paths.CLANG_CXX
172172
else:
173-
clang = shared.CLANG_CC
173+
clang = paths.CLANG_CC
174174

175175
# Special case the handling of `-v` because it has a special/different meaning
176176
# when used with no other arguments. In particular, we must handle this early
@@ -477,9 +477,9 @@ def phase_setup(state):
477477
@ToolchainProfiler.profile_block('compile inputs')
478478
def phase_compile_inputs(options, state, newargs):
479479
if shared.run_via_emxx:
480-
compiler = [shared.CLANG_CXX]
480+
compiler = [paths.CLANG_CXX]
481481
else:
482-
compiler = [shared.CLANG_CC]
482+
compiler = [paths.CLANG_CC]
483483

484484
if config.COMPILER_WRAPPER:
485485
logger.debug('using compiler wrapper: %s', config.COMPILER_WRAPPER)

emranlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
from tools import shared
1616

17-
shared.exec_process([shared.LLVM_RANLIB] + sys.argv[1:])
17+
shared.exec_process([shared.paths.LLVM_RANLIB] + sys.argv[1:])

emstrip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212
from tools import shared
1313

14-
shared.exec_process([shared.LLVM_STRIP] + sys.argv[1:])
14+
shared.exec_process([shared.paths.LLVM_STRIP] + sys.argv[1:])

test/browser_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
from tools import feature_matrix, shared, utils
3838
from tools.feature_matrix import UNSUPPORTED
39-
from tools.shared import DEBUG, EMCC, exit_with_error
39+
from tools.shared import DEBUG, exit_with_error, paths
4040
from tools.utils import MACOS, WINDOWS, memoize, path_from_root, read_binary
4141

4242
logger = logging.getLogger('common')
@@ -878,7 +878,7 @@ def compile_btest(self, filename, cflags, reporting=Reporting.FULL):
878878
if reporting == Reporting.FULL:
879879
# If C reporting (i.e. the REPORT_RESULT macro) is required we
880880
# also include report_result.c and force-include report_result.h
881-
self.run_process([EMCC, '-c', '-I' + TEST_ROOT,
881+
self.run_process([paths.EMCC, '-c', '-I' + TEST_ROOT,
882882
test_file('report_result.c')] + self.get_cflags(compile_only=True) + (['-fPIC'] if '-fPIC' in cflags else []))
883883
cflags += ['report_result.o', '-include', test_file('report_result.h')]
884884
if EMTEST_BROWSER == 'node':

test/clang_native.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import platform
99
import sys
1010

11-
from tools.shared import CLANG_CC, CLANG_CXX, PIPE
11+
from tools.shared import PIPE, paths
1212
from tools.utils import MACOS, WINDOWS, path_from_root, run_process
1313

1414
logger = logging.getLogger('clang_native')
@@ -63,9 +63,9 @@ def get_clang_native_env():
6363
return CACHED_CLANG_NATIVE_ENV
6464
env = os.environ.copy()
6565

66-
env['CC'] = CLANG_CC
67-
env['CXX'] = CLANG_CXX
68-
env['LD'] = CLANG_CXX
66+
env['CC'] = paths.CLANG_CC
67+
env['CXX'] = paths.CLANG_CXX
68+
env['LD'] = paths.CLANG_CXX
6969

7070
if MACOS:
7171
path = run_process(['xcrun', '--show-sdk-path'], stdout=PIPE).stdout.strip()

test/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from tools import building, config, feature_matrix, shared, utils
3333
from tools.feature_matrix import Feature
3434
from tools.settings import COMPILE_TIME_SETTINGS
35-
from tools.shared import DEBUG, EMCC, EMXX, get_canonical_temp_dir
35+
from tools.shared import DEBUG, get_canonical_temp_dir, paths
3636
from tools.utils import (
3737
WINDOWS,
3838
exit_with_error,
@@ -130,9 +130,9 @@ def copytree(src, dest):
130130

131131
def compiler_for(filename, force_c=False):
132132
if utils.suffix(filename) in ('.cc', '.cxx', '.cpp') and not force_c:
133-
return EMXX
133+
return paths.EMXX
134134
else:
135-
return EMCC
135+
return paths.EMCC
136136

137137

138138
def record_flaky_test(test_name, attempt_count, max_attempts, exception_msg):
@@ -1272,7 +1272,7 @@ def _test_dylink_dso_needed(self, do_run):
12721272
''')
12731273

12741274
def ccshared(src, linkto=None):
1275-
cmdv = [EMCC, src, '-o', utils.unsuffixed(src) + '.wasm', '-sSIDE_MODULE'] + self.get_cflags()
1275+
cmdv = [paths.EMCC, src, '-o', utils.unsuffixed(src) + '.wasm', '-sSIDE_MODULE'] + self.get_cflags()
12761276
if linkto:
12771277
cmdv += linkto
12781278
self.run_process(cmdv)

test/test_benchmark.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from decorators import needs_make
2626

2727
from tools import building, utils
28-
from tools.shared import CLANG_CC, CLANG_CXX, EMCC, PIPE, config
28+
from tools.shared import PIPE, config, paths
2929
from tools.utils import run_process
3030

3131
# standard arguments for timing:
@@ -232,7 +232,7 @@ def build(self, parent, filename, args, shared_args, emcc_args, native_args, nat
232232
final = final.replace('.cpp', '')
233233
utils.delete_file(final)
234234
cmd = [
235-
EMCC, filename,
235+
paths.EMCC, filename,
236236
OPTIMIZATIONS,
237237
'-sINITIAL_MEMORY=256MB',
238238
'-sENVIRONMENT=node,shell',
@@ -361,7 +361,7 @@ def get_output_files(self):
361361
aot_v8 = (config.V8_ENGINE if config.V8_ENGINE else []) + ['--no-liftoff']
362362

363363
named_benchmarkers = {
364-
'clang': NativeBenchmarker('clang', [CLANG_CC], [CLANG_CXX]),
364+
'clang': NativeBenchmarker('clang', [paths.CLANG_CC], [paths.CLANG_CXX]),
365365
'gcc': NativeBenchmarker('gcc', ['gcc', '-no-pie'], ['g++', '-no-pie']),
366366
'size': SizeBenchmarker('size'),
367367
'v8': EmscriptenBenchmarker('v8', aot_v8),

test/test_browser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@
7070

7171
from tools import ports, shared
7272
from tools.feature_matrix import Feature
73-
from tools.shared import EMCC, FILE_PACKAGER, PIPE
73+
from tools.shared import PIPE, paths
7474
from tools.utils import WINDOWS, delete_dir
7575

76+
EMCC = paths.EMCC
77+
FILE_PACKAGER = paths.FILE_PACKAGER
78+
7679

7780
def make_test_chunked_synchronous_xhr_server(support_byte_ranges, data, port):
7881
class ChunkedServerHandler(BaseHTTPRequestHandler):

test/test_core.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
)
7373

7474
from tools import building, config, shared, utils, webassembly
75-
from tools.shared import EMAR, EMCC, EMXX, FILE_PACKAGER, LLVM_COV, LLVM_PROFDATA, PIPE
75+
from tools.shared import PIPE, paths
7676
from tools.utils import LINUX, MACOS, WINDOWS, delete_file, write_file
7777

7878
# decorators for limiting which modes a test can run in
@@ -82,6 +82,10 @@
8282
EM_SIGINT = 2
8383
EM_SIGABRT = 6
8484

85+
EMAR = paths.EMAR
86+
EMCC = paths.EMCC
87+
EMXX = paths.EMXX
88+
8589

8690
def esm_integration(func):
8791
assert callable(func)
@@ -6599,7 +6603,7 @@ def test_neon_wasm_simd(self):
65996603
@no_big_endian('SIMD support is currently not compatible with big endian')
66006604
def test_sse1(self, args):
66016605
src = test_file('sse/test_sse1.cpp')
6602-
self.run_process([shared.CLANG_CXX, src, '-msse', '-o', 'test_sse1', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
6606+
self.run_process([paths.CLANG_CXX, src, '-msse', '-o', 'test_sse1', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
66036607
native_result = self.run_process('./test_sse1', stdout=PIPE).stdout
66046608

66056609
self.maybe_closure()
@@ -6620,7 +6624,7 @@ def test_sse1(self, args):
66206624
@no_big_endian('SIMD support is currently not compatible with big endian')
66216625
def test_sse2(self, args):
66226626
src = test_file('sse/test_sse2.cpp')
6623-
self.run_process([shared.CLANG_CXX, src, '-msse2', '-Wno-argument-outside-range', '-o', 'test_sse2', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
6627+
self.run_process([paths.CLANG_CXX, src, '-msse2', '-Wno-argument-outside-range', '-o', 'test_sse2', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
66246628
native_result = self.run_process('./test_sse2', stdout=PIPE).stdout
66256629

66266630
self.cflags += ['-I' + test_file('sse'), '-msse2', '-fno-inline-functions', '-Wno-argument-outside-range', '-sSTACK_SIZE=1MB'] + args
@@ -6634,7 +6638,7 @@ def test_sse2(self, args):
66346638
@no_big_endian('SIMD support is currently not compatible with big endian')
66356639
def test_sse3(self):
66366640
src = test_file('sse/test_sse3.cpp')
6637-
self.run_process([shared.CLANG_CXX, src, '-msse3', '-Wno-argument-outside-range', '-o', 'test_sse3', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
6641+
self.run_process([paths.CLANG_CXX, src, '-msse3', '-Wno-argument-outside-range', '-o', 'test_sse3', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
66386642
native_result = self.run_process('./test_sse3', stdout=PIPE).stdout
66396643

66406644
self.cflags += ['-I' + test_file('sse'), '-msse3', '-Wno-argument-outside-range']
@@ -6648,7 +6652,7 @@ def test_sse3(self):
66486652
@no_big_endian('SIMD support is currently not compatible with big endian')
66496653
def test_ssse3(self):
66506654
src = test_file('sse/test_ssse3.cpp')
6651-
self.run_process([shared.CLANG_CXX, src, '-mssse3', '-Wno-argument-outside-range', '-o', 'test_ssse3', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
6655+
self.run_process([paths.CLANG_CXX, src, '-mssse3', '-Wno-argument-outside-range', '-o', 'test_ssse3', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
66526656
native_result = self.run_process('./test_ssse3', stdout=PIPE).stdout
66536657

66546658
self.cflags += ['-I' + test_file('sse'), '-mssse3', '-Wno-argument-outside-range']
@@ -6665,7 +6669,7 @@ def test_ssse3(self):
66656669
def test_sse4_1(self):
66666670
src = test_file('sse/test_sse4_1.cpp')
66676671
# Run with inlining disabled to avoid slow LLVM behavior with lots of macro expanded loops inside a function body.
6668-
self.run_process([shared.CLANG_CXX, src, '-msse4.1', '-fno-inline-functions', '-Wno-argument-outside-range', '-o', 'test_sse4_1', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
6672+
self.run_process([paths.CLANG_CXX, src, '-msse4.1', '-fno-inline-functions', '-Wno-argument-outside-range', '-o', 'test_sse4_1', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
66696673
native_result = self.run_process('./test_sse4_1', stdout=PIPE).stdout
66706674

66716675
self.cflags += ['-I' + test_file('sse'), '-msse4.1', '-fno-inline-functions', '-Wno-argument-outside-range', '-sSTACK_SIZE=1MB']
@@ -6684,7 +6688,7 @@ def test_sse4_1(self):
66846688
def test_sse4(self, use_4_2):
66856689
msse4 = '-msse4.2' if use_4_2 else '-msse4'
66866690
src = test_file('sse/test_sse4_2.cpp')
6687-
self.run_process([shared.CLANG_CXX, src, msse4, '-Wno-argument-outside-range', '-o', 'test_sse4_2', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
6691+
self.run_process([paths.CLANG_CXX, src, msse4, '-Wno-argument-outside-range', '-o', 'test_sse4_2', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
66886692
native_result = self.run_process('./test_sse4_2', stdout=PIPE).stdout
66896693

66906694
self.cflags += ['-I' + test_file('sse'), msse4, '-Wno-argument-outside-range']
@@ -6705,7 +6709,7 @@ def test_sse4(self, use_4_2):
67056709
@no_big_endian('SIMD support is currently not compatible with big endian')
67066710
def test_avx(self, args):
67076711
src = test_file('sse/test_avx.cpp')
6708-
self.run_process([shared.CLANG_CXX, src, '-mavx', '-Wno-argument-outside-range', '-Wpedantic', '-o', 'test_avx', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
6712+
self.run_process([paths.CLANG_CXX, src, '-mavx', '-Wno-argument-outside-range', '-Wpedantic', '-o', 'test_avx', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
67096713
native_result = self.run_process('./test_avx', stdout=PIPE).stdout
67106714

67116715
self.cflags += ['-I' + test_file('sse'), '-mavx', '-fno-inline-functions', '-Wno-argument-outside-range', '-sSTACK_SIZE=1MB'] + args
@@ -6726,7 +6730,7 @@ def test_avx(self, args):
67266730
@no_big_endian('SIMD support is currently not compatible with big endian')
67276731
def test_avx2(self, args):
67286732
src = test_file('sse/test_avx2.cpp')
6729-
self.run_process([shared.CLANG_CXX, src, '-mavx2', '-Wno-argument-outside-range', '-Wpedantic', '-o', 'test_avx2', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
6733+
self.run_process([paths.CLANG_CXX, src, '-mavx2', '-Wno-argument-outside-range', '-Wpedantic', '-o', 'test_avx2', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
67306734
native_result = self.run_process('./test_avx2', stdout=PIPE).stdout
67316735

67326736
self.cflags += ['-I' + test_file('sse'), '-mavx2', '-Wno-argument-outside-range', '-sSTACK_SIZE=1MB'] + args
@@ -6738,9 +6742,7 @@ def test_sse_diagnostics(self):
67386742
self.cflags.remove('-Werror')
67396743
src = test_file('sse/test_sse_diagnostic.cpp')
67406744

6741-
p = self.run_process(
6742-
[shared.EMXX, src, '-msse', '-DWASM_SIMD_COMPAT_SLOW'] + self.get_cflags(),
6743-
stderr=PIPE)
6745+
p = self.run_process([paths.EMXX, src, '-msse', '-DWASM_SIMD_COMPAT_SLOW'] + self.get_cflags(), stderr=PIPE)
67446746
self.assertContained('Instruction emulated via slow path.', p.stderr)
67456747

67466748
@wasm_relaxed_simd
@@ -7960,7 +7962,7 @@ def test_dwarf(self):
79607962

79617963
self.emcc('test_dwarf.c')
79627964

7963-
out = self.run_process([shared.LLVM_DWARFDUMP, 'a.out.wasm', '-all'], stdout=PIPE).stdout
7965+
out = self.run_process([paths.LLVM_DWARFDUMP, 'a.out.wasm', '-all'], stdout=PIPE).stdout
79647966

79657967
# parse the sections
79667968
sections = {}
@@ -9680,7 +9682,7 @@ def test_emscripten_async_load_script(self):
96809682
create_file('file2.txt', 'second')
96819683
# `--from-emcc` needed here otherwise the output defines `var Module =` which will shadow the
96829684
# global `Module`.
9683-
self.run_process([FILE_PACKAGER, 'test.data', '--preload', 'file1.txt', 'file2.txt', '--from-emcc', '--js-output=script2.js'])
9685+
self.run_process([paths.FILE_PACKAGER, 'test.data', '--preload', 'file1.txt', 'file2.txt', '--from-emcc', '--js-output=script2.js'])
96849686
self.do_runf('test_emscripten_async_load_script.c', cflags=['-sFORCE_FILESYSTEM'])
96859687

96869688
@node_pthreads
@@ -9820,9 +9822,9 @@ def test_fcoverage_mapping(self):
98209822
self.set_setting('EXIT_RUNTIME')
98219823
self.do_core_test('test_hello_world.c', cflags=['-fprofile-instr-generate', '-fcoverage-mapping', '-g'])
98229824
self.assertExists('default.profraw')
9823-
self.run_process([LLVM_PROFDATA, 'merge', '-sparse', 'default.profraw', '-o', 'out.profdata'])
9825+
self.run_process([paths.LLVM_PROFDATA, 'merge', '-sparse', 'default.profraw', '-o', 'out.profdata'])
98249826
self.assertExists('out.profdata')
9825-
self.assertEqual(expected, self.run_process([LLVM_COV, 'show', 'test_hello_world.wasm', '-instr-profile=out.profdata'], stdout=PIPE).stdout)
9827+
self.assertEqual(expected, self.run_process([paths.LLVM_COV, 'show', 'test_hello_world.wasm', '-instr-profile=out.profdata'], stdout=PIPE).stdout)
98269828

98279829
# Generate tests for everything
98289830
def make_run(name, cflags=None, settings=None, env=None, # noqa

0 commit comments

Comments
 (0)