Skip to content
Merged
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
50 changes: 32 additions & 18 deletions test/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ def make_fake_clang(filename, version, targets='wasm32 - WebAssembly 32-bit'):
make_fake_tool(filename + '++', version, output)


# Return a new PATH that has no directories that would contain the given tool.
def path_without_tool(env_path, tool_bin):
tool_bin = utils.exe_suffix(tool_bin)
python_path = os.path.normpath(os.path.dirname(sys.executable))

def ignore_path(p):
# We cannot ignore a path element that contains the python executable itself, otherwise
# the bootstrap script will fail
if os.path.isfile(os.path.join(p, tool_bin)) and os.path.normpath(p) != python_path:
return True
return False

old_path = env_path.split(os.pathsep)
return os.pathsep.join([d for d in old_path if not ignore_path(d)])


SANITY_MESSAGE = 'Emscripten: Running sanity checks'

# arguments to build a minimal hello world program, without even libc
Expand Down Expand Up @@ -153,7 +169,7 @@ def do(self, command, env=None):

return self.run_process(command, stdout=PIPE, stderr=STDOUT, check=False, env=env).stdout

def check_working(self, command, expected=None):
def check_working(self, command, expected=None, env=None):
if type(command) is not list:
command = [command]
if command == [EMCC]:
Expand All @@ -164,7 +180,7 @@ def check_working(self, command, expected=None):
else:
expected = 'could not find the following tests: blahblah'

output = self.do(command)
output = self.do(command, env=env)
self.assertContained(expected, output)
return output

Expand All @@ -178,8 +194,13 @@ def test_aaa_normal(self):

@with_env_modify({'EM_CONFIG': None})
def test_firstrun(self):
# Remove from PATH every directory that contains clang.exe so config setup
# cannot accidentally succeed by virtue of locating tools in PATH.
env = os.environ.copy()
env['PATH'] = path_without_tool(env['PATH'], 'clang')

default_config = path_from_root('.emscripten')
output = self.do([EMCC, '-v'])
output = self.do([EMCC, '-v'], env=env)
self.assertContained('emcc: warning: config file not found: %s. You can create one by hand or run `emcc --generate-config`' % default_config, output)

temp_bin = os.path.abspath('bin')
Expand Down Expand Up @@ -688,11 +709,16 @@ def test_required_config_settings(self):
# with no binaryen root, an error is shown
restore_and_set_up()

# Remove wasm-opt from PATH so config setup cannot accidentally succeed by
# virtue of locating it in PATH.
env = os.environ.copy()
env['PATH'] = path_without_tool(env['PATH'], 'wasm-opt')

open(EM_CONFIG, 'a').write('\nBINARYEN_ROOT = ""\n')
self.check_working([EMCC, test_file('hello_world.c')], 'BINARYEN_ROOT is set to empty value in %s' % EM_CONFIG)
self.check_working([EMCC, test_file('hello_world.c')], 'BINARYEN_ROOT is set to empty value in %s' % EM_CONFIG, env=env)

open(EM_CONFIG, 'a').write('\ndel BINARYEN_ROOT\n')
self.check_working([EMCC, test_file('hello_world.c')], 'BINARYEN_ROOT not set in config (%s), and `wasm-opt` not found in PATH' % EM_CONFIG)
self.check_working([EMCC, test_file('hello_world.c')], 'BINARYEN_ROOT not set in config (%s), and `wasm-opt` not found in PATH' % EM_CONFIG, env=env)

@no_windows('Test relies on Unix-specific make_fake_tool')
def test_empty_config(self):
Expand Down Expand Up @@ -830,21 +856,9 @@ def test_bootstrap_without_em_config(self):
for e in ['LLVM_ROOT', 'EMSDK_NODE', 'EMSDK_PYTHON', 'EMSDK', 'EMSCRIPTEN', 'BINARYEN_ROOT', 'EMCC_SKIP_SANITY_CHECK', 'EM_CONFIG']:
env.pop(e, None)

python_path = os.path.normpath(os.path.dirname(sys.executable))

# Remove from PATH every directory that contains clang.exe so that bootstrap.py cannot
# accidentally succeed by virtue of locating tools in PATH.
def ignore_path(p):
clang_bin = utils.exe_suffix('clang')
# We cannot ignore a path element that contains the python executable itself, otherwise
# the bootstrap script will fail
if os.path.isfile(os.path.join(p, clang_bin)) and os.path.normpath(p) != python_path:
return True
return False

old_path = env['PATH'].split(os.pathsep)
new_path = [d for d in old_path if not ignore_path(d)]
env['PATH'] = os.pathsep.join(new_path)
env['PATH'] = path_without_tool(env['PATH'], 'clang')

# Running bootstrap.py should not fail
self.run_process([shared.bat_suffix(path_from_root('bootstrap'))], env=env)