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

Side by Side Diff: packagerChrome.py

Issue 29600577: Issue 5997 - Avoid including qunit files in release builds (Closed)
Patch Set: Avoid bundling tests if testScripts option is missing Created Nov. 7, 2017, 4:04 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
« no previous file with comments | « no previous file | packagerEdge.py » ('j') | tests/test_packagerWebExt.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 glob 6 import glob
7 import io 7 import io
8 import json 8 import json
9 import os 9 import os
10 import re 10 import re
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return manifest.encode('utf-8') 143 return manifest.encode('utf-8')
144 144
145 145
146 def toJson(data): 146 def toJson(data):
147 return json.dumps( 147 return json.dumps(
148 data, ensure_ascii=False, sort_keys=True, 148 data, ensure_ascii=False, sort_keys=True,
149 indent=2, separators=(',', ': ') 149 indent=2, separators=(',', ': ')
150 ).encode('utf-8') + '\n' 150 ).encode('utf-8') + '\n'
151 151
152 152
153 def create_bundles(params, files): 153 def create_bundles(params, files, bundle_tests):
154 base_extension_path = params['baseDir'] 154 base_extension_path = params['baseDir']
155 info_templates = { 155 info_templates = {
156 'chrome': 'chromeInfo.js.tmpl', 156 'chrome': 'chromeInfo.js.tmpl',
157 'edge': 'edgeInfo.js.tmpl', 157 'edge': 'edgeInfo.js.tmpl',
158 'gecko': 'geckoInfo.js.tmpl' 158 'gecko': 'geckoInfo.js.tmpl'
159 } 159 }
160 160
161 # Historically we didn't use relative paths when requiring modules, so in 161 # Historically we didn't use relative paths when requiring modules, so in
162 # order for webpack to know where to find them we need to pass in a list of 162 # order for webpack to know where to find them we need to pass in a list of
163 # resolve paths. Going forward we should always use relative paths, once we 163 # resolve paths. Going forward we should always use relative paths, once we
(...skipping 20 matching lines...) Expand all
184 184
185 bundle_file = os.path.relpath(os.path.join(base_item_path, name), 185 bundle_file = os.path.relpath(os.path.join(base_item_path, name),
186 base_extension_path) 186 base_extension_path)
187 entry_files = [os.path.join(base_item_path, module_path) 187 entry_files = [os.path.join(base_item_path, module_path)
188 for module_path in value.split()] 188 for module_path in value.split()]
189 configuration['bundles'].append({ 189 configuration['bundles'].append({
190 'bundle_name': bundle_file, 190 'bundle_name': bundle_file,
191 'entry_points': entry_files, 191 'entry_points': entry_files,
192 }) 192 })
193 193
194 if bundle_tests:
195 qunit_path = os.path.join(base_extension_path, 'qunit')
196 qunit_files = ([os.path.join(qunit_path, 'common.js')] +
197 glob.glob(os.path.join(qunit_path, 'tests', '*.js')))
198 configuration['bundles'].append({
199 'bundle_name': 'qunit/tests.js',
200 'entry_points': qunit_files
201 })
202
194 cmd = ['node', os.path.join(os.path.dirname(__file__), 'webpack_runner.js')] 203 cmd = ['node', os.path.join(os.path.dirname(__file__), 'webpack_runner.js')]
195 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 204 process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
196 stdin=subprocess.PIPE) 205 stdin=subprocess.PIPE)
197 output = process.communicate(input=toJson(configuration))[0] 206 output = process.communicate(input=toJson(configuration))[0]
198 if process.returncode != 0: 207 if process.returncode != 0:
199 raise subprocess.CalledProcessError(process.returncode, cmd=cmd) 208 raise subprocess.CalledProcessError(process.returncode, cmd=cmd)
200 output = json.loads(output) 209 output = json.loads(output)
201 210
202 # Clear the mapping for any files included in a bundle, to avoid them being 211 # Clear the mapping for any files included in a bundle, to avoid them being
203 # duplicated in the build. 212 # duplicated in the build.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 366 }
358 367
359 mapped = metadata.items('mapping') if metadata.has_section('mapping') else [ ] 368 mapped = metadata.items('mapping') if metadata.has_section('mapping') else [ ]
360 files = Files(getPackageFiles(params), getIgnoredFiles(params), 369 files = Files(getPackageFiles(params), getIgnoredFiles(params),
361 process=lambda path, data: processFile(path, data, params)) 370 process=lambda path, data: processFile(path, data, params))
362 371
363 files.readMappedFiles(mapped) 372 files.readMappedFiles(mapped)
364 files.read(baseDir, skip=[opt for opt, _ in mapped]) 373 files.read(baseDir, skip=[opt for opt, _ in mapped])
365 374
366 if metadata.has_section('bundles'): 375 if metadata.has_section('bundles'):
367 create_bundles(params, files) 376 bundle_tests = devenv and metadata.has_option('general', 'testScripts')
377 create_bundles(params, files, bundle_tests)
368 378
369 if metadata.has_section('preprocess'): 379 if metadata.has_section('preprocess'):
370 files.preprocess( 380 files.preprocess(
371 [f for f, _ in metadata.items('preprocess')], 381 [f for f, _ in metadata.items('preprocess')],
372 {'needsExt': True} 382 {'needsExt': True}
373 ) 383 )
374 384
375 if metadata.has_section('import_locales'): 385 if metadata.has_section('import_locales'):
376 import_locales(params, files) 386 import_locales(params, files)
377 387
378 files['manifest.json'] = createManifest(params, files) 388 files['manifest.json'] = createManifest(params, files)
379 if type == 'chrome': 389 if type == 'chrome':
380 fix_translations_for_chrome(files) 390 fix_translations_for_chrome(files)
381 391
382 if devenv: 392 if devenv:
383 add_devenv_requirements(files, metadata, params) 393 add_devenv_requirements(files, metadata, params)
tlucas 2017/11/08 12:08:51 I wonder if this is/should be handled by webpack a
kzar 2017/11/09 15:33:16 Well I agree it's kind of ugly how there are two s
tlucas 2017/11/09 16:29:49 Acknowledged.
384 394
385 zipdata = files.zipToString() 395 zipdata = files.zipToString()
386 signature = None 396 signature = None
387 pubkey = None 397 pubkey = None
388 if keyFile != None: 398 if keyFile != None:
389 signature = signBinary(zipdata, keyFile) 399 signature = signBinary(zipdata, keyFile)
390 pubkey = getPublicKey(keyFile) 400 pubkey = getPublicKey(keyFile)
391 writePackage(outFile, pubkey, signature, zipdata) 401 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW
« no previous file with comments | « no previous file | packagerEdge.py » ('j') | tests/test_packagerWebExt.py » ('J')

Powered by Google App Engine
This is Rietveld