aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemscripten.py8
-rw-r--r--tools/shared.py27
2 files changed, 28 insertions, 7 deletions
diff --git a/emscripten.py b/emscripten.py
index 681d2283..488b29e5 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -74,7 +74,7 @@ def emscript(infile, settings, outfile, libraries=[]):
if DEBUG: print >> sys.stderr, 'emscript: ll=>js'
- if jcache: JCache.ensure()
+ if jcache: shared.JCache.ensure()
# Pre-scan ll and alter settings as necessary
if DEBUG: t = time.time()
@@ -137,13 +137,13 @@ def emscript(infile, settings, outfile, libraries=[]):
out = None
if jcache:
keys = [pre_input, settings_text, ','.join(libraries)]
- shortkey = JCache.get_key(keys)
- out = JCache.get(shortkey, keys)
+ shortkey = shared.JCache.get_shortkey(keys)
+ out = shared.JCache.get(shortkey, keys)
if not out:
open(pre_file, 'w').write(pre_input)
out = shared.run_js(compiler, shared.COMPILER_ENGINE, [settings_file, pre_file, 'pre'] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src'))
if jcache:
- JCache.set(shortkey, keys, out)
+ shared.JCache.set(shortkey, keys, out)
pre, forwarded_data = out.split('//FORWARDED_DATA:')
forwarded_file = temp_files.get('.json').name
open(forwarded_file, 'w').write(forwarded_data)
diff --git a/tools/shared.py b/tools/shared.py
index b445051d..18c3cea7 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1,4 +1,4 @@
-import shutil, time, os, sys, json, tempfile, copy, shlex, atexit, subprocess
+import shutil, time, os, sys, json, tempfile, copy, shlex, atexit, subprocess, md5, cPickle
from subprocess import Popen, PIPE, STDOUT
from tempfile import mkstemp
@@ -1168,18 +1168,39 @@ class JCache:
keys = [keys]
ret = ''
for key in keys:
+ assert type(key) == str
ret += md5.md5(key).hexdigest()
return ret
+ @staticmethod
+ def get_cachename(shortkey):
+ return os.path.join(JCache.dirname, shortkey)
+
# Returns a cached value, if it exists. Make sure the full key matches
@staticmethod
def get(shortkey, keys):
- return None
+ cachename = JCache.get_cachename(shortkey)
+ if not os.path.exists(cachename): return
+ data = cPickle.Unpickler(open(cachename, 'rb')).load()
+ if len(data) != 2:
+ if DEBUG: print >> sys.stderr, 'jcache error in get'
+ return
+ oldkeys = data[0]
+ if len(oldkeys) != len(keys):
+ if DEBUG: print >> sys.stderr, 'jcache collision (a)'
+ return
+ for i in range(len(oldkeys)):
+ if oldkeys[i] != keys[i]:
+ if DEBUG: print >> sys.stderr, 'jcache collision (b)'
+ return
+ if DEBUG: print >> sys.stderr, 'jcache win'
+ return data[1]
# Sets the cached value for a key (from get_key)
@staticmethod
def set(shortkey, keys, value):
- pass
+ cachename = JCache.get_cachename(shortkey)
+ cPickle.Pickler(open(cachename, 'wb')).dump([keys, value])
# Compression of code and data for smaller downloads
class Compression: