diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rwxr-xr-x | emcc | 28 | ||||
-rw-r--r-- | settings.py | 2 | ||||
-rwxr-xr-x | tests/runner.py | 24 | ||||
-rw-r--r-- | tools/file_packager.py | 21 |
5 files changed, 67 insertions, 9 deletions
@@ -36,3 +36,4 @@ a license to everyone to use it as detailed in LICENSE.) * Mokhtar Naamani <mokhtar.naamani@gmail.com> * Benjamin Stover <benjamin.stover@gmail.com> * Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> +* Janus Troelsen <janus.troelsen@stud.tu-darmstadt.de> @@ -321,6 +321,14 @@ elif len(sys.argv) == 2 and sys.argv[1] == '-v': # -v with no inputs print 'emcc (Emscripten GCC-like replacement) 2.0' exit(subprocess.call([shared.CLANG, '-v'])) +def is_minus_s_for_emcc(newargs,i): + assert newargs[i] == '-s' + if i+1 < len(newargs) and '=' in newargs[i+1]: # -s OPT=VALUE is for us, -s by itself is a linker option + return True + else: + print >> sys.stderr, 'emcc: warning: treating -s as linker option and not as -s OPT=VALUE for js compilation' + return False + # If this is a configure-type thing, do not compile to JavaScript, instead use clang # to compile to a native binary (using our headers, so things make sense later) CONFIGURE_CONFIG = os.environ.get('EMMAKEN_JUST_CONFIGURE') or 'conftest.c' in sys.argv @@ -329,7 +337,21 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG: compiler = shared.CLANG if not ('CXXCompiler' in ' '.join(sys.argv) or os.environ.get('EMMAKEN_CXX')): compiler = shared.to_cc(compiler) - cmd = [compiler] + shared.EMSDK_OPTS + ['-DEMSCRIPTEN'] + sys.argv[1:] + def filter_emscripten_options(argv): + idx = 0 + skip_next = False + for el in argv: + if skip_next: + skip_next = False + idx += 1 + continue + if el == '-s' and is_minus_s_for_emcc(argv, idx): + skip_next = True + else: + yield el + idx += 1 + + cmd = [compiler] + shared.EMSDK_OPTS + ['-DEMSCRIPTEN'] + list(filter_emscripten_options(sys.argv[1:])) if DEBUG: print >> sys.stderr, 'emcc, just configuring: ', ' '.join(cmd) exit(subprocess.call(cmd)) @@ -553,11 +575,9 @@ try: settings_changes = [] for i in range(len(newargs)): if newargs[i] == '-s': - if i+1 < len(newargs) and '=' in newargs[i+1]: # -s OPT=VALUE is for us, -s by itself is a linker option + if is_minus_s_for_emcc(newargs, i): settings_changes.append(newargs[i+1]) newargs[i] = newargs[i+1] = '' - else: - print >> sys.stderr, 'emcc: warning: treating -s as linker option and not as -s OPT=VALUE for js compilation' elif newargs[i].startswith('--typed-arrays'): assert '=' not in newargs[i], 'Invalid typed arrays parameter (do not use "=")' settings_changes.append('USE_TYPED_ARRAYS=' + newargs[i+1]) diff --git a/settings.py b/settings.py index bb749945..45a30569 100644 --- a/settings.py +++ b/settings.py @@ -2,6 +2,8 @@ # IMPORTANT: Edit the *copy* with the right paths! # Note: If you put paths relative to the home directory, do not forget os.path.expanduser +import os + # this helps projects using emscripten find it EMSCRIPTEN_ROOT = os.path.expanduser(os.getenv('EMSCRIPTEN') or '/opt/emscripten') LLVM_ROOT = os.path.expanduser(os.getenv('LLVM') or '/usr/bin') diff --git a/tests/runner.py b/tests/runner.py index 090ad3f0..49787383 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7674,6 +7674,19 @@ fscanfed: 10 - hello code = open('a.out.js').read() assert 'SAFE_HEAP' in code, 'valid -s option had an effect' + def test_conftest_s_flag_passing(self): + open(os.path.join(self.get_dir(), 'conftest.c'), 'w').write(r''' + int main() { + return 0; + } + ''') + os.environ["EMMAKEN_JUST_CONFIGURE"] = "1" + cmd = ['python', EMCC, '-s', 'ASSERTIONS=1', os.path.join(self.get_dir(), 'conftest.c'), '-o', 'conftest'] + output = Popen(cmd, stderr=PIPE).communicate() + self.assertNotContained('emcc: warning: treating -s as linker option', output[1]) + assert os.path.exists('conftest') + del os.environ["EMMAKEN_JUST_CONFIGURE"] + 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') @@ -8395,6 +8408,17 @@ elif 'browser' in str(sys.argv): shutil.move('water.dds', 'water.donotfindme.dds') # make sure we load from the compressed self.btest('s3tc_crunch.c', reference='s3tc_crunch.png', reference_slack=1, args=['--pre-js', 'pre.js']) + def test_s3tc_crunch_split(self): # load several datafiles/outputs of file packager + shutil.copyfile(path_from_root('tests', 'ship.dds'), 'ship.dds') + shutil.copyfile(path_from_root('tests', 'bloom.dds'), 'bloom.dds') + shutil.copyfile(path_from_root('tests', 'water.dds'), 'water.dds') + Popen(['python', FILE_PACKAGER, 'asset_a.data', '--pre-run', '--crunch', '--preload', 'ship.dds', 'bloom.dds'], stdout=open('asset_a.js', 'w')).communicate() + Popen(['python', FILE_PACKAGER, 'asset_b.data', '--pre-run', '--crunch', '--preload', 'water.dds'], stdout=open('asset_b.js', 'w')).communicate() + shutil.move('ship.dds', 'ship.donotfindme.dds') # make sure we load from the compressed + shutil.move('bloom.dds', 'bloom.donotfindme.dds') # make sure we load from the compressed + shutil.move('water.dds', 'water.donotfindme.dds') # make sure we load from the compressed + self.btest('s3tc_crunch.c', reference='s3tc_crunch.png', reference_slack=1, args=['--pre-js', 'asset_a.js', '--pre-js', 'asset_b.js']) + def test_aniso(self): shutil.copyfile(path_from_root('tests', 'water.dds'), 'water.dds') self.btest('aniso.c', reference='aniso.png', reference_slack=2, args=['--preload-file', 'water.dds']) diff --git a/tools/file_packager.py b/tools/file_packager.py index 7797e58c..2a39f2b1 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -25,7 +25,7 @@ TODO: You can also provide .crn files yourself, pre-crunched. With this o to dds files in the browser, exactly the same as if this tool compressed them. ''' -import os, sys, shutil +import os, sys, shutil, random from shared import Compression, execute, suffix, unsuffixed import shared @@ -97,6 +97,10 @@ for arg in sys.argv[1:]: Compression.js_name = arg in_compress = 0 +print ''' +(function() { +''' + code = ''' function assert(check, msg) { if (!check) throw msg + new Error().stack; @@ -127,6 +131,9 @@ def was_seen(name): return False data_files = filter(lambda file_: not was_seen(file_['name']), data_files) +# Randomize order, to get around silly fake antivirus positivies +random.shuffle(data_files) + # Apply plugins for file_ in data_files: for plugin in plugins: @@ -199,7 +206,7 @@ for file_ in data_files: for i in range(len(parts)): partial = '/'.join(parts[:i+1]) if partial not in partial_dirs: - code += '''Module['FS_createFolder']('/%s', '%s', true, true);\n''' % ('/'.join(parts[:i]), parts[i]) + code += '''Module['FS_createPath']('/%s', '%s', true, true);\n''' % ('/'.join(parts[:i]), parts[i]) partial_dirs.append(partial) if has_preloaded: @@ -296,7 +303,7 @@ if has_preloaded: curr.response = byteArray.subarray(%d,%d); curr.onload(); ''' % (file_['name'], file_['data_start'], file_['data_end']) - use_data += " Module['removeRunDependency']('datafile');\n" + use_data += " Module['removeRunDependency']('datafile_%s');\n" % data_target if Compression.on: use_data = ''' @@ -324,10 +331,10 @@ if has_preloaded: var curr; %s }; - Module['addRunDependency']('datafile'); + Module['addRunDependency']('datafile_%s'); dataFile.send(null); if (Module['setStatus']) Module['setStatus']('Downloading...'); - ''' % (os.path.basename(Compression.compressed_name(data_target) if Compression.on else data_target), use_data) # use basename because from the browser's point of view, we need to find the datafile in the same dir as the html file + ''' % (os.path.basename(Compression.compressed_name(data_target) if Compression.on else data_target), use_data, data_target) # use basename because from the browser's point of view, we need to find the datafile in the same dir as the html file if pre_run: print ''' @@ -349,3 +356,7 @@ if crunch: }); ''' +print ''' +})(); +''' + |