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

Delta Between Two Patch Sets: packagerChrome.py

Issue 29501558: Issue 5383 - Add tests for the Chrome and Firefox packagers (Closed)
Left Patch Set: Adjusting tests to recent changes Created Oct. 11, 2017, 4:01 p.m.
Right Patch Set: Addressing Vasily's comments Created Oct. 22, 2017, 11:11 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « package.json ('k') | tests/README.md » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 import struct 11 import struct
12 import subprocess 12 import subprocess
13 import sys 13 import sys
14 import random
14 15
15 from packager import (readMetadata, getDefaultFileName, getBuildVersion, 16 from packager import (readMetadata, getDefaultFileName, getBuildVersion,
16 getTemplate, Files) 17 getTemplate, Files)
17 18
18 defaultLocale = 'en_US' 19 defaultLocale = 'en_US'
19 20
20 21
21 def getIgnoredFiles(params): 22 def getIgnoredFiles(params):
22 return {'store.description'} 23 return {'store.description'}
23 24
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 'bundle_name': bundle_file, 189 'bundle_name': bundle_file,
189 'entry_points': entry_files, 190 'entry_points': entry_files,
190 }) 191 })
191 192
192 cmd = ['node', os.path.join(os.path.dirname(__file__), 'webpack_runner.js')] 193 cmd = ['node', os.path.join(os.path.dirname(__file__), 'webpack_runner.js')]
193 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 194 process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
194 stdin=subprocess.PIPE) 195 stdin=subprocess.PIPE)
195 output = process.communicate(input=toJson(configuration))[0] 196 output = process.communicate(input=toJson(configuration))[0]
196 if process.returncode != 0: 197 if process.returncode != 0:
197 raise subprocess.CalledProcessError(process.returncode, cmd=cmd) 198 raise subprocess.CalledProcessError(process.returncode, cmd=cmd)
198 199 output = json.loads(output)
199 bundles = json.loads(output) 200
200 for bundle in bundles: 201 # Clear the mapping for any files included in a bundle, to avoid them being
201 files[bundle[1:]] = bundles[bundle].encode('utf-8') 202 # duplicated in the build.
203 for to_ignore in output['included']:
204 files.pop(to_ignore, None)
205
206 for bundle in output['files']:
207 files[bundle] = output['files'][bundle].encode('utf-8')
202 208
203 209
204 def import_locales(params, files): 210 def import_locales(params, files):
205 for item in params['metadata'].items('import_locales'): 211 for item in params['metadata'].items('import_locales'):
206 filename, keys = item 212 filename, keys = item
207 for sourceFile in glob.glob(os.path.join(os.path.dirname(item.source), 213 for sourceFile in glob.glob(os.path.join(os.path.dirname(item.source),
208 *filename.split('/'))): 214 *filename.split('/'))):
209 locale = sourceFile.split(os.path.sep)[-2] 215 locale = sourceFile.split(os.path.sep)[-2]
210 targetFile = os.path.join('_locales', locale, 'messages.json') 216 targetFile = os.path.join('_locales', locale, 'messages.json')
211 data = json.loads(files.get(targetFile, '{}').decode('utf-8')) 217 data = json.loads(files.get(targetFile, '{}').decode('utf-8'))
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 file = open(outputFile, 'wb') 314 file = open(outputFile, 'wb')
309 else: 315 else:
310 file = outputFile 316 file = outputFile
311 if pubkey != None and signature != None: 317 if pubkey != None and signature != None:
312 file.write(struct.pack('<4sIII', 'Cr24', 2, len(pubkey), len(signature)) ) 318 file.write(struct.pack('<4sIII', 'Cr24', 2, len(pubkey), len(signature)) )
313 file.write(pubkey) 319 file.write(pubkey)
314 file.write(signature) 320 file.write(signature)
315 file.write(zipdata) 321 file.write(zipdata)
316 322
317 323
324 def add_devenv_requirements(files, metadata, params):
325 files.read(
326 os.path.join(os.path.dirname(__file__), 'chromeDevenvPoller__.js'),
327 relpath='devenvPoller__.js',
328 )
329 files['devenvVersion__'] = str(random.random())
330
331 if metadata.has_option('general', 'testScripts'):
332 files['qunit/index.html'] = createScriptPage(
333 params, 'testIndex.html.tmpl', ('general', 'testScripts')
334 )
335
336
318 def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuil d=False, keyFile=None, devenv=False): 337 def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuil d=False, keyFile=None, devenv=False):
319 metadata = readMetadata(baseDir, type) 338 metadata = readMetadata(baseDir, type)
320 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) 339 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum)
321 340
322 if outFile == None: 341 if outFile == None:
323 if type == 'gecko': 342 if type == 'gecko':
324 file_extension = 'xpi' 343 file_extension = 'xpi'
325 else: 344 else:
326 file_extension = 'crx' if keyFile else 'zip' 345 file_extension = 'crx' if keyFile else 'zip'
327 outFile = getDefaultFileName(metadata, version, file_extension) 346 outFile = getDefaultFileName(metadata, version, file_extension)
(...skipping 24 matching lines...) Expand all
352 ) 371 )
353 372
354 if metadata.has_section('import_locales'): 373 if metadata.has_section('import_locales'):
355 import_locales(params, files) 374 import_locales(params, files)
356 375
357 files['manifest.json'] = createManifest(params, files) 376 files['manifest.json'] = createManifest(params, files)
358 if type == 'chrome': 377 if type == 'chrome':
359 fix_translations_for_chrome(files) 378 fix_translations_for_chrome(files)
360 379
361 if devenv: 380 if devenv:
362 import buildtools 381 add_devenv_requirements(files, metadata, params)
363 import random
364 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js '), relpath='devenvPoller__.js')
365 files['devenvVersion__'] = str(random.random())
366
367 if metadata.has_option('general', 'testScripts'):
368 files['qunit/index.html'] = createScriptPage(
369 params, 'testIndex.html.tmpl', ('general', 'testScripts')
370 )
371 382
372 zipdata = files.zipToString() 383 zipdata = files.zipToString()
373 signature = None 384 signature = None
374 pubkey = None 385 pubkey = None
375 if keyFile != None: 386 if keyFile != None:
376 signature = signBinary(zipdata, keyFile) 387 signature = signBinary(zipdata, keyFile)
377 pubkey = getPublicKey(keyFile) 388 pubkey = getPublicKey(keyFile)
378 writePackage(outFile, pubkey, signature, zipdata) 389 writePackage(outFile, pubkey, signature, zipdata)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld