diff --git a/emscripten.py b/emscripten.py index 5eb62ba22..681d22836 100755 --- a/emscripten.py +++ b/emscripten.py @@ -74,6 +74,8 @@ def emscript(infile, settings, outfile, libraries=[]): if DEBUG: print >> sys.stderr, 'emscript: ll=>js' + if jcache: JCache.ensure() + # Pre-scan ll and alter settings as necessary if DEBUG: t = time.time() ll = open(infile).read() @@ -134,13 +136,14 @@ def emscript(infile, settings, outfile, libraries=[]): pre_input = ''.join(pre) + '\n' + meta out = None if jcache: - pre_cache_key = JCache.get_key([pre_input, settings_text, ','.join(libraries)]) - out = JCache.get(pre_cache_key) + keys = [pre_input, settings_text, ','.join(libraries)] + shortkey = JCache.get_key(keys) + out = 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(pre_cache_key, out) + 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 06cbba682..b445051dc 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1154,19 +1154,31 @@ class Cache: return cachename class JCache: - # Generates a single key from multiple values - @staticmethod - def get_key(keys): - return '' + dirname = os.path.join(Cache.dirname, 'jcache') - # Returns a cached value for a key (from get_key), if it exists @staticmethod - def get(key): + def ensure(): + Cache.ensure() + if not os.path.exists(JCache.dirname): + os.makedirs(JCache.dirname) + + @staticmethod + def get_shortkey(keys): + if type(keys) not in [list, tuple]: + keys = [keys] + ret = '' + for key in keys: + ret += md5.md5(key).hexdigest() + return ret + + # Returns a cached value, if it exists. Make sure the full key matches + @staticmethod + def get(shortkey, keys): return None # Sets the cached value for a key (from get_key) @staticmethod - def set(key, value): + def set(shortkey, keys, value): pass # Compression of code and data for smaller downloads