aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-11-19 14:46:02 +0100
committerAlon Zakai <alonzakai@gmail.com>2012-11-21 20:47:01 +0100
commite4aa21f08ab91749ec2e7b3a22a3200bae6c8512 (patch)
tree300747067b1676100cf66c549e92fdf13eb9fdea
parent8fce64dd18afaa0c49fb59cf161fa2fadeac6e7a (diff)
fix and test pre caching
-rwxr-xr-xemscripten.py3
-rwxr-xr-xtests/runner.py38
-rw-r--r--tools/shared.py8
3 files changed, 41 insertions, 8 deletions
diff --git a/emscripten.py b/emscripten.py
index 488b29e5..42603cd7 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -93,6 +93,7 @@ def emscript(infile, settings, outfile, libraries=[]):
in_func = False
ll_lines = open(infile).readlines()
for line in ll_lines:
+ if line.startswith(';'): continue
if in_func:
funcs[-1].append(line)
if line.startswith('}'):
@@ -139,10 +140,12 @@ def emscript(infile, settings, outfile, libraries=[]):
keys = [pre_input, settings_text, ','.join(libraries)]
shortkey = shared.JCache.get_shortkey(keys)
out = shared.JCache.get(shortkey, keys)
+ if out and DEBUG: print >> sys.stderr, ' loading pre from jcache'
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:
+ if DEBUG: print >> sys.stderr, ' saving pre to jcache'
shared.JCache.set(shortkey, keys, out)
pre, forwarded_data = out.split('//FORWARDED_DATA:')
forwarded_file = temp_files.get('.json').name
diff --git a/tests/runner.py b/tests/runner.py
index 8ffc759a..7a26e6a3 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -10063,6 +10063,8 @@ elif 'sanity' in str(sys.argv):
assert os.path.exists(CONFIG_FILE), 'To run these tests, we need a (working!) %s file to already exist' % EM_CONFIG
+ assert not os.environ.get('EMCC_DEBUG'), 'do not run sanity checks in debug mode!'
+
shutil.copyfile(CONFIG_FILE, CONFIG_FILE + '_backup')
def restore():
shutil.copyfile(CONFIG_FILE + '_backup', CONFIG_FILE)
@@ -10295,10 +10297,11 @@ fi
self.assertContained(SANITY_MESSAGE, output)
# but with EMCC_DEBUG=1 we should check
- assert not os.environ.get('EMCC_DEBUG'), 'do not run sanity checks in debug mode!'
- os.environ['EMCC_DEBUG'] = '1'
- output = self.check_working(EMCC)
- del os.environ['EMCC_DEBUG']
+ try:
+ os.environ['EMCC_DEBUG'] = '1'
+ output = self.check_working(EMCC)
+ finally:
+ del os.environ['EMCC_DEBUG']
self.assertContained(SANITY_MESSAGE, output)
output = self.check_working(EMCC)
self.assertNotContained(SANITY_MESSAGE, output)
@@ -10435,6 +10438,33 @@ fi
assert os.path.exists(RELOOPER) == (i >= 2), 'have relooper on O2: ' + output
assert ('L2 : do {' in open('a.out.js').read()) == (i >= 2), 'reloop code on O2: ' + output
+ def test_jcache(self):
+ PRE_LOAD_MSG = 'loading pre from jcache'
+ PRE_SAVE_MSG = 'saving pre to jcache'
+
+ restore()
+ Cache.erase()
+
+ try:
+ os.environ['EMCC_DEBUG'] = '1'
+
+ src = None
+ for args, expect_save, expect_load in [([], False, False),
+ (['--jcache'], True, False),
+ (['--jcache'], False, True),
+ ([], False, False)]:
+ print args, expect_save, expect_load
+ out, err = Popen(['python', EMCC, path_from_root('tests', 'hello_world_loop.cpp')] + args, stdout=PIPE, stderr=PIPE).communicate()
+ assert (PRE_SAVE_MSG in err) == expect_save, err
+ assert (PRE_LOAD_MSG in err) == expect_load, errr
+ curr = open('a.out.js').read()
+ if src is None:
+ src = None
+ else:
+ assert src == curr, 'caching must not affect codegen'
+ finally:
+ del os.environ['EMCC_DEBUG']
+
else:
raise Exception('Test runner is confused: ' + str(sys.argv))
diff --git a/tools/shared.py b/tools/shared.py
index 18c3cea7..83c837c8 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1183,17 +1183,17 @@ class JCache:
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'
+ #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)'
+ #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)'
+ #if DEBUG: print >> sys.stderr, 'jcache collision (b)'
return
- if DEBUG: print >> sys.stderr, 'jcache win'
+ #if DEBUG: print >> sys.stderr, 'jcache win'
return data[1]
# Sets the cached value for a key (from get_key)