 Issue 29363565:
  Issue 4552 - Drop jshydra dependency (buildtools)  (Closed)
    
  
    Issue 29363565:
  Issue 4552 - Drop jshydra dependency (buildtools)  (Closed) 
  | Left: | ||
| Right: | 
| OLD | NEW | 
|---|---|
| 1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public | 
| 2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 
| 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 
| 4 | 4 | 
| 5 import errno | 5 import errno | 
| 6 import io | 6 import io | 
| 7 import json | 7 import json | 
| 8 import os | 8 import os | 
| 9 import re | 9 import re | 
| 10 from StringIO import StringIO | 10 from StringIO import StringIO | 
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 137 | 
| 138 return manifest.encode('utf-8') | 138 return manifest.encode('utf-8') | 
| 139 | 139 | 
| 140 | 140 | 
| 141 def createInfoModule(params): | 141 def createInfoModule(params): | 
| 142 template = getTemplate('chromeInfo.js.tmpl') | 142 template = getTemplate('chromeInfo.js.tmpl') | 
| 143 return template.render(params).encode('utf-8') | 143 return template.render(params).encode('utf-8') | 
| 144 | 144 | 
| 145 | 145 | 
| 146 def convertJS(params, files): | 146 def convertJS(params, files): | 
| 147 from jshydra.abp_rewrite import rewrite_js | |
| 148 | |
| 149 output_files = collections.OrderedDict() | 147 output_files = collections.OrderedDict() | 
| 150 args = collections.defaultdict(list) | 148 args = collections.defaultdict(dict) | 
| 151 | 149 | 
| 152 for item in params['metadata'].items('convert_js'): | 150 for item in params['metadata'].items('convert_js'): | 
| 
Wladimir Palant
2016/11/30 14:54:44
Nit: `for name, value in ...`? This should make th
 
kzar
2016/11/30 15:26:17
Well we need item still for `item.source`. How abo
 | |
| 153 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', item[0]).groups() | 151 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', item[0]).groups() | 
| 154 if arg is None: | 152 if arg is None: | 
| 155 output_files[filename] = (item[1].split(), item.source) | 153 output_files[filename] = (item[1].split(), item.source) | 
| 156 else: | 154 else: | 
| 157 args[filename].append('{}={}'.format(arg, item[1])) | 155 args[filename][arg] = item[1] | 
| 
Wladimir Palant
2016/11/30 11:39:32
Nit: Frankly, I'd prefer `args.setdefault(filename
 
kzar
2016/11/30 14:29:44
Done.
 | |
| 156 | |
| 157 template = getTemplate('modules.js.tmpl', autoEscape=True) | |
| 
Wladimir Palant
2016/11/30 11:39:32
Please remove autoEscape=True, this isn't an HTML
 
kzar
2016/11/30 14:29:44
Done.
 | |
| 158 | 158 | 
| 159 for filename, (input_files, origin) in output_files.iteritems(): | 159 for filename, (input_files, origin) in output_files.iteritems(): | 
| 160 if '/' in filename and not files.isIncluded(filename): | 160 if '/' in filename and not files.isIncluded(filename): | 
| 161 continue | 161 continue | 
| 162 | 162 | 
| 163 args["filename"]["autoload"] = set(args.get("autoload", "").split(",")) | |
| 
Wladimir Palant
2016/11/30 11:39:32
This line has three bugs, I assume that it hasn't
 
kzar
2016/11/30 14:29:44
Ouch, done.
 | |
| 164 | |
| 163 base_dir = os.path.dirname(origin) | 165 base_dir = os.path.dirname(origin) | 
| 164 jshydra_args = ['--arg', ' '.join(args[filename])] | 166 modules = [] | 
| 
kzar
2016/11/18 17:25:48
List of tuples instead of a dict since the module
 | |
| 165 | 167 | 
| 166 for input_filename in input_files: | 168 for input_filename in input_files: | 
| 167 jshydra_args.append(os.path.join(base_dir, input_filename)) | 169 module_name = os.path.splitext(os.path.basename(input_filename))[0] | 
| 170 prefix = os.path.basename(os.path.dirname(input_filename)) | |
| 171 if prefix != "lib": | |
| 172 module_name = "{}_{}".format(prefix, module_name) | |
| 173 with open(os.path.join(base_dir, input_filename), 'r') as f: | |
| 
Wladimir Palant
2016/11/30 11:39:32
Nit: file rather than f?
 
kzar
2016/11/30 14:29:44
Done.
 | |
| 174 modules.append((module_name, f.read().decode('utf-8'))) | |
| 168 files.pop(input_filename, None) | 175 files.pop(input_filename, None) | 
| 169 | 176 | 
| 170 files[filename] = rewrite_js(jshydra_args) | 177 files[filename] = template.render( | 
| 178 args=args[filename], | |
| 179 modules=modules | |
| 180 ).encode('utf-8') | |
| 171 | 181 | 
| 172 | 182 | 
| 173 def toJson(data): | 183 def toJson(data): | 
| 174 return json.dumps( | 184 return json.dumps( | 
| 175 data, ensure_ascii=False, sort_keys=True, | 185 data, ensure_ascii=False, sort_keys=True, | 
| 176 indent=2, separators=(',', ': ') | 186 indent=2, separators=(',', ': ') | 
| 177 ).encode('utf-8') + '\n' | 187 ).encode('utf-8') + '\n' | 
| 178 | 188 | 
| 179 | 189 | 
| 180 def importGeckoLocales(params, files): | 190 def importGeckoLocales(params, files): | 
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l', | 394 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l', | 
| 385 ('general', 'testScripts')) | 395 ('general', 'testScripts')) | 
| 386 | 396 | 
| 387 zipdata = files.zipToString() | 397 zipdata = files.zipToString() | 
| 388 signature = None | 398 signature = None | 
| 389 pubkey = None | 399 pubkey = None | 
| 390 if keyFile != None: | 400 if keyFile != None: | 
| 391 signature = signBinary(zipdata, keyFile) | 401 signature = signBinary(zipdata, keyFile) | 
| 392 pubkey = getPublicKey(keyFile) | 402 pubkey = getPublicKey(keyFile) | 
| 393 writePackage(outFile, pubkey, signature, zipdata) | 403 writePackage(outFile, pubkey, signature, zipdata) | 
| OLD | NEW |