Skip to content

Commit 5024d16

Browse files
authored
Avoid stdout file in read_and_preprocess. NFC (emscripten-core#23649)
The comment here suggests there is bug with stdout streaming in python but we use `stdout=PIPE` when we run `compiler.mjs`, which tends to generate a lot more output that `preprocessor.mjs` See `compile_javascript` in `emscripten.py`.
1 parent ee4fe8a commit 5024d16

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

test/test_other.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15409,6 +15409,18 @@ def test_js_preprocess_pre_post(self):
1540915409
self.do_runf('hello_world.c', 'assertions disabled\n4', emcc_args=['-sASSERTIONS=0'])
1541015410
self.assertNotContained('#preprocess', read_file('hello_world.js'))
1541115411

15412+
@crossplatform
15413+
def test_js_preprocess_huge_file(self):
15414+
# Check that huge files can be preprocessed. We once had issues with files
15415+
# larger then 64k being sent over stdout using python's subprocess.
15416+
huge_js = '#preprocess\nfunction hugeFunc() {\n'
15417+
huge_js += 100000 * ' console.log("huge function");\n'
15418+
huge_js += '}\n'
15419+
create_file('huge.js', huge_js)
15420+
assert len(huge_js) > (1024 * 1024)
15421+
self.do_runf('hello_world.c', 'hello, world!\n', emcc_args=['--pre-js=huge.js'])
15422+
self.assertContained('function hugeFunc', read_file('hello_world.js'))
15423+
1541215424
@with_both_compilers
1541315425
def test_use_port_errors(self, compiler):
1541415426
stderr = self.expect_fail([compiler, test_file('hello_world.c'), '--use-port=invalid', '-o', 'out.js'])

tools/shared.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -720,29 +720,20 @@ def safe_copy(src, dst):
720720

721721

722722
def read_and_preprocess(filename, expand_macros=False):
723-
temp_dir = get_emscripten_temp_dir()
724723
# Create a settings file with the current settings to pass to the JS preprocessor
725-
726724
with get_temp_files().get_file('.json') as settings_file:
727725
with open(settings_file, 'w') as s:
728726
json.dump(settings.external_dict(), s, sort_keys=True, indent=2)
729727

730728
# Run the JS preprocessor
731-
# N.B. We can't use the default stdout=PIPE here as it only allows 64K of output before it hangs
732-
# and shell.html is bigger than that!
733-
# See https://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/
734729
dirname, filename = os.path.split(filename)
735730
if not dirname:
736731
dirname = None
737-
stdout = os.path.join(temp_dir, 'stdout')
738732
args = [settings_file, filename]
739733
if expand_macros:
740734
args += ['--expand-macros']
741735

742-
run_js_tool(path_from_root('tools/preprocessor.mjs'), args, stdout=open(stdout, 'w'), cwd=dirname)
743-
out = utils.read_file(stdout)
744-
745-
return out
736+
return run_js_tool(path_from_root('tools/preprocessor.mjs'), args, stdout=subprocess.PIPE, cwd=dirname)
746737

747738

748739
def do_replace(input_, pattern, replacement):

0 commit comments

Comments
 (0)