Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: packagerChrome.py

Issue 29549786: Issue 5535 - Replace our module system with webpack (Closed)
Patch Set: Expose stats Object Created Oct. 3, 2017, 3:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 import shutil
11 from StringIO import StringIO 10 from StringIO import StringIO
12 import struct 11 import struct
13 import subprocess 12 import subprocess
14 import sys 13 import sys
15 import tempfile
16 14
17 from ensure_dependencies import read_deps 15 from ensure_dependencies import read_deps
18 from packager import (readMetadata, getDefaultFileName, getBuildVersion, 16 from packager import (readMetadata, getDefaultFileName, getBuildVersion,
19 getTemplate, Files) 17 getTemplate, Files)
20 18
21 defaultLocale = 'en_US' 19 defaultLocale = 'en_US'
22 20
23 21
24 def getIgnoredFiles(params): 22 def getIgnoredFiles(params):
25 return {'store.description'} 23 return {'store.description'}
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return manifest.encode('utf-8') 140 return manifest.encode('utf-8')
143 141
144 142
145 def create_bundles(params, files): 143 def create_bundles(params, files):
146 base_extension_path = params['baseDir'] 144 base_extension_path = params['baseDir']
147 info_templates = { 145 info_templates = {
148 'chrome': 'chromeInfo.js.tmpl', 146 'chrome': 'chromeInfo.js.tmpl',
149 'edge': 'edgeInfo.js.tmpl', 147 'edge': 'edgeInfo.js.tmpl',
150 'gecko-webext': 'geckoInfo.js.tmpl' 148 'gecko-webext': 'geckoInfo.js.tmpl'
151 } 149 }
152 info_module = None
153 150
154 # Historically we didn't use relative paths when requiring modules, so in 151 # Historically we didn't use relative paths when requiring modules, so in
155 # order for webpack to know where to find them we need to pass in a list of 152 # order for webpack to know where to find them we need to pass in a list of
156 # resolve paths. Going forward we should always use relative paths, once we 153 # resolve paths. Going forward we should always use relative paths, once we
157 # do that consistently this can be removed. See issues 5760, 5761 and 5762. 154 # do that consistently this can be removed. See issues 5760, 5761 and 5762.
158 resolve_paths = ' '.join( 155 resolve_paths = ' '.join(
159 [os.path.join(base_extension_path, dir, 'lib') 156 [os.path.join(base_extension_path, dir, 'lib')
160 for dir in ['', 'adblockpluscore', 'adblockplusui']] 157 for dir in ['', 'adblockpluscore', 'adblockplusui']]
161 ) 158 )
162 159
163 temp_dir = tempfile.mkdtemp() 160 template = getTemplate(info_templates[params['type']])
Wladimir Palant 2017/10/04 10:38:06 Nit: this variable is better named info_template I
kzar 2017/10/04 13:13:25 Done.
164 try: 161 info_module = template.render(
165 info_module = os.path.join(temp_dir, 'info.js') 162 basename=params['metadata'].get('general', 'basename'),
166 template = getTemplate(info_templates[params['type']]) 163 version=params['metadata'].get('general', 'version')
167 with open(info_module, 'w') as info_file: 164 ).encode('utf-8')
168 info_file.write(
169 template.render(
170 basename=params['metadata'].get('general', 'basename'),
171 version=params['metadata'].get('general', 'version')
172 ).encode('utf-8')
173 )
174 165
175 for item in params['metadata'].items('bundles'): 166 for item in params['metadata'].items('bundles'):
176 name, value = item 167 name, value = item
177 base_item_path = os.path.dirname(item.source) 168 base_item_path = os.path.dirname(item.source)
178 169
179 bundle_file = os.path.relpath(os.path.join(base_item_path, name), 170 bundle_file = os.path.relpath(os.path.join(base_item_path, name),
180 base_extension_path) 171 base_extension_path)
181 entry_files = [os.path.join(base_item_path, module_path) 172 entry_files = [os.path.join(base_item_path, module_path)
182 for module_path in value.split()] 173 for module_path in value.split()]
183 subprocess.check_call( 174 files[bundle_file] = subprocess.check_output(
184 ['npm', 'run-script', 'webpack', '--silent'], 175 ['node', 'webpack_runner.js'],
185 cwd=os.path.dirname(__file__), 176 cwd=os.path.dirname(__file__),
Wladimir Palant 2017/10/04 10:38:06 I'd prefer an absolute path to webpack_runner.js i
kzar 2017/10/04 13:13:24 Done.
186 env={ 177 env={
187 'EXTENSION_PATH': base_extension_path, 178 'EXTENSION_PATH': base_extension_path,
188 'ENTRY_POINTS': ' '.join(entry_files), 179 'ENTRY_POINTS': ' '.join(entry_files),
Wladimir Palant 2017/10/04 10:38:06 This will break for paths containing spaces.
kzar 2017/10/04 13:13:24 Whoops, good point.
189 'OUTPUT_PATH': temp_dir, 180 'BUNDLE_NAME': bundle_file,
190 'BUNDLE_NAME': bundle_file, 181 'RESOLVE_PATHS': resolve_paths,
191 'RESOLVE_PATHS': resolve_paths, 182 'INFO_MODULE': info_module,
Wladimir Palant 2017/10/04 10:38:06 Why do we still need to pass data via environment
kzar 2017/10/04 13:13:24 Done.
192 'INFO_PATH': info_module, 183 'PATH': os.environ['PATH']
193 'PATH': os.environ['PATH'] 184 }
194 } 185 )
195 )
196 for file_name in [bundle_file, bundle_file + '.map']:
197 with open(os.path.join(temp_dir, file_name), 'r') as f:
198 files[file_name] = f.read()
199 finally:
200 shutil.rmtree(temp_dir)
201 186
202 187
203 def toJson(data): 188 def toJson(data):
204 return json.dumps( 189 return json.dumps(
205 data, ensure_ascii=False, sort_keys=True, 190 data, ensure_ascii=False, sort_keys=True,
206 indent=2, separators=(',', ': ') 191 indent=2, separators=(',', ': ')
207 ).encode('utf-8') + '\n' 192 ).encode('utf-8') + '\n'
208 193
209 194
210 def import_string_webext(data, key, source): 195 def import_string_webext(data, key, source):
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 params, 'testIndex.html.tmpl', ('general', 'testScripts') 418 params, 'testIndex.html.tmpl', ('general', 'testScripts')
434 ) 419 )
435 420
436 zipdata = files.zipToString() 421 zipdata = files.zipToString()
437 signature = None 422 signature = None
438 pubkey = None 423 pubkey = None
439 if keyFile != None: 424 if keyFile != None:
440 signature = signBinary(zipdata, keyFile) 425 signature = signBinary(zipdata, keyFile)
441 pubkey = getPublicKey(keyFile) 426 pubkey = getPublicKey(keyFile)
442 writePackage(outFile, pubkey, signature, zipdata) 427 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW
« no previous file with comments | « package.json ('k') | webpack.config.js » ('j') | webpack_runner.js » ('J')

Powered by Google App Engine
This is Rietveld