Skip to content

Commit 4d31e72

Browse files
authored
[test] Have build_library helper using subprocess wrapper. NFC (emscripten-core#26071)
The build_library helper function was not hiding its output by default because it wasn't using the `self.run_process` wrapper than redirects output.
1 parent da52638 commit 4d31e72

File tree

1 file changed

+51
-66
lines changed

1 file changed

+51
-66
lines changed

test/common.py

Lines changed: 51 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ class RunnerCore(RetryableTestCase, metaclass=RunnerMeta):
327327
# Change this to None to get stderr reporting, for debugging purposes
328328
stderr_redirect = STDOUT
329329

330+
library_cache: dict[str, tuple[str, object]] = {}
331+
330332
def is_wasm(self):
331333
return self.get_setting('WASM') != 0
332334

@@ -1083,8 +1085,6 @@ def assertBinaryEqual(self, file1, file2):
10831085
self.assertEqual(read_binary(file1),
10841086
read_binary(file2))
10851087

1086-
library_cache: dict[str, tuple[str, object]] = {}
1087-
10881088
def get_build_dir(self):
10891089
ret = self.in_dir('building')
10901090
ensure_dir(ret)
@@ -1134,9 +1134,8 @@ def get_library(self, name, generated_libs, configure=['sh', './configure'], #
11341134
cflags = ' '.join(cflags)
11351135
env_init.setdefault('CFLAGS', cflags)
11361136
env_init.setdefault('CXXFLAGS', cflags)
1137-
return build_library(name, build_dir, generated_libs, configure,
1138-
make, make_args, self.library_cache,
1139-
cache_name, env_init=env_init, native=native)
1137+
return self.build_library(name, build_dir, generated_libs, configure,
1138+
make, make_args, cache_name, env_init=env_init, native=native)
11401139

11411140
def clear(self):
11421141
force_delete_contents(self.get_dir())
@@ -1484,78 +1483,64 @@ def get_zlib_library(self, cmake, cflags=None):
14841483
self.cflags = old_args
14851484
return rtn
14861485

1486+
def build_library(self, name, build_dir, generated_libs, configure, make, make_args, cache_name, env_init, native):
1487+
"""Build a library and cache the result. We build the library file
1488+
once and cache it for all our tests. (We cache in memory since the test
1489+
directory is destroyed and recreated for each test. Note that we cache
1490+
separately for different compilers). This cache is just during the test
1491+
runner. There is a different concept of caching as well, see |Cache|.
1492+
"""
1493+
if type(generated_libs) is not list:
1494+
generated_libs = [generated_libs]
1495+
source_dir = test_file(name.replace('_native', ''))
14871496

1488-
###################################################################################################
1489-
1490-
1491-
def build_library(name,
1492-
build_dir,
1493-
generated_libs,
1494-
configure,
1495-
make,
1496-
make_args,
1497-
cache,
1498-
cache_name,
1499-
env_init,
1500-
native):
1501-
"""Build a library and cache the result. We build the library file
1502-
once and cache it for all our tests. (We cache in memory since the test
1503-
directory is destroyed and recreated for each test. Note that we cache
1504-
separately for different compilers). This cache is just during the test
1505-
runner. There is a different concept of caching as well, see |Cache|.
1506-
"""
1507-
1508-
if type(generated_libs) is not list:
1509-
generated_libs = [generated_libs]
1510-
source_dir = test_file(name.replace('_native', ''))
1511-
1512-
project_dir = Path(build_dir, name)
1513-
if os.path.exists(project_dir):
1514-
shutil.rmtree(project_dir)
1515-
# Useful in debugging sometimes to comment this out, and two lines above
1516-
shutil.copytree(source_dir, project_dir)
1497+
project_dir = Path(build_dir, name)
1498+
if os.path.exists(project_dir):
1499+
shutil.rmtree(project_dir)
1500+
# Useful in debugging sometimes to comment this out, and two lines above
1501+
shutil.copytree(source_dir, project_dir)
15171502

1518-
generated_libs = [os.path.join(project_dir, lib) for lib in generated_libs]
1503+
generated_libs = [os.path.join(project_dir, lib) for lib in generated_libs]
15191504

1520-
if native:
1521-
env = clang_native.get_clang_native_env()
1522-
else:
1523-
env = os.environ.copy()
1524-
env.update(env_init)
1505+
if native:
1506+
env = clang_native.get_clang_native_env()
1507+
else:
1508+
env = os.environ.copy()
1509+
env.update(env_init)
15251510

1526-
if not native:
1527-
# Inject emcmake, emconfigure or emmake accordingly, but only if we are
1528-
# cross compiling.
1529-
if configure:
1530-
if configure[0] == 'cmake':
1531-
configure = [EMCMAKE] + configure
1511+
if not native:
1512+
# Inject emcmake, emconfigure or emmake accordingly, but only if we are
1513+
# cross compiling.
1514+
if configure:
1515+
if configure[0] == 'cmake':
1516+
configure = [EMCMAKE] + configure
1517+
else:
1518+
configure = [EMCONFIGURE] + configure
15321519
else:
1533-
configure = [EMCONFIGURE] + configure
1534-
else:
1535-
make = [EMMAKE] + make
1520+
make = [EMMAKE] + make
15361521

1537-
if configure:
1538-
utils.run_process(configure, env=env, cwd=project_dir)
1539-
# if we run configure or cmake we don't then need any kind
1540-
# of special env when we run make below
1541-
env = None
1522+
if configure:
1523+
self.run_process(configure, env=env, cwd=project_dir)
1524+
# if we run configure or cmake we don't then need any kind
1525+
# of special env when we run make below
1526+
env = None
15421527

1543-
def open_make_out(mode='r'):
1544-
return open(os.path.join(project_dir, 'make.out'), mode)
1528+
def open_make_out(mode='r'):
1529+
return open(os.path.join(project_dir, 'make.out'), mode)
15451530

1546-
def open_make_err(mode='r'):
1547-
return open(os.path.join(project_dir, 'make.err'), mode)
1531+
def open_make_err(mode='r'):
1532+
return open(os.path.join(project_dir, 'make.err'), mode)
15481533

1549-
if EMTEST_VERBOSE:
1550-
# VERBOSE=1 is cmake and V=1 is for autoconf
1551-
make_args += ['VERBOSE=1', 'V=1']
1534+
if EMTEST_VERBOSE:
1535+
# VERBOSE=1 is cmake and V=1 is for autoconf
1536+
make_args += ['VERBOSE=1', 'V=1']
15521537

1553-
utils.run_process(make + make_args, env=env, cwd=project_dir)
1538+
self.run_process(make + make_args, env=env, cwd=project_dir)
15541539

1555-
if cache is not None:
1556-
cache[cache_name] = []
1540+
# Cache the result
1541+
self.library_cache[cache_name] = []
15571542
for f in generated_libs:
15581543
basename = os.path.basename(f)
1559-
cache[cache_name].append((basename, read_binary(f)))
1544+
self.library_cache[cache_name].append((basename, read_binary(f)))
15601545

1561-
return generated_libs
1546+
return generated_libs

0 commit comments

Comments
 (0)