Skip to content

Commit 78508a9

Browse files
committed
Move some log level utility code to util.py. NFC
1 parent d653a2a commit 78508a9

18 files changed

+146
-138
lines changed

emcc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
from tools import shared, system_libs, utils, cmdline
3737
from tools import diagnostics, building, compile
38-
from tools.shared import unsuffixed_basename, get_file_suffix
3938
from tools.shared import exit_with_error, DEBUG
4039
from tools.shared import in_temp
4140
from tools.shared import DYLIB_EXTENSIONS
@@ -44,7 +43,7 @@
4443
from tools import config
4544
from tools import cache
4645
from tools.settings import default_setting, user_settings, settings, COMPILE_TIME_SETTINGS
47-
from tools.utils import read_file
46+
from tools.utils import read_file, unsuffixed_basename, get_file_suffix
4847

4948
logger = logging.getLogger('emcc')
5049

@@ -566,7 +565,7 @@ def compile_source_file(input_file):
566565
if not shared.SKIP_SUBPROCS:
567566
assert os.path.exists(output_file)
568567
if options.save_temps:
569-
shutil.copyfile(output_file, shared.unsuffixed_basename(input_file) + '.o')
568+
shutil.copyfile(output_file, utils.unsuffixed_basename(input_file) + '.o')
570569
return output_file
571570

572571
# Compile input files individually to temporary locations.

test/common.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import clang_native
3838
import jsrun
3939
import line_endings
40-
from tools.shared import EMCC, EMXX, DEBUG, exe_suffix
40+
from tools.shared import EMCC, EMXX, DEBUG
4141
from tools.shared import get_canonical_temp_dir, path_from_root
4242
from tools.utils import MACOS, WINDOWS, read_file, read_binary, write_binary, exit_with_error
4343
from tools.settings import COMPILE_TIME_SETTINGS
@@ -125,7 +125,7 @@ class FirefoxConfig:
125125
data_dir_flag = '-profile '
126126
default_flags = ('-new-instance',)
127127
headless_flags = '-headless'
128-
executable_name = exe_suffix('firefox')
128+
executable_name = utils.exe_suffix('firefox')
129129

130130
@staticmethod
131131
def configure(data_dir):
@@ -157,13 +157,13 @@ def configure(data_dir):
157157

158158
DEFAULT_BROWSER_DATA_DIR = path_from_root('out/browser-profile')
159159

160-
WEBIDL_BINDER = shared.bat_suffix(path_from_root('tools/webidl_binder'))
160+
WEBIDL_BINDER = utils.bat_suffix(path_from_root('tools/webidl_binder'))
161161

162-
EMBUILDER = shared.bat_suffix(path_from_root('embuilder'))
163-
EMMAKE = shared.bat_suffix(path_from_root('emmake'))
164-
EMCMAKE = shared.bat_suffix(path_from_root('emcmake'))
165-
EMCONFIGURE = shared.bat_suffix(path_from_root('emconfigure'))
166-
EMRUN = shared.bat_suffix(shared.path_from_root('emrun'))
162+
EMBUILDER = utils.bat_suffix(path_from_root('embuilder'))
163+
EMMAKE = utils.bat_suffix(path_from_root('emmake'))
164+
EMCMAKE = utils.bat_suffix(path_from_root('emcmake'))
165+
EMCONFIGURE = utils.bat_suffix(path_from_root('emconfigure'))
166+
EMRUN = utils.bat_suffix(shared.path_from_root('emrun'))
167167
WASM_DIS = os.path.join(building.get_binaryen_bin(), 'wasm-dis')
168168
LLVM_OBJDUMP = shared.llvm_tool_path('llvm-objdump')
169169
PYTHON = sys.executable
@@ -240,7 +240,7 @@ def get_browser_config():
240240

241241

