diff options
-rwxr-xr-x | emcc | 22 | ||||
-rw-r--r-- | src/library.js | 12 | ||||
-rwxr-xr-x | tests/runner.py | 30 | ||||
-rw-r--r-- | tools/file_packager.py | 11 | ||||
-rw-r--r-- | tools/shared.py | 5 |
5 files changed, 68 insertions, 12 deletions
@@ -53,6 +53,15 @@ from tools import shared, jsrun from tools.shared import Compression, execute, suffix, unsuffixed, unsuffixed_basename from tools.response_file import read_response_file +CXX_SUFFIXES = ('.cpp', '.cxx', '.cc') +SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx', '.cc', '.m', '.mm') +BITCODE_SUFFIXES = ('.bc', '.o', '.obj') +DYNAMICLIB_SUFFIXES = ('.dylib', '.so', '.dll') +STATICLIB_SUFFIXES = ('.a',) +ASSEMBLY_SUFFIXES = ('.ll',) +LIB_PREFIXES = ('', 'lib') +JS_CONTAINING_SUFFIXES = ('js', 'html') + # Mapping of emcc opt levels to llvm opt levels. We use llvm opt level 3 in emcc opt # levels 2 and 3 (emcc 3 is unsafe opts, so unsuitable for the only level to get # llvm opt level 3, and speed-wise emcc level 2 is already the slowest/most optimizing @@ -532,7 +541,7 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG: if debug_configure: open(tempout, 'a').write('============= ' + arg + '\n' + src + '\n=============\n\n') except: pass - if arg.endswith('.s'): + elif arg.endswith('.s'): if debug_configure: open(tempout, 'a').write('(compiling .s assembly, must use clang\n') use_js = 0 @@ -615,15 +624,6 @@ if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += shlex.split(EMMAKEN_CFLAGS) # ---------------- Utilities --------------- -SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx', '.cc', '.m', '.mm') -BITCODE_SUFFIXES = ('.bc', '.o', '.obj') -DYNAMICLIB_SUFFIXES = ('.dylib', '.so', '.dll') -STATICLIB_SUFFIXES = ('.a',) -ASSEMBLY_SUFFIXES = ('.ll',) -LIB_PREFIXES = ('', 'lib') - -JS_CONTAINING_SUFFIXES = ('js', 'html') - seen_names = {} def uniquename(name): if name not in seen_names: @@ -1105,6 +1105,8 @@ try: output_file = in_temp(unsuffixed(uniquename(input_file)) + '.o') temp_files.append(output_file) args = newargs + ['-emit-llvm', '-c', input_file, '-o', output_file] + if input_file.endswith(CXX_SUFFIXES): + args += shared.EMSDK_CXX_OPTS logging.debug("running:" + call + ' ' + ' '.join(args)) execute([call] + args) # let compiler frontend print directly, so colors are saved (PIPE kills that) if not os.path.exists(output_file): diff --git a/src/library.js b/src/library.js index 6613335b..68addfdc 100644 --- a/src/library.js +++ b/src/library.js @@ -4930,7 +4930,17 @@ LibraryManager.library = { (chr >= {{{ charCode('{') }}} && chr <= {{{ charCode('~') }}}); }, isspace: function(chr) { - return chr in { 32: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0 }; + switch(chr) { + case 32: + case 9: + case 10: + case 11: + case 12: + case 13: + return true; + default: + return false; + }; }, isblank: function(chr) { return chr == {{{ charCode(' ') }}} || chr == {{{ charCode('\t') }}}; diff --git a/tests/runner.py b/tests/runner.py index 5eaf13dd..55d666e9 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -12165,6 +12165,36 @@ seeked= file. self.assertNotContained('emcc: warning: treating -s as linker option', output[1]) assert os.path.exists('conftest') + def test_file_packager(self): + try: + os.mkdir('subdir') + except: + pass + open('data1.txt', 'w').write('data1') + os.chdir('subdir') + open('data2.txt', 'w').write('data2') + # relative path to below the current dir is invalid + out, err = Popen([PYTHON, FILE_PACKAGER, 'test.data', '--preload', '../data1.txt'], stdout=PIPE, stderr=PIPE).communicate() + assert len(out) == 0 + assert 'below the current directory' in err + # relative path that ends up under us is cool + out, err = Popen([PYTHON, FILE_PACKAGER, 'test.data', '--preload', '../subdir/data2.txt'], stdout=PIPE, stderr=PIPE).communicate() + assert len(out) > 0 + assert 'below the current directory' not in err + # direct path leads to the same code being generated - relative path does not make us do anything different + out2, err2 = Popen([PYTHON, FILE_PACKAGER, 'test.data', '--preload', 'data2.txt'], stdout=PIPE, stderr=PIPE).communicate() + assert len(out2) > 0 + assert 'below the current directory' not in err2 + def clean(txt): + return filter(lambda line: 'PACKAGE_UUID' not in line, txt.split('\n')) + out = clean(out) + out2 = clean(out2) + assert out == out2 + # sanity check that we do generate different code for different inputs + out3, err3 = Popen([PYTHON, FILE_PACKAGER, 'test.data', '--preload', 'data2.txt', 'data2.txt@waka.txt'], stdout=PIPE, stderr=PIPE).communicate() + out3 = clean(out3) + assert out != out3 + def test_crunch(self): # crunch should not be run if a .crn exists that is more recent than the .dds shutil.copyfile(path_from_root('tests', 'ship.dds'), 'ship.dds') diff --git a/tools/file_packager.py b/tools/file_packager.py index 575e5957..0fa6a529 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -198,6 +198,17 @@ for file_ in data_files: os.path.walk(file_['srcpath'], add, [file_['mode'], file_['srcpath'], file_['dstpath']]) data_files = filter(lambda file_: not os.path.isdir(file_['srcpath']), data_files) +# Absolutize paths, and check that they make sense +curr_abspath = os.path.abspath(os.getcwd()) +for file_ in data_files: + path = file_['dstpath'] + abspath = os.path.abspath(path) + print >> sys.stderr, path, abspath, curr_abspath + if not abspath.startswith(curr_abspath): + print >> sys.stderr, 'Error: Embedding "%s" which is below the current directory. This is invalid since the current directory becomes the root that the generated code will see' % path + sys.exit(1) + file_['dstpath'] = abspath[len(curr_abspath)+1:] + for file_ in data_files: file_['dstpath'] = file_['dstpath'].replace(os.path.sep, '/') # name in the filesystem, native and emulated if file_['dstpath'].endswith('/'): # If user has submitted a directory name as the destination but omitted the destination filename, use the filename from source file diff --git a/tools/shared.py b/tools/shared.py index 007c2ee8..5c19efa8 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -509,6 +509,7 @@ COMPILER_OPTS = COMPILER_OPTS + ['-m32', '-U__i386__', '-U__i386', '-Ui386', '-target', LLVM_TARGET] if LLVM_TARGET == 'le32-unknown-nacl': + COMPILER_OPTS = filter(lambda opt: opt != '-m32', COMPILER_OPTS) # le32 target is 32-bit anyhow, no need for -m32 COMPILER_OPTS += ['-U__native_client__', '-U__pnacl__', '-U__ELF__'] # The nacl target is originally used for Google Native Client. Emscripten is not NaCl, so remove the platform #define, when using their triple. USE_EMSDK = not os.environ.get('EMMAKEN_NO_SDK') @@ -516,7 +517,7 @@ USE_EMSDK = not os.environ.get('EMMAKEN_NO_SDK') if USE_EMSDK: # Disable system C and C++ include directories, and add our own (using -idirafter so they are last, like system dirs, which # allows projects to override them) - EMSDK_OPTS = ['-nostdinc', '-nostdinc++', '-Xclang', '-nobuiltininc', '-Xclang', '-nostdsysteminc', + EMSDK_OPTS = ['-nostdinc', '-Xclang', '-nobuiltininc', '-Xclang', '-nostdsysteminc', '-Xclang', '-isystem' + path_from_root('system', 'local', 'include'), '-Xclang', '-isystem' + path_from_root('system', 'include', 'libcxx'), '-Xclang', '-isystem' + path_from_root('system', 'include'), @@ -529,9 +530,11 @@ if USE_EMSDK: ] + [ '-U__APPLE__', '-U__linux__' ] + EMSDK_CXX_OPTS = ['-nostdinc++'] COMPILER_OPTS += EMSDK_OPTS else: EMSDK_OPTS = [] + EMSDK_CXX_OPTS = [] #print >> sys.stderr, 'SDK opts', ' '.join(EMSDK_OPTS) #print >> sys.stderr, 'Compiler opts', ' '.join(COMPILER_OPTS) |