aboutsummaryrefslogtreecommitdiff
path: root/tools/shared.py
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/shared.py
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/shared.py')
-rw-r--r--tools/shared.py30
1 files changed, 15 insertions, 15 deletions
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'