Skip to content

Commit

Permalink
Show a clear error on -o pointing to an invalid directory. fixes emsc…
Browse files Browse the repository at this point in the history
…ripten-core#8549 (emscripten-core#8551)

Without this, Python will give an error "no such file" when we try to write to that file, which can be confusing. Worse, this will happen on the first file we try to write to, which may be one of the helper files (.wasm, .mem, etc.), which is even more confusing.
  • Loading branch information
kripken authored and VirtualTim committed May 21, 2019
1 parent cd4f62e commit 5d7247b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,13 @@ def uniquename(name):
# specified_target is the user-specified one, target is what we will generate
if specified_target:
target = specified_target
# check for the existence of the output directory now, to avoid having
# to do so repeatedly when each of the various output files (.mem, .wasm,
# etc) are written. This gives a more useful error message than the
# IOError and python backtrace that users would otherwise see.
dirname = os.path.dirname(target)
if dirname and not os.path.isdir(dirname):
exit_with_error("specified output file (%s) is in a directory that does not exist" % target)
else:
target = 'a.out.js'

Expand Down
4 changes: 4 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7847,6 +7847,10 @@ def test_invalid_mem(self):
ret = self.expect_fail([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'WASM_MEM_MAX=33MB+1'])
self.assertContained('WASM_MEM_MAX must be a multiple of 64KB', ret)

def test_invalid_output_dir(self):
ret = self.expect_fail([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-o', os.path.join('NONEXISTING_DIRECTORY', 'out.js')])
self.assertContained('specified output file (NONEXISTING_DIRECTORY%sout.js) is in a directory that does not exist' % os.path.sep, ret)

@unittest.skipIf(SPIDERMONKEY_ENGINE not in JS_ENGINES, 'cannot run without spidermonkey')
def test_binaryen_ctors(self):
# ctor order must be identical to js builds, deterministically
Expand Down

0 comments on commit 5d7247b

Please sign in to comment.