diff options
-rwxr-xr-x | em++ | 4 | ||||
-rwxr-xr-x | emar | 4 | ||||
-rwxr-xr-x | emcc | 6 | ||||
-rwxr-xr-x | emld | 4 | ||||
-rw-r--r-- | src/compiler.js | 7 | ||||
-rw-r--r-- | src/shell.js | 7 | ||||
-rw-r--r-- | system/lib/libcxx/Makefile | 2 | ||||
-rwxr-xr-x | tests/runner.py | 59 | ||||
-rw-r--r-- | tools/eliminator/eliminator.coffee | 5 | ||||
-rwxr-xr-x | tools/emmaken.py | 4 | ||||
-rwxr-xr-x | tools/emmakenxx.py | 4 | ||||
-rw-r--r-- | tools/js-optimizer.js | 12 | ||||
-rw-r--r-- | tools/make_minigzip.py | 2 | ||||
-rw-r--r-- | tools/shared.py | 30 |
14 files changed, 86 insertions, 64 deletions
@@ -4,9 +4,9 @@ See emcc.py. This script forwards to there, noting that we want C++ and not C by default ''' -import os, sys +import os, subprocess, sys from tools import shared os.environ['EMMAKEN_CXX'] = '1' -exit(os.execvp(shared.EMCC, [shared.EMCC] + sys.argv[1:])) +exit(subprocess.call(['python', shared.EMCC] + sys.argv[1:])) @@ -7,7 +7,7 @@ emar - ar helper script This script acts as a frontend replacement for ar. See emcc. ''' -import os, sys +import os, subprocess, sys from tools import shared DEBUG = os.environ.get('EMCC_DEBUG') @@ -18,5 +18,5 @@ if DEBUG: print >> sys.stderr, 'emar:', sys.argv, ' ==> ', newargs if len(newargs) > 2: - os.execvp(shared.LLVM_AR, newargs) + subprocess.call(newargs) @@ -287,7 +287,7 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG: compiler = shared.to_cc(compiler) cmd = [compiler] + shared.EMSDK_OPTS + ['-DEMSCRIPTEN'] + sys.argv[1:] if DEBUG: print >> sys.stderr, 'emcc, just configuring: ', ' '.join(cmd) - exit(os.execvp(compiler, cmd)) + exit(subprocess.call(cmd)) if os.environ.get('EMMAKEN_COMPILER'): CXX = os.environ['EMMAKEN_COMPILER'] @@ -671,9 +671,9 @@ try: # dlmalloc def create_dlmalloc(): if DEBUG: print >> sys.stderr, 'emcc: building dlmalloc for cache' - execute([shared.EMCC, shared.path_from_root('system', 'lib', 'dlmalloc.c'), '-g', '-o', in_temp('dlmalloc.o')], stdout=stdout, stderr=stderr) + execute(['python', shared.EMCC, shared.path_from_root('system', 'lib', 'dlmalloc.c'), '-g', '-o', in_temp('dlmalloc.o')], stdout=stdout, stderr=stderr) # we include the libc++ new stuff here, so that the common case of using just new/delete is quick to link - execute([shared.EMXX, shared.path_from_root('system', 'lib', 'libcxx', 'new.cpp'), '-g', '-o', in_temp('new.o')], stdout=stdout, stderr=stderr) + execute(['python', shared.EMXX, shared.path_from_root('system', 'lib', 'libcxx', 'new.cpp'), '-g', '-o', in_temp('new.o')], stdout=stdout, stderr=stderr) shared.Building.link([in_temp('dlmalloc.o'), in_temp('new.o')], in_temp('dlmalloc_full.o')) return in_temp('dlmalloc_full.o') def fix_dlmalloc(): @@ -9,7 +9,7 @@ This script acts as a frontend replacement for the ld linker. See emcc. We could use the compiler code for this, but here we want to be careful to use all the linker flags we have been passed, sending them to ld. ''' -import os, sys +import os, subprocess, sys from tools import shared DEBUG = os.environ.get('EMCC_DEBUG') @@ -56,5 +56,5 @@ if target: newargs.append('-o=' + actual_target) if DEBUG: print >> sys.stderr, "emld running:", call, ' '.join(newargs) -os.execvp(call, [call] + newargs) +subprocess.call([call] + newargs) diff --git a/src/compiler.js b/src/compiler.js index c39927e7..29ae47dd 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -29,11 +29,14 @@ if (ENVIRONMENT_IS_NODE) { }; var nodeFS = require('fs'); + var nodePath = require('path'); read = function(filename) { + filename = nodePath['normalize'](filename); var ret = nodeFS['readFileSync'](filename).toString(); - if (!ret && filename[0] != '/') { - filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename; + // The path is absolute if the normalized version is the same as the resolved. + if (!ret && filename != nodePath['resolve'](filename)) { + filename = path.join(__dirname, '..', 'src', filename); ret = nodeFS['readFileSync'](filename).toString(); } return ret; diff --git a/src/shell.js b/src/shell.js index 5b6419c0..55f96194 100644 --- a/src/shell.js +++ b/src/shell.js @@ -24,11 +24,14 @@ if (ENVIRONMENT_IS_NODE) { }; var nodeFS = require('fs'); + var nodePath = require('path'); Module['read'] = function(filename) { + filename = nodePath['normalize'](filename); var ret = nodeFS['readFileSync'](filename).toString(); - if (!ret && filename[0] != '/') { - filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename; + // The path is absolute if the normalized version is the same as the resolved. + if (!ret && filename != nodePath['resolve'](filename)) { + filename = path.join(__dirname, '..', 'src', filename); ret = nodeFS['readFileSync'](filename).toString(); } return ret; diff --git a/system/lib/libcxx/Makefile b/system/lib/libcxx/Makefile index 01d8dbf3..98a5974d 100644 --- a/system/lib/libcxx/Makefile +++ b/system/lib/libcxx/Makefile @@ -1,5 +1,4 @@ OBJECTS = \ - locale.bc \ algorithm.bc \ condition_variable.bc \ future.bc \ @@ -20,6 +19,7 @@ OBJECTS = \ chrono.bc \ exception.bc \ ios.bc \ + locale.bc \ regex.bc \ strstream.bc \ typeinfo.bc diff --git a/tests/runner.py b/tests/runner.py index 9dc7ab32..99372553 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -63,6 +63,8 @@ class RunnerCore(unittest.TestCase): shutil.copy(os.path.join(self.get_dir(), name), os.path.join(TEMP_DIR, self.id().replace('__main__.', '').replace('.test_', '.')+'.'+suff)) if not self.save_dir: + # rmtree() fails on Windows if the current working directory is inside the tree. + os.chdir(os.path.join(self.get_dir(), '..')) shutil.rmtree(self.get_dir()) def skip(self, why): @@ -135,7 +137,7 @@ class RunnerCore(unittest.TestCase): transform = open(transform_filename, 'w') transform.write(''' import sys -sys.path += ['%s'] +sys.path += [%r] ''' % path_from_root('')) transform.write(post1) transform.write(''' @@ -163,6 +165,9 @@ process(sys.argv[1]) additional_files = final_additional_files else: # copy whole directory, and use a specific main .cpp file + # (rmtree() fails on Windows if the current working directory is inside the tree.) + if os.getcwd().startswith(os.path.abspath(dirname)): + os.chdir(os.path.join(dirname, '..')) shutil.rmtree(dirname) shutil.copytree(src, dirname) shutil.move(os.path.join(dirname, main_file), filename) @@ -253,7 +258,7 @@ process(sys.argv[1]) library_cache = {} - def get_library(self, name, generated_libs, configure=['./configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=True): + def get_library(self, name, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=True): build_dir = self.get_build_dir() output_dir = self.get_dir() @@ -4518,7 +4523,7 @@ def process(filename): # emcc should build in dlmalloc automatically, and do all the sign correction etc. for it try_delete(os.path.join(self.get_dir(), 'src.cpp.o.js')) - output = Popen([EMCC, path_from_root('tests', 'dlmalloc_test.c'), + output = Popen(['python', EMCC, path_from_root('tests', 'dlmalloc_test.c'), '-o', os.path.join(self.get_dir(), 'src.cpp.o.js')], stdout=PIPE, stderr=self.stderr_redirect).communicate() self.do_run('x', '*1,0*', ['200', '1'], no_build=True) @@ -5207,7 +5212,7 @@ def process(filename): open(header_filename, 'w').write(header) basename = os.path.join(self.get_dir(), 'bindingtest') - output = Popen([BINDINGS_GENERATOR, basename, header_filename], stdout=PIPE, stderr=self.stderr_redirect).communicate()[0] + output = Popen(['python', BINDINGS_GENERATOR, basename, header_filename], stdout=PIPE, stderr=self.stderr_redirect).communicate()[0] #print output assert 'Traceback' not in output, 'Failure in binding generation: ' + output @@ -5379,7 +5384,7 @@ Child2:9 open(header_filename, 'w').write(header) basename = os.path.join(self.get_dir(), 'bindingtest') - output = Popen([BINDINGS_GENERATOR, basename, header_filename], stdout=PIPE, stderr=self.stderr_redirect).communicate()[0] + output = Popen(['python', BINDINGS_GENERATOR, basename, header_filename], stdout=PIPE, stderr=self.stderr_redirect).communicate()[0] #print output assert 'Traceback' not in output, 'Failure in binding generation: ' + output @@ -5937,7 +5942,7 @@ TT = %s suffix = '.c' if compiler == EMCC else '.cpp' # --version - output = Popen([compiler, '--version'], stdout=PIPE, stderr=PIPE).communicate() + output = Popen(['python', compiler, '--version'], stdout=PIPE, stderr=PIPE).communicate() self.assertContained('''emcc (Emscripten GCC-like replacement) 2.0 Copyright (C) 2011 the Emscripten authors. This is free and open source software under the MIT license. @@ -5995,7 +6000,7 @@ Options that are modified or new in %s include: # handle singleton archives self.clear() Popen([compiler, path_from_root('tests', 'hello_world' + suffix), '-o', 'a.bc'], stdout=PIPE, stderr=PIPE).communicate() - Popen([LLVM_AR, 'r', 'a.a', 'a.bc'], stdout=PIPE, stderr=PIPE).communicate() + Popen(['python', LLVM_AR, 'r', 'a.a', 'a.bc'], stdout=PIPE, stderr=PIPE).communicate() assert os.path.exists('a.a') output = Popen([compiler, 'a.a']).communicate() assert os.path.exists('a.out.js'), output @@ -6205,7 +6210,7 @@ f.close() def test_emcc_html(self): # test HTML generation. - output = Popen([EMCC, path_from_root('tests', 'hello_world_sdl.cpp'), '-o', 'something.html'], stdout=PIPE, stderr=PIPE).communicate() + output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_sdl.cpp'), '-o', 'something.html'], stdout=PIPE, stderr=PIPE).communicate() assert len(output[0]) == 0, output[0] assert os.path.exists('something.html'), output self.run_browser('something.html', 'You should see "hello, world!" and a colored cube.') @@ -6232,7 +6237,7 @@ f.close() } ''')) - Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-o', 'page.html', + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-o', 'page.html', '--compression', '%s,%s,%s' % (path_from_root('third_party', 'lzma.js', 'lzma-native'), path_from_root('third_party', 'lzma.js', 'lzma-decoder.js'), 'LZMA.decompress')]).communicate() @@ -6262,7 +6267,7 @@ f.close() } ''')) - Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'somefile.txt', '-o', 'page.html']).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'somefile.txt', '-o', 'page.html']).communicate() self.run_browser('page.html', 'You should see |load me right before|.', '/report_result?1') def test_emcc_multifile(self): @@ -6298,13 +6303,13 @@ f.close() ''')) # by individual files - Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'subdirr/data1.txt', '--preload-file', 'subdirr/data2.txt', '-o', 'page.html']).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'subdirr/data1.txt', '--preload-file', 'subdirr/data2.txt', '-o', 'page.html']).communicate() self.run_browser('page.html', 'You should see two cool numbers', '/report_result?1') os.remove('page.html') # by directory - Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'subdirr', '-o', 'page.html']).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'subdirr', '-o', 'page.html']).communicate() self.run_browser('page.html', 'You should see two cool numbers', '/report_result?1') def test_emcc_compressed_file(self): @@ -6326,7 +6331,7 @@ f.close() } ''')) - Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-o', 'page.html', '--preload-file', 'datafile.txt', + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-o', 'page.html', '--preload-file', 'datafile.txt', '--compression', '%s,%s,%s' % (path_from_root('third_party', 'lzma.js', 'lzma-native'), path_from_root('third_party', 'lzma.js', 'lzma-decoder.js'), 'LZMA.decompress')]).communicate() @@ -6341,7 +6346,7 @@ f.close() shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.jpg')) open(os.path.join(self.get_dir(), 'sdl_image.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_image.c')).read())) - Popen([EMCC, os.path.join(self.get_dir(), 'sdl_image.c'), '--preload-file', 'screenshot.jpg', '-o', 'page.html']).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'sdl_image.c'), '--preload-file', 'screenshot.jpg', '-o', 'page.html']).communicate() self.run_browser('page.html', '', '/report_result?600') def test_emcc_sdl_image_compressed(self): @@ -6354,7 +6359,7 @@ f.close() shutil.copyfile(image, os.path.join(self.get_dir(), basename)) open(os.path.join(self.get_dir(), 'sdl_image.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_image.c')).read()).replace('screenshot.jpg', basename).replace('600', str(width)).replace('450', str(height))) - Popen([EMCC, os.path.join(self.get_dir(), 'sdl_image.c'), '--preload-file', basename, '-o', 'page.html', + Popen(['python', EMCC, os.path.join(self.get_dir(), 'sdl_image.c'), '--preload-file', basename, '-o', 'page.html', '--compression', '%s,%s,%s' % (path_from_root('third_party', 'lzma.js', 'lzma-native'), path_from_root('third_party', 'lzma.js', 'lzma-decoder.js'), 'LZMA.decompress')]).communicate() @@ -6366,7 +6371,7 @@ f.close() def test_emcc_worker(self): # Test running in a web worker - output = Popen([EMCC, path_from_root('tests', 'hello_world_worker.cpp'), '-o', 'worker.js'], stdout=PIPE, stderr=PIPE).communicate() + output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_worker.cpp'), '-o', 'worker.js'], stdout=PIPE, stderr=PIPE).communicate() assert len(output[0]) == 0, output[0] assert os.path.exists('worker.js'), output self.assertContained('you should not see this text when in a worker!', run_js('worker.js')) # code should run standalone @@ -6388,7 +6393,7 @@ f.close() def test_emcc_gl(self): # test the OpenGL ES implementation - output = Popen([EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html', + output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html', '-DHAVE_BUILTIN_SINCOS', '--shell-file', path_from_root('tests', 'hello_world_gles_shell.html')], stdout=PIPE, stderr=PIPE).communicate() @@ -6398,7 +6403,7 @@ f.close() def test_emcc_gl_fail(self): # Make sure that OpenGL ES is not available if typed arrays are not used - output = Popen([EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html', + output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html', '-DHAVE_BUILTIN_SINCOS', '-s', 'USE_TYPED_ARRAYS=0', '--shell-file', path_from_root('tests', 'hello_world_gles_shell.html')], @@ -6430,9 +6435,9 @@ f.close() } ''') - Popen([EMCC, os.path.join(self.get_dir(), 'libdir', 'libfile.cpp'), '-c'], stdout=PIPE, stderr=STDOUT).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'libdir', 'libfile.cpp'), '-c'], stdout=PIPE, stderr=STDOUT).communicate() shutil.move(os.path.join(self.get_dir(), 'libfile.o'), os.path.join(self.get_dir(), 'libdir', 'libfile.so')) - Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-L' + os.path.join(self.get_dir(), 'libdir'), '-lfile'], stdout=PIPE, stderr=STDOUT).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-L' + os.path.join(self.get_dir(), 'libdir'), '-lfile'], stdout=PIPE, stderr=STDOUT).communicate() self.assertContained('hello from lib', run_js(os.path.join(self.get_dir(), 'a.out.js'))) def test_emcc_embed_file(self): @@ -6450,7 +6455,7 @@ f.close() } ''') - Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--embed-file', 'somefile.txt']).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--embed-file', 'somefile.txt']).communicate() self.assertContained('|hello from a file wi|', run_js(os.path.join(self.get_dir(), 'a.out.js'))) def test_emcc_multidynamic_link(self): @@ -6495,7 +6500,7 @@ f.close() ''') # This lets us link the same dynamic lib twice. We will need to link it in manually at the end. - compiler = [EMCC, '--ignore-dynamic-linking'] + compiler = ['python', EMCC, '--ignore-dynamic-linking'] # Build libfile normally into an .so Popen(compiler + [os.path.join(self.get_dir(), 'libdir', 'libfile.cpp'), '-o', os.path.join(self.get_dir(), 'libdir', 'libfile.so')]).communicate() @@ -6505,7 +6510,7 @@ f.close() Popen(compiler + [os.path.join(self.get_dir(), 'main.cpp'), '-L' + os.path.join(self.get_dir(), 'libdir'), '-lfile', '-lother', '-c']).communicate() # The normal build system is over. We need to do an additional step to link in the dynamic libraries, since we ignored them before - Popen([EMCC, os.path.join(self.get_dir(), 'main.o'), '-L' + os.path.join(self.get_dir(), 'libdir'), '-lfile', '-lother']).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.o'), '-L' + os.path.join(self.get_dir(), 'libdir'), '-lfile', '-lother']).communicate() self.assertContained('*hello from lib\n|hello from lib|\n*', run_js(os.path.join(self.get_dir(), 'a.out.js'))) @@ -6525,7 +6530,7 @@ f.close() Module.print(MESSAGE); ''') - Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'before.js', '--post-js', 'after.js']).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'before.js', '--post-js', 'after.js']).communicate() self.assertContained('hello from main\nhello from js\n', run_js(os.path.join(self.get_dir(), 'a.out.js'))) def test_eliminator(self): @@ -6649,7 +6654,7 @@ elif 'benchmark' in str(sys.argv): final_filename = os.path.join(dirname, 'src.js') try_delete(final_filename) - output = Popen([EMCC, filename, '-O3', + output = Popen(['python', EMCC, filename, '-O3', '-s', 'INLINING_LIMIT=0', '-s', 'TOTAL_MEMORY=100*1024*1024', '-s', 'FAST_MEMORY=10*1024*1024', '-o', final_filename] + emcc_args, stdout=PIPE, stderr=self.stderr_redirect).communicate() @@ -6904,6 +6909,8 @@ elif 'sanity' in str(sys.argv): def do(self, command): if type(command) is not list: command = [command] + if command[0] == EMCC: + command = ['python'] + command return Popen(command, stdout=PIPE, stderr=STDOUT).communicate()[0] @@ -6937,7 +6944,7 @@ elif 'sanity' in str(sys.argv): self.assertContained('Please edit that file and change the paths to fit your system', output) self.assertContained('make sure LLVM_ROOT and NODE_JS are correct', output) self.assertContained('This command will now exit. When you are done editing those paths, re-run it.', output) - assert output.replace('\n', '').endswith('===='), 'We should have stopped: ' + output + assert output.split()[-1].endswith('===='), 'We should have stopped: ' + output assert (open(CONFIG_FILE).read() == open(path_from_root('settings.py')).read()), 'Settings should be copied from settings.py' # Second run, with bad EM_CONFIG diff --git a/tools/eliminator/eliminator.coffee b/tools/eliminator/eliminator.coffee index ba91aa89..0af57111 100644 --- a/tools/eliminator/eliminator.coffee +++ b/tools/eliminator/eliminator.coffee @@ -369,7 +369,10 @@ class ExpressionOptimizer # function, then writes the optimized result to stdout. main = -> # Get the parse tree. - src = fs.readFileSync('/dev/stdin').toString() + src = '' + size = fs.fstatSync(process.stdin.fd).size + if size > 0 + src = fs.readSync(process.stdin.fd, size)[0] throw 'Cannot identify generated functions' if GENERATED_FUNCTIONS_MARKER in src generatedFunctionsLine = src.split('\n').filter (line) -> diff --git a/tools/emmaken.py b/tools/emmaken.py index 8e1bfdc8..ae4794f0 100755 --- a/tools/emmaken.py +++ b/tools/emmaken.py @@ -113,7 +113,7 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG: compiler = 'g++' if 'CXXCompiler' in ' '.join(sys.argv) or os.environ.get('EMMAKEN_CXX') else 'gcc' cmd = [compiler] + EMSDK_OPTS + sys.argv[1:] print >> sys.stderr, 'emmaken.py, just configuring: ', cmd - exit(os.execvp(compiler, cmd)) + exit(subprocess.call(cmd)) try: #f=open('/dev/shm/tmp/waka.txt', 'a') @@ -223,7 +223,7 @@ try: print >> sys.stderr, "Running:", call, ' '.join(newargs) - os.execvp(call, [call] + newargs) + subprocess.call([call] + newargs) except Exception, e: print 'Error in emmaken.py. (Is the config file %s set up properly?) Error:' % EM_CONFIG, e raise diff --git a/tools/emmakenxx.py b/tools/emmakenxx.py index c9ab4ef4..1c31f3c2 100755 --- a/tools/emmakenxx.py +++ b/tools/emmakenxx.py @@ -4,7 +4,7 @@ see emmaken.py ''' -import os, sys +import os, subprocess, sys __rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) def path_from_root(*pathelems): @@ -14,5 +14,5 @@ from tools.shared import * emmaken = path_from_root('tools', 'emmaken.py') os.environ['EMMAKEN_CXX'] = '1' -exit(os.execvp('python', ['python', emmaken] + sys.argv[1:])) +exit(subprocess.call(['python', emmaken] + sys.argv[1:])) diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 7094cdfc..79599528 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -24,11 +24,14 @@ if (ENVIRONMENT_IS_NODE) { }; var nodeFS = require('fs'); + var nodePath = require('path'); read = function(filename) { + filename = nodePath['normalize'](filename); var ret = nodeFS['readFileSync'](filename).toString(); - if (!ret && filename[0] != '/') { - filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename; + // The path is absolute if the normalized version is the same as the resolved. + if (!ret && filename != nodePath['resolve'](filename)) { + filename = path.join(__dirname, '..', 'src', filename); ret = nodeFS['readFileSync'](filename).toString(); } return ret; @@ -97,12 +100,15 @@ if (typeof print === 'undefined') { // Fix read for our location read = function(filename) { - if (filename[0] != '/') filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename; + // The path is absolute if the normalized version is the same as the resolved. + filename = path.normalize(filename); + if (filename != path.resolve(filename)) filename = path.join(__dirname, '..', 'src', filename); return fs.readFileSync(filename).toString(); } var uglify = require('../tools/eliminator/node_modules/uglify-js'); var fs = require('fs'); +var path = require('path'); // Load some modules diff --git a/tools/make_minigzip.py b/tools/make_minigzip.py index cdd9c2ab..60177318 100644 --- a/tools/make_minigzip.py +++ b/tools/make_minigzip.py @@ -9,5 +9,5 @@ zlib = shared.Building.build_library('zlib', shared.EMSCRIPTEN_TEMP_DIR, shared. print 'Building minigzip' -Popen([shared.EMCC, '-O2', shared.path_from_root('tests', 'zlib', 'minigzip.c'), zlib, '-o', shared.path_from_root('tools', 'minigzip.js')]).communicate() +Popen(['python', shared.EMCC, '-O2', shared.path_from_root('tests', 'zlib', 'minigzip.c'), zlib, '-o', shared.path_from_root('tools', 'minigzip.js')]).communicate() diff --git a/tools/shared.py b/tools/shared.py index 6a63d4ec..87d6904a 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -357,11 +357,11 @@ class Building: @staticmethod def get_building_env(): env = os.environ.copy() - env['CC'] = EMCC - env['CXX'] = EMXX - env['AR'] = EMAR - env['RANLIB'] = EMRANLIB - env['LIBTOOL'] = EMLIBTOOL + env['CC'] = 'python %r' % EMCC + env['CXX'] = 'python %r' % EMXX + env['AR'] = 'python %r' % EMAR + env['RANLIB'] = 'python %r' % EMRANLIB + env['LIBTOOL'] = 'python %r' % EMLIBTOOL env['EMMAKEN_COMPILER'] = Building.COMPILER env['EMSCRIPTEN_TOOLS'] = path_from_root('tools') env['CFLAGS'] = env['EMMAKEN_CFLAGS'] = ' '.join(Building.COMPILER_TEST_OPTS) @@ -377,10 +377,10 @@ class Building: SET(CMAKE_SYSTEM_NAME Linux) # which C and C++ compiler to use -SET(CMAKE_C_COMPILER $EMSCRIPTEN_ROOT/emcc) -SET(CMAKE_CXX_COMPILER $EMSCRIPTEN_ROOT/em++) -SET(CMAKE_AR $EMSCRIPTEN_ROOT/emar) -SET(CMAKE_RANLIB $EMSCRIPTEN_ROOT/emranlib) +SET(CMAKE_C_COMPILER python $EMSCRIPTEN_ROOT/emcc) +SET(CMAKE_CXX_COMPILER python $EMSCRIPTEN_ROOT/em++) +SET(CMAKE_AR python $EMSCRIPTEN_ROOT/emar) +SET(CMAKE_RANLIB python $EMSCRIPTEN_ROOT/emranlib) SET(CMAKE_C_FLAGS $CFLAGS) SET(CMAKE_CXX_FLAGS $CXXFLAGS) @@ -394,7 +394,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' \ - .replace('$EMSCRIPTEN_ROOT', path_from_root('')) \ + .replace('$EMSCRIPTEN_ROOT', path_from_root('').replace('\\', '/')) \ .replace('$CFLAGS', env['CFLAGS']) \ .replace('$CXXFLAGS', env['CFLAGS']) toolchainFile = mkstemp(suffix='.txt')[1] @@ -409,17 +409,17 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' \ env['EMMAKEN_JUST_CONFIGURE'] = '1' if 'cmake' in args[0]: args = Building.handle_CMake_toolchain(args, env) - Popen(args, stdout=stdout, stderr=stderr, env=env).communicate()[0] + Popen(args, stdout=stdout, stderr=stderr, env=env).communicate() del env['EMMAKEN_JUST_CONFIGURE'] @staticmethod def make(args, stdout=None, stderr=None, env=None): if env is None: env = Building.get_building_env() - Popen(args, stdout=stdout, stderr=stderr, env=env).communicate()[0] + Popen(args, stdout=stdout, stderr=stderr, env=env).communicate() @staticmethod - def build_library(name, build_dir, output_dir, generated_libs, configure=['./configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=None, cache_name=None, copy_project=False, env_init={}, source_dir=None): + def build_library(name, build_dir, output_dir, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=None, cache_name=None, copy_project=False, env_init={}, source_dir=None): ''' Build a library into a .bc file. We build the .bc file once and cache it for all our tests. (We cache in memory since the test directory is destroyed and recreated for each test. Note that we cache separately for different compilers). @@ -555,13 +555,13 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' \ if output_filename is None: output_filename = filename + '.o' try_delete(output_filename) - Popen([EMCC, filename] + args + ['-o', output_filename], stdout=stdout, stderr=stderr, env=env).communicate() + Popen(['python', EMCC, filename] + args + ['-o', output_filename], stdout=stdout, stderr=stderr, env=env).communicate() assert os.path.exists(output_filename), 'emcc could not create output file' @staticmethod def emar(action, output_filename, filenames, stdout=None, stderr=None, env=None): try_delete(output_filename) - Popen([EMAR, action, output_filename] + filenames, stdout=stdout, stderr=stderr, env=env).communicate() + Popen(['python', EMAR, action, output_filename] + filenames, stdout=stdout, stderr=stderr, env=env).communicate() if 'c' in action: assert os.path.exists(output_filename), 'emar could not create output file' |