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 = {} |
151 | 149 |
152 for item in params['metadata'].items('convert_js'): | 150 for item in params['metadata'].items('convert_js'): |
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.setdefault(filename, {})[arg] = item[1] |
| 156 |
| 157 template = getTemplate('modules.js.tmpl') |
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 current_args = args.get(filename, {}) |
| 164 current_args['autoload'] = [module for module in |
| 165 current_args.get('autoload', '').split(',') |
| 166 if module != ''] |
| 167 |
163 base_dir = os.path.dirname(origin) | 168 base_dir = os.path.dirname(origin) |
164 jshydra_args = ['--arg', ' '.join(args[filename])] | 169 modules = [] |
165 | 170 |
166 for input_filename in input_files: | 171 for input_filename in input_files: |
167 jshydra_args.append(os.path.join(base_dir, input_filename)) | 172 module_name = os.path.splitext(os.path.basename(input_filename))[0] |
| 173 prefix = os.path.basename(os.path.dirname(input_filename)) |
| 174 if prefix != 'lib': |
| 175 module_name = '{}_{}'.format(prefix, module_name) |
| 176 with open(os.path.join(base_dir, input_filename), 'r') as file: |
| 177 modules.append((module_name, file.read().decode('utf-8'))) |
168 files.pop(input_filename, None) | 178 files.pop(input_filename, None) |
169 | 179 |
170 files[filename] = rewrite_js(jshydra_args) | 180 files[filename] = template.render( |
| 181 args=current_args, |
| 182 modules=modules |
| 183 ).encode('utf-8') |
171 | 184 |
172 | 185 |
173 def toJson(data): | 186 def toJson(data): |
174 return json.dumps( | 187 return json.dumps( |
175 data, ensure_ascii=False, sort_keys=True, | 188 data, ensure_ascii=False, sort_keys=True, |
176 indent=2, separators=(',', ': ') | 189 indent=2, separators=(',', ': ') |
177 ).encode('utf-8') + '\n' | 190 ).encode('utf-8') + '\n' |
178 | 191 |
179 | 192 |
180 def importGeckoLocales(params, files): | 193 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', | 397 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp
l', |
385 ('general', 'testScripts')) | 398 ('general', 'testScripts')) |
386 | 399 |
387 zipdata = files.zipToString() | 400 zipdata = files.zipToString() |
388 signature = None | 401 signature = None |
389 pubkey = None | 402 pubkey = None |
390 if keyFile != None: | 403 if keyFile != None: |
391 signature = signBinary(zipdata, keyFile) | 404 signature = signBinary(zipdata, keyFile) |
392 pubkey = getPublicKey(keyFile) | 405 pubkey = getPublicKey(keyFile) |
393 writePackage(outFile, pubkey, signature, zipdata) | 406 writePackage(outFile, pubkey, signature, zipdata) |
OLD | NEW |