Skip to content

Commit 1f58cab

Browse files
authored
Remove unnecessary building.clear function. NFC (#16542)
This function was only called from `tests/test_benchmark.py` and it had no purpose. These tests the tests in general (including the benchmarker) always run emcc as a separate process. Calling this fuction doesn't effect past of future calls to emcc. This also allowed me to completely remove the cleanup method from `tests/test_benchmark.py` since I notices the environment overrides were already invjected by `env=` paramaeters to the emcc subprocess. This meant that overriding the current process environment was not needed.
1 parent 989f5c2 commit 1f58cab

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

tests/test_benchmark.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ def get_output_files(self):
163163
def get_size_text(self):
164164
return 'dynamically linked - libc etc. are not included!'
165165

166-
def cleanup(self):
167-
pass
168-
169166

170167
def run_binaryen_opts(filename, opts):
171168
run_process([
@@ -181,14 +178,11 @@ def __init__(self, name, engine, extra_args=[], env={}, binaryen_opts=[]):
181178
self.engine = engine
182179
self.extra_args = extra_args.copy()
183180
self.env = os.environ.copy()
184-
for k, v in env.items():
185-
self.env[k] = v
181+
self.env.update(env)
186182
self.binaryen_opts = binaryen_opts.copy()
187183

188184
def build(self, parent, filename, args, shared_args, emcc_args, native_args, native_exec, lib_builder, has_output_parser):
189185
self.filename = filename
190-
self.old_env = os.environ
191-
os.environ = self.env.copy()
192186
llvm_root = self.env.get('LLVM') or config.LLVM_ROOT
193187
if lib_builder:
194188
env_init = self.env.copy()
@@ -240,10 +234,6 @@ def get_output_files(self):
240234
ret.append(self.filename[:-3] + '.wasm')
241235
return ret
242236

243-
def cleanup(self):
244-
os.environ = self.old_env
245-
building.clear()
246-
247237

248238
class EmscriptenWasm2CBenchmarker(EmscriptenBenchmarker):
249239
def __init__(self, name):
@@ -351,9 +341,6 @@ def run(self, args):
351341
def get_output_files(self):
352342
return [self.filename, self.filename.replace('.js', '.wasm')]
353343

354-
def cleanup(self):
355-
pass
356-
357344

358345
# Benchmarkers
359346

@@ -476,7 +463,6 @@ def do_benchmark(self, name, src, expected_output='FAIL', args=[],
476463
b.build(self, filename, args, shared_args, emcc_args, native_args, native_exec, lib_builder, has_output_parser=output_parser is not None)
477464
b.bench(args, output_parser, reps, expected_output)
478465
b.display(baseline)
479-
b.cleanup()
480466

481467
def test_primes(self, check=True):
482468
src = r'''

tools/building.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
EXPECTED_BINARYEN_VERSION = 105
4343
# cache results of nm - it can be slow to run
4444
nm_cache = {}
45-
# Stores the object files contained in different archive files passed as input
46-
ar_contents = {}
4745
_is_ar_cache = {}
4846
# the exports the user requested
4947
user_requested_exports = set()
@@ -122,15 +120,6 @@ def check(value):
122120
return [v for v in values if check(v)]
123121

124122

125-
# clear caches. this is not normally needed, except if the clang/LLVM
126-
# used changes inside this invocation of Building, which can happen in the benchmarker
127-
# when it compares different builds.
128-
def clear():
129-
nm_cache.clear()
130-
ar_contents.clear()
131-
_is_ar_cache.clear()
132-
133-
134123
# .. but for Popen, we cannot have doublequotes, so provide functionality to
135124
# remove them when needed.
136125
def remove_quotes(arg):
@@ -208,6 +197,8 @@ def read_link_inputs(files):
208197
# each of them provides. Do this in multiple parallel processes.
209198
archive_names = [] # .a files passed in to the command line to the link
210199
object_names = [] # .o/.bc files passed in to the command line to the link
200+
# Stores the object files contained in different archive files passed as input
201+
ar_contents = {}
211202
for f in files:
212203
absolute_path_f = make_paths_absolute(f)
213204

@@ -228,6 +219,7 @@ def read_link_inputs(files):
228219
# Next, extract symbols from all object files (either standalone or inside archives we just extracted)
229220
# The results are not used here directly, but populated to llvm-nm cache structure.
230221
llvm_nm_multiple(object_names)
222+
return ar_contents
231223

232224

233225
def llvm_backend_args():
@@ -443,6 +435,8 @@ def consider_object(f, force_add=False):
443435
files_to_link.append(f)
444436
return do_add
445437

438+
ar_contents = read_link_inputs(input_files)
439+
446440
# Traverse a single archive. The object files are repeatedly scanned for
447441
# newly satisfied symbols until no new symbols are found. Returns true if
448442
# any object files were added to the link.
@@ -465,8 +459,6 @@ def consider_archive(f, force_add):
465459
logger.debug('done running loop of archive %s' % (f))
466460
return added_any_objects
467461

468-
read_link_inputs(input_files)
469-
470462
# Rescan a group of archives until we don't find any more objects to link.
471463
def scan_archive_group(group):
472464
loop_again = True

0 commit comments

Comments
 (0)