aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-12-07 10:37:25 -0500
committerAlon Zakai <alonzakai@gmail.com>2013-12-07 10:37:25 -0500
commit1a007b1631509b9d72499a8f4402294017ee04dc (patch)
tree92f8b0341497c7bd4e53aa82c690346536a244c3 /tools
parentdf11c6f1fd1636a355b83a1c48b3a890596e6a32 (diff)
parenteb083723747a90cb6ab9853fec8d6e8ef54748bc (diff)
Merge branch 'incoming'
Diffstat (limited to 'tools')
-rw-r--r--tools/cache.py12
-rw-r--r--tools/file_packager.py8
-rw-r--r--tools/jsrun.py2
-rw-r--r--tools/shared.py34
4 files changed, 37 insertions, 19 deletions
diff --git a/tools/cache.py b/tools/cache.py
index c316a1fd..6f2443e8 100644
--- a/tools/cache.py
+++ b/tools/cache.py
@@ -13,8 +13,7 @@ class Cache:
self.debug = debug
def ensure(self):
- if not os.path.exists(self.dirname):
- os.makedirs(self.dirname)
+ shared.safe_ensure_dirs(self.dirname)
def erase(self):
tempfiles.try_delete(self.dirname)
@@ -48,11 +47,7 @@ class JCache:
def ensure(self):
self.cache.ensure()
- if not os.path.exists(self.dirname):
- try:
- os.makedirs(self.dirname)
- except (IOError, OSError):
- pass
+ shared.safe_ensure_dirs(self.dirname)
def get_shortkey(self, keys):
if type(keys) not in [list, tuple]:
@@ -196,3 +191,6 @@ def chunkify(funcs, chunk_size, chunking_file, DEBUG=False):
# if previous_mapping.get(ident) != new_mapping.get(ident):
# print >> sys.stderr, 'mapping inconsistency', ident, previous_mapping.get(ident), new_mapping.get(ident)
return [''.join([func[1] for func in chunk]) for chunk in chunks] # remove function names
+
+import shared
+
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 3ba5b23f..7d9344cd 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -453,7 +453,13 @@ if has_preloaded:
package_uuid = uuid.uuid4();
remote_package_name = os.path.basename(Compression.compressed_name(data_target) if Compression.on else data_target)
code += r'''
- var PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/');
+ var PACKAGE_PATH;
+ if (typeof window === 'object') {
+ PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/');
+ } else {
+ // worker
+ PACKAGE_PATH = encodeURIComponent(location.pathname.toString().substring(0, location.pathname.toString().lastIndexOf('/')) + '/');
+ }
var PACKAGE_NAME = '%s';
var REMOTE_PACKAGE_NAME = '%s';
var PACKAGE_UUID = '%s';
diff --git a/tools/jsrun.py b/tools/jsrun.py
index 7acfc978..f74a1492 100644
--- a/tools/jsrun.py
+++ b/tools/jsrun.py
@@ -3,7 +3,7 @@ from subprocess import Popen, PIPE, STDOUT
TRACK_PROCESS_SPAWNS = True if (os.getenv('EM_BUILD_VERBOSE') and int(os.getenv('EM_BUILD_VERBOSE')) >= 3) else False
-def timeout_run(proc, timeout, note='unnamed process', full_output=False):
+def timeout_run(proc, timeout=None, note='unnamed process', full_output=False):
start = time.time()
if timeout is not None:
while time.time() - start < timeout and proc.poll() is None:
diff --git a/tools/shared.py b/tools/shared.py
index 6330b8a6..3eb72a1e 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1,4 +1,4 @@
-import shutil, time, os, sys, json, tempfile, copy, shlex, atexit, subprocess, hashlib, cPickle, re
+import shutil, time, os, sys, json, tempfile, copy, shlex, atexit, subprocess, hashlib, cPickle, re, errno
from subprocess import Popen, PIPE, STDOUT
from tempfile import mkstemp
from distutils.spawn import find_executable
@@ -456,6 +456,18 @@ FILE_PACKAGER = path_from_root('tools', 'file_packager.py')
# Temp dir. Create a random one, unless EMCC_DEBUG is set, in which case use TEMP_DIR/emscripten_temp
+def safe_ensure_dirs(dirname):
+ try:
+ os.makedirs(dirname)
+ except os.error, e:
+ # Ignore error for already existing dirname
+ if e.errno != errno.EEXIST:
+ raise e
+ # FIXME: Notice that this will result in a false positive,
+ # should the dirname be a file! There seems to no way to
+ # handle this atomically in Python 2.x.
+ # There is an additional option for Python 3.x, though.
+
class Configuration:
def __init__(self, environ=os.environ):
self.DEBUG = environ.get('EMCC_DEBUG')
@@ -480,10 +492,9 @@ class Configuration:
if self.DEBUG:
try:
self.EMSCRIPTEN_TEMP_DIR = self.CANONICAL_TEMP_DIR
- if not os.path.exists(self.EMSCRIPTEN_TEMP_DIR):
- os.makedirs(self.EMSCRIPTEN_TEMP_DIR)
+ safe_ensure_dirs(self.EMSCRIPTEN_TEMP_DIR)
except Exception, e:
- logging.debug(e + 'Could not create canonical temp dir. Check definition of TEMP_DIR in ~/.emscripten')
+ logging.error(str(e) + 'Could not create canonical temp dir. Check definition of TEMP_DIR in ~/.emscripten')
def get_temp_files(self):
return tempfiles.TempFiles(
@@ -1017,8 +1028,7 @@ class Building:
try:
temp_dir = os.path.join(EMSCRIPTEN_TEMP_DIR, 'ar_output_' + str(os.getpid()) + '_' + str(len(temp_dirs)))
temp_dirs.append(temp_dir)
- if not os.path.exists(temp_dir):
- os.makedirs(temp_dir)
+ safe_ensure_dirs(temp_dir)
os.chdir(temp_dir)
contents = filter(lambda x: len(x) > 0, Popen([LLVM_AR, 't', f], stdout=PIPE).communicate()[0].split('\n'))
#print >> sys.stderr, ' considering archive', f, ':', contents
@@ -1027,9 +1037,9 @@ class Building:
else:
for content in contents: # ar will silently fail if the directory for the file does not exist, so make all the necessary directories
dirname = os.path.dirname(content)
- if dirname and not os.path.exists(dirname):
- os.makedirs(dirname)
- Popen([LLVM_AR, 'x', f], stdout=PIPE).communicate() # if absolute paths, files will appear there. otherwise, in this directory
+ if dirname:
+ safe_ensure_dirs(dirname)
+ Popen([LLVM_AR, 'xo', f], stdout=PIPE).communicate() # if absolute paths, files will appear there. otherwise, in this directory
contents = map(lambda content: os.path.join(temp_dir, content), contents)
contents = filter(os.path.exists, map(os.path.abspath, contents))
added_contents = set()
@@ -1411,6 +1421,10 @@ class Building:
@staticmethod
def ensure_relooper(relooper):
if os.path.exists(relooper): return
+ if os.environ.get('EMCC_FAST_COMPILER'):
+ logging.debug('not building relooper to js, using it in c++ backend')
+ return
+
Cache.ensure()
curr = os.getcwd()
try:
@@ -1509,7 +1523,7 @@ class JS:
@staticmethod
def to_nice_ident(ident): # limited version of the JS function toNiceIdent
- return ident.replace('%', '$').replace('@', '_')
+ return ident.replace('%', '$').replace('@', '_').replace('.', '_')
@staticmethod
def make_initializer(sig, settings=None):