systrace: check for errors when compiling JS
Change-Id: I0daba4b5977734ce819451dd9200317d7e0c4ca9
diff --git a/update.py b/update.py
index 357e1a0..37f41c5 100755
--- a/update.py
+++ b/update.py
@@ -1,6 +1,6 @@
-#!/usr/bin/python
+#!/usr/bin/python2.6
-import httplib, urllib, subprocess, sys, config
+import config, httplib, json, urllib, subprocess, sys
# Read all the Javascript files.
js_code = [('js_code', open(f).read()) for f in config.js_in_files]
@@ -13,7 +13,8 @@
params = urllib.urlencode(js_code + [
('language', 'ECMASCRIPT5'),
('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
- ('output_format', 'text'),
+ ('output_format', 'json'),
+ ('output_info', 'errors'),
('output_info', 'compiled_code'),
])
@@ -29,8 +30,20 @@
print sys.stderr, "error returned from JS compile service: %d" % response.status
sys.exit(1)
-open(config.js_out_file, 'wt').write(data)
-print 'Generated %s. Check the file to see if errors occured!' % config.js_out_file
+result = json.loads(data)
+if 'errors' in result:
+ for e in result['errors']:
+ filenum = int(e['file'][6:])
+ filename = js_in_files[filenum]
+ lineno = e['lineno']
+ charno = e['charno']
+ err = e['error']
+ print '%s:%d:%d: %s' % (filename, lineno, charno, err)
+ print 'Failed to generate %s.' % config.js_out_file
+ sys.exit(1)
+
+open(config.js_out_file, 'wt').write(result['compiledCode'] + '\n')
+print 'Generated %s' % config.js_out_file
yuic_args = ['yui-compressor', '--type', 'css', '-o', config.css_out_file]
p = subprocess.Popen(yuic_args, stdin=subprocess.PIPE)
@@ -39,4 +52,4 @@
print 'Failed to generate %s.' % config.css_out_file
sys.exit(1)
-print 'Generated %s.' % config.css_out_file
+print 'Generated %s' % config.css_out_file