aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSigmund Vik <sigmund_vik@yahoo.com>2012-03-20 14:26:50 +0100
committerSigmund Vik <sigmund_vik@yahoo.com>2012-03-20 14:26:50 +0100
commitf829735cc3e20e5d2165a020e87c4128d2ed9792 (patch)
tree6a4d4589ec780ee560e4a8ab8bc8ab55318e4d34 /tools
parentbe2dafadec0e5a39e3e55a3663183ca6a8dd5d8e (diff)
Misc fixes for Windows.
Most of these changes have to do with how python scripts are invoked. For Linux, 'Popen([EMCC] + args)' works because the first line in emcc is '#!/usr/bin/env python'. On Windows, the python interpreter has to be explicitly invoked, e.g. 'Popen(['python', EMCC] + args)'. Note that there is no harm in explicitly invoking the python interpreter on Linux, so this works on both platforms. For Windows, execvp() behaves differently than on Linux: http://mail.python.org/pipermail/python-list/2002-July/763863.html http://msdn.microsoft.com/en-us/library/3xw6zy53.aspx This causes many strange things to happen as the parent process terminated before its children. In this change the use of execvp() has been replaced with subprocess.call(). This change also fixes some code that assumed that the path separator always is '/', but for Windows it is '\'. And where the path module can be required, we use path.normalize() and path.resolve() to check if a filename is absolute in a platform agnostic manner.
Diffstat (limited to 'tools')
-rw-r--r--tools/eliminator/eliminator.coffee5
-rwxr-xr-xtools/emmaken.py4
-rwxr-xr-xtools/emmakenxx.py4
-rw-r--r--tools/js-optimizer.js12
-rw-r--r--tools/make_minigzip.py2
-rw-r--r--tools/shared.py30
6 files changed, 33 insertions, 24 deletions
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'