Bug 1491104 - Part 2: Add a script to regenerate all binjs files in tree. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Thu, 04 Oct 2018 21:22:43 +0900
changeset 495398 b6a33d28cb1e3fba94d040f4bc025258b02ad3a9
parent 495397 638b59fbfb47e37e088c9cf08fd5ba0ae5282660
child 495399 82efcc7fe32fe0bf727f3e9aea588d11c5a24ded
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1491104
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1491104 - Part 2: Add a script to regenerate all binjs files in tree. r=Yoric
js/src/jsapi-tests/binast/README.md
js/src/jsapi-tests/binast/encode.py
new file mode 100644
--- /dev/null
+++ b/js/src/jsapi-tests/binast/README.md
@@ -0,0 +1,10 @@
+To update all binjs files in tree, run the following command:
+
+```
+./encode.py \
+    --topsrcdir={path to mozilla-unified} \
+    --binjsdir={path to binjs-ref clone} \
+    --binjs_encode={path to  binjs_encode} \
+    --babel={path to babel command} \
+    --babel-preset-env={path to babel-preset-env}
+```
new file mode 100755
--- /dev/null
+++ b/js/src/jsapi-tests/binast/encode.py
@@ -0,0 +1,78 @@
+#!/usr/bin/python -B
+
+from __future__ import print_function
+from optparse import OptionParser
+import os
+import re
+import subprocess
+import sys
+
+parser = OptionParser()
+parser.add_option('--topsrcdir', dest='topsrcdir',
+                  help='path to mozilla-central')
+parser.add_option('--binjsdir', dest='binjsdir',
+                  help='cwd when running binjs_encode')
+parser.add_option('--binjs_encode', dest='binjs_encode',
+                  help='path to binjs_encode commad')
+(options, args) = parser.parse_args()
+
+def ensure_dir(path, name):
+    if not os.path.isdir(path):
+        print('{} directory {} does not exit'.format(name, path),
+              file=sys.stderr)
+        sys.exit(1)
+
+def ensure_file(path, name):
+    if not os.path.isfile(path):
+        print('{} {} does not exit'.format(name, path),
+              file=sys.stderr)
+        sys.exit(1)
+
+ensure_dir(options.topsrcdir, 'topsrcdir')
+ensure_dir(options.binjsdir, 'binjsdir')
+ensure_file(options.binjs_encode, 'binjs_encode command')
+
+def encode(infile_path, outfile_path, binjs_encode_args=[]):
+    print(infile_path)
+
+    infile = open(infile_path)
+    outfile = open(outfile_path, 'w')
+
+    binjs_encode = subprocess.Popen([options.binjs_encode] + binjs_encode_args,
+                                    cwd=options.binjsdir,
+                                    stdin=infile, stdout=outfile)
+
+    if binjs_encode.wait() != 0:
+        print('binjs_encode failed',
+              file=sys.stderr)
+        sys.exit(1)
+
+def encode_inplace(dir, *args, **kwargs):
+    js_pat = re.compile('\.js$')
+    for root, dirs, files in os.walk(dir):
+        for filename in files:
+            if filename.endswith('.js'):
+                binjsfilename = js_pat.sub('.binjs', filename)
+                infile_path = os.path.join(root, filename)
+                outfile_path = os.path.join(root, binjsfilename)
+                encode(infile_path, outfile_path, *args, **kwargs)
+
+wpt_dir = os.path.join(options.topsrcdir, 'testing', 'web-platform')
+ensure_dir(wpt_dir, 'wpt')
+
+wpt_binast_dir = os.path.join(wpt_dir, 'mozilla', 'tests', 'binast')
+ensure_dir(wpt_binast_dir, 'binast in wpt')
+
+encode(os.path.join(wpt_binast_dir, 'large-binjs.js'),
+       os.path.join(wpt_binast_dir, 'large.binjs'))
+encode(os.path.join(wpt_binast_dir, 'small-binjs.js'),
+       os.path.join(wpt_binast_dir, 'small.binjs'))
+
+binast_test_dir = os.path.join(options.topsrcdir, 'js', 'src', 'jsapi-tests', 'binast')
+ensure_dir(binast_test_dir, 'binast in jsapi-tests')
+
+encode_inplace(os.path.join(binast_test_dir, 'parser', 'tester'),
+               binjs_encode_args=['advanced', 'expanded'])
+encode_inplace(os.path.join(binast_test_dir, 'parser', 'unit'),
+               binjs_encode_args=['advanced', 'expanded'])
+encode_inplace(os.path.join(binast_test_dir, 'parser', 'multipart'))