Skip to content

Commit

Permalink
Revise how EMCC_STRICT and -s STRICT=1 are read so that they are alwa…
Browse files Browse the repository at this point in the history
…ys visible.
  • Loading branch information
juj committed Dec 7, 2016
1 parent 12d47b0 commit 815a35b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 28 deletions.
28 changes: 27 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def filter_emscripten_options(argv):
if not use_js:
cmd += shared.EMSDK_OPTS + ['-D__EMSCRIPTEN__']
# The preprocessor define EMSCRIPTEN is deprecated. Don't pass it to code in strict mode. Code should use the define __EMSCRIPTEN__ instead.
if not shared.is_emscripten_strict(): cmd += ['-DEMSCRIPTEN']
if not shared.Settings.STRICT:
cmd += ['-DEMSCRIPTEN']
if use_js: cmd += ['-s', 'ERROR_ON_UNDEFINED_SYMBOLS=1'] # configure tests should fail when an undefined symbol exists

logging.debug('just configuring: ' + ' '.join(cmd))
Expand Down Expand Up @@ -921,6 +922,22 @@ def detect_fixed_language_mode(args):
if separate_asm:
shared.Settings.SEPARATE_ASM = os.path.basename(asm_target)

if 'EMCC_STRICT' in os.environ:
shared.Settings.STRICT = int(os.environ.get('EMCC_STRICT'))

STRICT = ([None] + filter(lambda x: x.startswith('STRICT='), settings_changes))[-1]
if STRICT:
shared.Settings.STRICT = int(STRICT[len('STRICT='):])

if shared.Settings.STRICT:
shared.Settings.ERROR_ON_UNDEFINED_SYMBOLS = 1
shared.Settings.ERROR_ON_MISSING_LIBRARIES = 1

# Libraries are searched before settings_changes are applied, so pull its value from the command line already here.
ERROR_ON_MISSING_LIBRARIES = ([None] + filter(lambda x: x.startswith('ERROR_ON_MISSING_LIBRARIES='), settings_changes))[-1]
if ERROR_ON_MISSING_LIBRARIES:
shared.Settings.ERROR_ON_MISSING_LIBRARIES = int(ERROR_ON_MISSING_LIBRARIES[len('ERROR_ON_MISSING_LIBRARIES='):])

system_js_libraries = []

# Find library files
Expand Down Expand Up @@ -1009,6 +1026,15 @@ def check(input_file):
if shared.get_llvm_target() == shared.WASM_TARGET:
shared.Settings.WASM_BACKEND = 1

if not shared.Settings.STRICT:
# The preprocessor define EMSCRIPTEN is deprecated. Don't pass it to code in strict mode. Code should use the define __EMSCRIPTEN__ instead.
shared.COMPILER_OPTS += ['-DEMSCRIPTEN']

# The system include path system/include/emscripten/ is deprecated, i.e. instead of #include <emscripten.h>, one should pass in #include <emscripten/emscripten.h>.
# This path is not available in Emscripten strict mode.
if shared.USE_EMSDK:
shared.C_INCLUDE_PATHS += [shared.path_from_root('system', 'include', 'emscripten')]

# Use settings

try:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7040,3 +7040,24 @@ def test_check_engine(self):
except SystemExit as e:
caught_exit = e.code
self.assertEqual(1, caught_exit, 'Did not catch SystemExit with bogus JS engine')

def test_error_on_missing_libraries(self):
env = os.environ.copy()
if 'EMCC_STRICT' in env: del env['EMCC_STRICT']

process = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-lsomenonexistingfile', '-s', 'STRICT=1'], stdout=PIPE, stderr=PIPE, env=env)
process.communicate()
assert process.returncode is not 0, '-llsomenonexistingfile is an error in strict mode'

process = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-lsomenonexistingfile', '-s', 'ERROR_ON_MISSING_LIBRARIES=0'], stdout=PIPE, stderr=PIPE, env=env)
process.communicate()
assert process.returncode is 0, '-llsomenonexistingfile is not an error if -s ERROR_ON_MISSING_LIBRARIES=0 is passed'

process = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-lsomenonexistingfile', '-s', 'STRICT=1', '-s', 'ERROR_ON_MISSING_LIBRARIES=0'], stdout=PIPE, stderr=PIPE, env=env)
process.communicate()
assert process.returncode is 0, '-s ERROR_ON_MISSING_LIBRARIES=0 should override -s STRICT=1'

process = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-lsomenonexistingfile', '-s', 'STRICT=0'], stdout=PIPE, stderr=PIPE, env=env)
process.communicate()
# TODO: TEMPORARY: When -s ERROR_ON_MISSING_LIBRARIES=1 becomes the default, change the following line to expect failure instead of 0.
assert process.returncode is 0, '-llsomenonexistingfile is not yet an error in non-strict mode'
28 changes: 1 addition & 27 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,6 @@ def find_temp_directory():
def get_emscripten_version(path):
return open(path).read().strip().replace('"', '')

# Returns true if Emscripten is running in 'strict' mode, in which deprecated compiler features are not supported.
def is_emscripten_strict():
if os.environ.get('EMCC_STRICT') and int(os.environ.get('EMCC_STRICT')) != 0: return True
try:
return Settings.STRICT
except:
pass
return False

# Check that basic stuff we need (a JS engine to compile, Node.js, and Clang and LLVM)
# exists.
# The test runner always does this check (through |force|). emcc does this less frequently,
Expand Down Expand Up @@ -941,9 +932,6 @@ def get_llvm_target():
'-D__unix',
'-D__unix__']

# The preprocessor define EMSCRIPTEN is deprecated. Don't pass it to code in strict mode. Code should use the define __EMSCRIPTEN__ instead.
if not is_emscripten_strict(): COMPILER_OPTS += ['-DEMSCRIPTEN']

# Changes to default clang behavior

# Implicit functions can cause horribly confusing function pointer type errors, see #2175
Expand All @@ -967,11 +955,6 @@ def get_llvm_target():
path_from_root('system', 'local', 'include')
]

# The system include path system/include/emscripten/ is deprecated, i.e. instead of #include <emscripten.h>, one should pass in #include <emscripten/emscripten.h>.
# This path is not available in Emscripten strict mode.
if not is_emscripten_strict():
C_INCLUDE_PATHS += [path_from_root('system', 'include', 'emscripten')]

CXX_INCLUDE_PATHS = [
path_from_root('system', 'include', 'libcxx'),
path_from_root('system', 'lib', 'libcxxabi', 'include')
Expand Down Expand Up @@ -1111,13 +1094,6 @@ def load(self, args=[]):
settings = re.sub(r'var ([\w\d]+)', r'self.attrs["\1"]', settings)
exec settings

# Apply default values for settings that are configured from environment variables.
if is_emscripten_strict():
# Specify default values for Emscripten strict mode.
self.attrs['STRICT'] = 1
self.attrs['ERROR_ON_UNDEFINED_SYMBOLS'] = 1
self.attrs['ERROR_ON_MISSING_LIBRARIES'] = 1

# Apply additional settings. First -O, then -s
for i in range(len(args)):
if args[i].startswith('-O'):
Expand Down Expand Up @@ -2033,9 +2009,7 @@ def path_to_system_js_libraries(library_name):
elif library_name.endswith('.js') and os.path.isfile(shared.path_from_root('src', 'library_' + library_name)):
library_files += ['library_' + library_name]
else:
emscripten_strict_mode = shared.is_emscripten_strict() or 'STRICT=1' in settings_changes
error_on_missing_libraries = (emscripten_strict_mode and not 'ERROR_ON_MISSING_LIBRARIES=0' in settings_changes) or 'ERROR_ON_MISSING_LIBRARIES=1' in settings_changes
if error_on_missing_libraries:
if Settings.ERROR_ON_MISSING_LIBRARIES:
logging.fatal('emcc: cannot find library "%s"', library_name)
exit(1)
else:
Expand Down

0 comments on commit 815a35b

Please sign in to comment.