242242
def compiler_for(filename, force_c=False):
243-
if shared.suffix(filename) in ('.cc', '.cxx', '.cpp') and not force_c:
243+
if utils.suffix(filename) in ('.cc', '.cxx', '.cpp') and not force_c:
244244
return EMXX
245245
else:
246246
return EMCC
@@ -1531,7 +1531,7 @@ def build(self, filename, libraries=None, includes=None, force_c=False, cflags=N
15311531
compiler = [compiler_for(filename, force_c)]
15321532

15331533
if force_c:
1534-
assert shared.suffix(filename) != '.c', 'force_c is not needed for source files ending in .c'
1534+
assert utils.suffix(filename) != '.c', 'force_c is not needed for source files ending in .c'
15351535
compiler.append('-xc')
15361536

15371537
all_cflags = self.get_cflags(main_file=True)
@@ -1543,7 +1543,7 @@ def build(self, filename, libraries=None, includes=None, force_c=False, cflags=N
15431543
if output_basename:
15441544
output = output_basename + output_suffix
15451545
else:
1546-
output = shared.unsuffixed_basename(filename) + output_suffix
1546+
output = utils.unsuffixed_basename(filename) + output_suffix
15471547
cmd = compiler + [str(filename), '-o', output] + all_cflags
15481548
if libraries:
15491549
cmd += libraries
@@ -1983,7 +1983,7 @@ def _test_dylink_dso_needed(self, do_run):
19831983
so = '.wasm' if self.is_wasm() else '.js'
19841984

19851985
def ccshared(src, linkto=None):
1986-
cmdv = [EMCC, src, '-o', shared.unsuffixed(src) + so, '-sSIDE_MODULE'] + self.get_cflags()
1986+
cmdv = [EMCC, src, '-o', utils.unsuffixed(src) + so, '-sSIDE_MODULE'] + self.get_cflags()
19871987
if linkto:
19881988
cmdv += linkto
19891989
self.run_process(cmdv)
@@ -2059,7 +2059,7 @@ def do_runf(self, filename, expected_output=None, **kwargs):
20592059
def do_run_in_out_file_test(self, srcfile, **kwargs):
20602060
srcfile = maybe_test_file(srcfile)
20612061
out_suffix = kwargs.pop('out_suffix', '')
2062-
outfile = shared.unsuffixed(srcfile) + out_suffix + '.out'
2062+
outfile = utils.unsuffixed(srcfile) + out_suffix + '.out'
20632063
if EMTEST_REBASELINE:
20642064
expected = None
20652065
else:

test/jsrun.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
from subprocess import PIPE, CalledProcessError
1313

14-
from tools import shared, utils
14+
from tools import utils
1515

1616
WORKING_ENGINES = {} # Holds all configured engines and whether they work: maps path -> True/False
1717
DEFAULT_TIMEOUT = 5 * 60
@@ -22,7 +22,7 @@ def make_command(filename, engine, args=None):
2222
# if no engine is needed, indicated by None, then there is a native executable
2323
# provided which we can just run
2424
if engine[0] is None:
25-
executable = shared.replace_suffix(os.path.abspath(filename), '.exe')
25+
executable = utils.replace_suffix(os.path.abspath(filename), '.exe')
2626
return [executable] + args
2727
# Emscripten supports multiple javascript runtimes. The default is nodejs but
2828
# it can also use d8 (the v8 engine shell) or jsc (JavaScript Core aka
@@ -43,7 +43,7 @@ def make_command(filename, engine, args=None):
4343
command_flags += ['run']
4444
if is_wasmer or is_wasmtime:
4545
# in a wasm runtime, run the wasm, not the js
46-
filename = shared.replace_suffix(filename, '.wasm')
46+
filename = utils.replace_suffix(filename, '.wasm')
4747
# Separates engine flags from script flags
4848
flag_separator = ['--'] if is_d8 or is_jsc else []
4949
return engine + command_flags + [filename] + flag_separator + args

test/test_benchmark.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from tools.shared import CLANG_CC, CLANG_CXX
2525
from common import test_file, read_file, read_binary, needs_make
2626
from tools.shared import run_process, PIPE, EMCC, config
27-
from tools import building, utils, shared
27+
from tools import building, utils
2828

2929
# standard arguments for timing:
3030
# 0: no runtime, just startup
@@ -250,7 +250,7 @@ def build(self, parent, filename, args, shared_args, emcc_args, native_args, nat
250250
self.cmd = cmd
251251
run_process(cmd, env=self.env)
252252
if self.binaryen_opts:
253-
run_binaryen_opts(shared.replace_suffix(final, '.wasm'), self.binaryen_opts)
253+
run_binaryen_opts(utils.replace_suffix(final, '.wasm'), self.binaryen_opts)
254254
self.filename = final
255255

256256
def run(self, args):
@@ -260,12 +260,12 @@ def get_output_files(self):
260260
ret = [self.filename]
261261
if 'WASM=0' in self.cmd:
262262
if 'MINIMAL_RUNTIME=0' not in self.cmd:
263-
ret.append(shared.replace_suffix(self.filename, '.asm.js'))
264-
ret.append(shared.replace_suffix(self.filename, '.mem'))
263+
ret.append(utils.replace_suffix(self.filename, '.asm.js'))
264+
ret.append(utils.replace_suffix(self.filename, '.mem'))
265265
else:
266266
ret.append(self.filename + '.mem')
267267
else:
268-
ret.append(shared.replace_suffix(self.filename, '.wasm'))
268+
ret.append(utils.replace_suffix(self.filename, '.wasm'))
269269
return ret
270270

271271

@@ -346,7 +346,7 @@ def run(self, args):
346346
return jsrun.run_js(self.filename, engine=self.engine, args=args, stderr=PIPE)
347347

348348
def get_output_files(self):
349-
return [self.filename, shared.replace_suffix(self.filename, '.wasm')]
349+
return [self.filename, utils.replace_suffix(self.filename, '.wasm')]
350350

351351

352352
# Benchmarkers

test/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4067,7 +4067,7 @@ def dylink_testf(self, main, side=None, expected=None, force_c=False, main_cflag
40674067
# Same as dylink_test but takes source code as filenames on disc.
40684068
old_args = self.cflags.copy()
40694069
if not expected:
4070-
outfile = shared.replace_suffix(main, '.out')
4070+
outfile = utils.replace_suffix(main, '.out')
40714071
expected = read_file(outfile)
40724072
if not side:
40734073
side, ext = os.path.splitext(main)

test/test_other.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@
5151
from tools.settings import settings
5252
from tools.system_libs import DETERMINISTIC_PREFIX
5353

54-
emmake = shared.bat_suffix(path_from_root('emmake'))
55-
emconfig = shared.bat_suffix(path_from_root('em-config'))
56-
emsize = shared.bat_suffix(path_from_root('emsize'))
57-
empath_split = shared.bat_suffix(path_from_root('empath-split'))
58-
emprofile = shared.bat_suffix(path_from_root('emprofile'))
59-
emstrip = shared.bat_suffix(path_from_root('emstrip'))
60-
emsymbolizer = shared.bat_suffix(path_from_root('emsymbolizer'))
54+
emmake = utils.bat_suffix(path_from_root('emmake'))
55+
emconfig = utils.bat_suffix(path_from_root('em-config'))
56+
emsize = utils.bat_suffix(path_from_root('emsize'))
57+
empath_split = utils.bat_suffix(path_from_root('empath-split'))
58+
emprofile = utils.bat_suffix(path_from_root('emprofile'))
59+
emstrip = utils.bat_suffix(path_from_root('emstrip'))
60+
emsymbolizer = utils.bat_suffix(path_from_root('emsymbolizer'))
6161

6262

6363
def is_bitcode(filename):
@@ -2946,7 +2946,7 @@ def test_js_optimizer(self, passes, filename=None):
29462946
testname = self.id().split('.')[-1]
29472947
filename = utils.removeprefix(testname, 'test_js_optimizer_') + '.js'
29482948
filename = test_file('js_optimizer', filename)
2949-
expected_file = shared.unsuffixed(filename) + '-output.js'
2949+
expected_file = utils.unsuffixed(filename) + '-output.js'
29502950
# test calling optimizer
29512951
js = self.run_process(config.NODE_JS + [path_from_root('tools/acorn-optimizer.mjs'), filename] + passes, stdin=PIPE, stdout=PIPE).stdout
29522952
if common.EMTEST_REBASELINE:
@@ -3981,7 +3981,7 @@ def test_file_packager_depfile(self, embed):
39813981
else:
39823982
self.run_process([FILE_PACKAGER, 'test.data', '--js-output=test.js', '--depfile=test.data.d', '--from-emcc', '--preload', '.'])
39833983
output = read_file('test.data.d')
3984-
file_packager = utils.normalize_path(shared.replace_suffix(FILE_PACKAGER, '.py'))
3984+
file_packager = utils.normalize_path(utils.replace_suffix(FILE_PACKAGER, '.py'))
39853985
file_packager = file_packager.replace(' ', '\\ ')
39863986
lines = output.splitlines()
39873987
split = lines.index(': \\')
@@ -6902,7 +6902,7 @@ def test_sdl2_config(self):
69026902
[['--cflags', '--libs'], '-sUSE_SDL=2'],
69036903
]:
69046904
print(args, expected)
6905-
out = self.run_process([shared.bat_suffix(cache.get_sysroot_dir('bin/sdl2-config'))] + args,
6905+
out = self.run_process([utils.bat_suffix(cache.get_sysroot_dir('bin/sdl2-config'))] + args,
69066906
stdout=PIPE, stderr=PIPE).stdout
69076907
self.assertContained(expected, out)
69086908
print('via emmake')

test/test_sanity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def make_readonly(filename):
488488
with env_modify({'EM_CACHE': self.in_dir('test_cache')}):
489489
self.run_process([EMCC, test_file('hello_world.c'), '-c'])
490490
finally:
491-
for_all_files(path_from_root('system/include'), shared.make_writable)
491+
for_all_files(path_from_root('system/include'), utils.make_writable)
492492

493493
@parameterized({
494494
'': [False, False],
@@ -831,7 +831,7 @@ def test_bootstrap_without_em_config(self):
831831

832832
# Remove from PATH every directory that contains clang.exe so that bootstrap.py cannot
833833
# accidentally succeed by virtue of locating tools in PATH.
834-
new_path = [d for d in env['PATH'].split(os.pathsep) if not os.path.isfile(os.path.join(d, shared.exe_suffix('clang')))]
834+
new_path = [d for d in env['PATH'].split(os.pathsep) if not os.path.isfile(os.path.join(d, utils.exe_suffix('clang')))]
835835
env['PATH'] = os.pathsep.join(new_path)
836836

837837
# Running bootstrap.py should not fail

tools/building.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from .shared import path_from_root
3232
from .shared import asmjs_mangle, DEBUG
3333
from .shared import LLVM_DWARFDUMP, demangle_c_symbol_name
34-
from .shared import get_emscripten_temp_dir, exe_suffix, is_c_symbol
34+
from .shared import get_emscripten_temp_dir, is_c_symbol
3535
from .utils import WINDOWS
3636
from .settings import settings
3737
from .feature_matrix import UNSUPPORTED
@@ -384,9 +384,9 @@ def acorn_optimizer(filename, passes, extra_info=None, return_output=False, work
384384
return check_call(cmd, stdout=PIPE).stdout
385385

386386
acorn_optimizer.counter += 1
387-
basename = shared.unsuffixed(original_filename)
387+
basename = utils.unsuffixed(original_filename)
388388
if '.jso' in basename:
389-
basename = shared.unsuffixed(basename)
389+
basename = utils.unsuffixed(basename)
390390
output_file = basename + '.jso%d.js' % acorn_optimizer.counter
391391
shared.get_temp_files().note(output_file)
392392
cmd += ['-o', output_file]
@@ -1181,7 +1181,7 @@ def get_binaryen_feature_flags():
11811181

11821182

11831183
def check_binaryen(bindir):
1184-
opt = os.path.join(bindir, exe_suffix('wasm-opt'))
1184+
opt = os.path.join(bindir, utils.exe_suffix('wasm-opt'))
11851185
if not os.path.exists(opt):
11861186
exit_with_error('binaryen executable not found (%s). Please check your binaryen installation' % opt)
11871187
try:

tools/empath-split.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def parse_args():
8989
if args.preserve_manifest:
9090
args.verbose = True
9191
if not args.wasm_split:
92-
args.wasm_split = os.path.join(building.get_binaryen_bin(), shared.exe_suffix('wasm-split'))
92+
args.wasm_split = os.path.join(building.get_binaryen_bin(), utils.exe_suffix('wasm-split'))
9393

9494
if '--manifest' in forwarded_args:
9595
parser.error('manifest file will be generated by this script and should not be given')

tools/file_packager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def generate_object_file(data_files):
255255
embed_files = [f for f in data_files if f.mode == 'embed']
256256
assert embed_files
257257

258-
asm_file = shared.replace_suffix(options.obj_output, '.s')
258+
asm_file = utils.replace_suffix(options.obj_output, '.s')
259259

260260
used = set()
261261
for f in embed_files:

0 commit comments

Comments
 (0)