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