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 ConfigParser |
5 import errno | 6 import errno |
6 import glob | 7 import glob |
7 import io | 8 import io |
8 import json | 9 import json |
9 import os | 10 import os |
10 import re | 11 import re |
11 import struct | 12 import struct |
12 import subprocess | 13 import subprocess |
13 import sys | 14 import sys |
14 import random | 15 import random |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 ).encode('utf-8') + '\n' | 149 ).encode('utf-8') + '\n' |
149 | 150 |
150 | 151 |
151 def create_bundles(params, files, bundle_tests): | 152 def create_bundles(params, files, bundle_tests): |
152 base_extension_path = params['baseDir'] | 153 base_extension_path = params['baseDir'] |
153 info_templates = { | 154 info_templates = { |
154 'chrome': 'chromeInfo.js.tmpl', | 155 'chrome': 'chromeInfo.js.tmpl', |
155 'edge': 'edgeInfo.js.tmpl', | 156 'edge': 'edgeInfo.js.tmpl', |
156 'gecko': 'geckoInfo.js.tmpl', | 157 'gecko': 'geckoInfo.js.tmpl', |
157 } | 158 } |
| 159 aliases = { |
| 160 # To use our custom loader for the info module we must first set up an |
| 161 # alias to a file that exists. |
| 162 'info$': os.path.join(os.path.dirname(__file__), 'info.js'), |
| 163 # Prevent builtin Node.js modules from being used instead of our own |
| 164 # when the names clash. Once relative paths are used this won't be |
| 165 # necessary. |
| 166 'url$': 'url.js', |
| 167 'events$': 'events.js', |
| 168 'punycode$': 'punycode.js', |
| 169 } |
| 170 try: |
| 171 aliases.update(params['metadata'].items('module_alias')) |
| 172 except ConfigParser.NoSectionError: |
| 173 pass |
158 | 174 |
159 # Historically we didn't use relative paths when requiring modules, so in | 175 # Historically we didn't use relative paths when requiring modules, so in |
160 # order for webpack to know where to find them we need to pass in a list of | 176 # order for webpack to know where to find them we need to pass in a list of |
161 # resolve paths. Going forward we should always use relative paths, once we | 177 # resolve paths. Going forward we should always use relative paths, once we |
162 # do that consistently this can be removed. See issues 5760, 5761 and 5762. | 178 # do that consistently this can be removed. See issues 5760, 5761 and 5762. |
163 resolve_paths = [os.path.join(base_extension_path, dir, 'lib') | 179 resolve_paths = [os.path.join(base_extension_path, dir, 'lib') |
164 for dir in ['', 'adblockpluscore', 'adblockplusui']] | 180 for dir in ['', 'adblockpluscore', 'adblockplusui']] |
165 | 181 |
166 info_template = getTemplate(info_templates[params['type']]) | 182 info_template = getTemplate(info_templates[params['type']]) |
167 info_module = info_template.render( | 183 info_module = info_template.render( |
168 basename=params['metadata'].get('general', 'basename'), | 184 basename=params['metadata'].get('general', 'basename'), |
169 version=params['version'], | 185 version=params['version'], |
170 ).encode('utf-8') | 186 ).encode('utf-8') |
171 | 187 |
172 configuration = { | 188 configuration = { |
173 'bundles': [], | 189 'bundles': [], |
174 'extension_path': base_extension_path, | 190 'extension_path': base_extension_path, |
175 'info_module': info_module, | 191 'info_module': info_module, |
176 'resolve_paths': resolve_paths, | 192 'resolve_paths': resolve_paths, |
| 193 'aliases': aliases, |
177 } | 194 } |
178 | 195 |
179 for item in params['metadata'].items('bundles'): | 196 for item in params['metadata'].items('bundles'): |
180 name, value = item | 197 name, value = item |
181 base_item_path = os.path.dirname(item.source) | 198 base_item_path = os.path.dirname(item.source) |
182 | 199 |
183 bundle_file = os.path.relpath(os.path.join(base_item_path, name), | 200 bundle_file = os.path.relpath(os.path.join(base_item_path, name), |
184 base_extension_path) | 201 base_extension_path) |
185 entry_files = [os.path.join(base_item_path, module_path) | 202 entry_files = [os.path.join(base_item_path, module_path) |
186 for module_path in value.split()] | 203 for module_path in value.split()] |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 if devenv: | 404 if devenv: |
388 add_devenv_requirements(files, metadata, params) | 405 add_devenv_requirements(files, metadata, params) |
389 | 406 |
390 zipdata = files.zipToString() | 407 zipdata = files.zipToString() |
391 signature = None | 408 signature = None |
392 pubkey = None | 409 pubkey = None |
393 if keyFile != None: | 410 if keyFile != None: |
394 signature = signBinary(zipdata, keyFile) | 411 signature = signBinary(zipdata, keyFile) |
395 pubkey = getPublicKey(keyFile) | 412 pubkey = getPublicKey(keyFile) |
396 writePackage(outFile, pubkey, signature, zipdata) | 413 writePackage(outFile, pubkey, signature, zipdata) |
OLD | NEW |