Skip to content

Commit 1644c92

Browse files
authored
Fix wat2wasm -o - for writing to stdout. NFC (#2638)
Fixes: #2637
1 parent c5f3b04 commit 1644c92

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/option-parser.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ void OptionParser::Parse(int argc, char* argv[]) {
208208
arg[best_length + 2] == '=') { // +2 to skip "--".
209209
option_argument = &arg[best_length + 3];
210210
} else {
211-
if (i + 1 == argc || argv[i + 1][0] == '-') {
211+
if (i + 1 == argc ||
212+
(argv[i + 1][0] == '-' && strlen(argv[i + 1]) > 1)) {
212213
Errorf("option '--%s' requires argument",
213214
best_option.long_name.c_str());
214215
continue;
@@ -240,7 +241,8 @@ void OptionParser::Parse(int argc, char* argv[]) {
240241
break;
241242
}
242243

243-
if (i + 1 == argc || argv[i + 1][0] == '-') {
244+
if (i + 1 == argc ||
245+
(argv[i + 1][0] == '-' && strlen(argv[i + 1]) > 1)) {
244246
Errorf("option '-%c' requires argument", option.short_name);
245247
break;
246248
}

test/run-tests.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ def Run(self, cwd, timeout, console_out=False, env=None):
265265
process = None
266266
is_timeout = Cell(False)
267267

268+
cmd = self.args
269+
stdout_filename = None
270+
# Hacky support for stdout redirection `cmd > output`
271+
if len(cmd) > 2 and cmd[-2] == '>':
272+
stdout_filename = os.path.join(cwd, cmd[-1])
273+
cmd = cmd[:-2]
274+
268275
def KillProcess(timeout=True):
269276
if process:
270277
try:
@@ -289,7 +296,7 @@ def KillProcess(timeout=True):
289296

290297
# http://stackoverflow.com/a/10012262: subprocess with a timeout
291298
# http://stackoverflow.com/a/22582602: kill subprocess and children
292-
process = subprocess.Popen(self.args, cwd=cwd, env=env,
299+
process = subprocess.Popen(cmd, cwd=cwd, env=env,
293300
stdout=None if console_out else subprocess.PIPE,
294301
stderr=None if console_out else subprocess.PIPE,
295302
stdin=None if not self.stdin else subprocess.PIPE,
@@ -310,6 +317,10 @@ def KillProcess(timeout=True):
310317
finally:
311318
KillProcess(False)
312319

320+
if stdout_filename:
321+
open(stdout_filename, 'wb').write(stdout)
322+
stdout = None
323+
313324
return RunResult(self, stdout, stderr, returncode, duration)
314325

315326
def __str__(self):

test/wat2wasm_stdout.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
;;; TOOL: wat2wasm
2+
;;; ARGS: -o - > %(temp_file)s_tmp.wasm
3+
;;; RUN: %(wasm2wat)s %(temp_file)s_tmp.wasm
4+
(module
5+
(func)
6+
)
7+
(;; STDOUT ;;;
8+
(module
9+
(type (;0;) (func))
10+
(func (;0;) (type 0)))
11+
;;; STDOUT ;;)

0 commit comments

Comments
 (0)