Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -15183,7 +15183,8 @@ def test_empath_split(self):
''')

self.run_process([EMCC, 'main.cpp', 'foo.cpp', '-gsource-map', '-g2', '-o', 'test.js'])
self.run_process([empath_split, 'test.wasm', 'path_list.txt', '-g', '-o', 'test_primary.wasm', '--out-prefix=test_'])
empath_split_cmd = [empath_split, 'test.wasm', 'path_list.txt', '-g', '-o', 'test_primary.wasm', '--out-prefix=test_', '-v']
out = self.run_process(empath_split_cmd, stdout=PIPE).stdout

# Check if functions are correctly assigned and split with the specified
# paths. When one path contains another, the inner path should take its
Expand All @@ -15207,6 +15208,18 @@ def has_defined_function(file, func):
self.assertTrue(has_defined_function('test_lib2.wasm', r'std::__2::ios_base::getloc\\28\\29\\20const'))
self.assertTrue(has_defined_function('test_lib2.wasm', r'std::uncaught_exceptions\\28\\29'))

# When --preserve-manifest is NOT given, the files should be deleted
match = re.search(r'wasm-split(?:\.exe)?\s+.*--manifest\s+(\S+)', out)
manifest = match.group(1)
self.assertNotExists(manifest)

# When --preserve-manifest is given, the files should be preserved
out = self.run_process(empath_split_cmd + ['--preserve-manifest'], stdout=PIPE, stderr=subprocess.DEVNULL).stdout
match = re.search(r'wasm-split(?:\.exe)?\s+.*--manifest\s+(\S+)', out)
manifest = match.group(1)
self.assertExists(manifest)
delete_file(manifest)

# Check --print-sources option
out = self.run_process([empath_split, 'test.wasm', '--print-sources'], stdout=PIPE).stdout
self.assertIn('main.cpp', out)
Expand Down
10 changes: 7 additions & 3 deletions tools/empath-split.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,9 @@ def main():
path_to_funcs = get_path_to_functions_map(args.wasm, sourcemap, all_paths)

# Write .manifest file
with tempfile.NamedTemporaryFile(suffix=".manifest", mode='w+', delete=args.preserve_manifest) as f:
manifest = f.name
f = tempfile.NamedTemporaryFile(suffix=".manifest", mode='w+', delete=False)
manifest = f.name
try:
for i, (module, paths) in enumerate(module_to_paths.items()):
if i != 0: # Unless we are the first entry add a newline separator
f.write('\n')
Expand All @@ -339,7 +340,7 @@ def main():
f.write(f'{module}\n')
for func in funcs:
f.write(func + '\n')
f.flush()
f.close()

cmd = [args.wasm_split, '--multi-split', args.wasm, '--manifest', manifest]
if args.verbose:
Expand All @@ -349,6 +350,9 @@ def main():
if args.verbose:
print('\n' + ' '.join(cmd))
shared.run_process(cmd)
finally:
if not args.preserve_manifest:
os.remove(manifest)


if __name__ == '__main__':
Expand Down