LEFT | RIGHT |
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 from StringIO import StringIO | |
12 import struct | 11 import struct |
13 import subprocess | 12 import subprocess |
14 import sys | 13 import sys |
| 14 import random |
15 | 15 |
16 from packager import (readMetadata, getDefaultFileName, getBuildVersion, | 16 from packager import (readMetadata, getDefaultFileName, getBuildVersion, |
17 getTemplate, Files) | 17 getTemplate, Files) |
18 | 18 |
19 defaultLocale = 'en_US' | 19 defaultLocale = 'en_US' |
20 | 20 |
21 | 21 |
22 def getIgnoredFiles(params): | 22 def getIgnoredFiles(params): |
23 return {'store.description'} | 23 return {'store.description'} |
24 | 24 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 'bundle_name': bundle_file, | 189 'bundle_name': bundle_file, |
190 'entry_points': entry_files, | 190 'entry_points': entry_files, |
191 }) | 191 }) |
192 | 192 |
193 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')] |
194 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, | 194 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
195 stdin=subprocess.PIPE) | 195 stdin=subprocess.PIPE) |
196 output = process.communicate(input=toJson(configuration))[0] | 196 output = process.communicate(input=toJson(configuration))[0] |
197 if process.returncode != 0: | 197 if process.returncode != 0: |
198 raise subprocess.CalledProcessError(process.returncode, cmd=cmd) | 198 raise subprocess.CalledProcessError(process.returncode, cmd=cmd) |
199 | 199 output = json.loads(output) |
200 bundles = json.loads(output) | 200 |
201 for bundle in bundles: | 201 # Clear the mapping for any files included in a bundle, to avoid them being |
202 files[bundle] = 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') |
203 | 208 |
204 | 209 |
205 def import_locales(params, files): | 210 def import_locales(params, files): |
206 for item in params['metadata'].items('import_locales'): | 211 for item in params['metadata'].items('import_locales'): |
207 filename, keys = item | 212 filename, keys = item |
208 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), |
209 *filename.split('/'))): | 214 *filename.split('/'))): |
210 locale = sourceFile.split(os.path.sep)[-2] | 215 locale = sourceFile.split(os.path.sep)[-2] |
211 targetFile = os.path.join('_locales', locale, 'messages.json') | 216 targetFile = os.path.join('_locales', locale, 'messages.json') |
212 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 Loading... |
309 file = open(outputFile, 'wb') | 314 file = open(outputFile, 'wb') |
310 else: | 315 else: |
311 file = outputFile | 316 file = outputFile |
312 if pubkey != None and signature != None: | 317 if pubkey != None and signature != None: |
313 file.write(struct.pack('<4sIII', 'Cr24', 2, len(pubkey), len(signature))
) | 318 file.write(struct.pack('<4sIII', 'Cr24', 2, len(pubkey), len(signature))
) |
314 file.write(pubkey) | 319 file.write(pubkey) |
315 file.write(signature) | 320 file.write(signature) |
316 file.write(zipdata) | 321 file.write(zipdata) |
317 | 322 |
318 | 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 |
319 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): |
320 metadata = readMetadata(baseDir, type) | 338 metadata = readMetadata(baseDir, type) |
321 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) | 339 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) |
322 | 340 |
323 if outFile == None: | 341 if outFile == None: |
324 if type == 'gecko': | 342 if type == 'gecko': |
325 file_extension = 'xpi' | 343 file_extension = 'xpi' |
326 else: | 344 else: |
327 file_extension = 'crx' if keyFile else 'zip' | 345 file_extension = 'crx' if keyFile else 'zip' |
328 outFile = getDefaultFileName(metadata, version, file_extension) | 346 outFile = getDefaultFileName(metadata, version, file_extension) |
(...skipping 24 matching lines...) Expand all Loading... |
353 ) | 371 ) |
354 | 372 |
355 if metadata.has_section('import_locales'): | 373 if metadata.has_section('import_locales'): |
356 import_locales(params, files) | 374 import_locales(params, files) |
357 | 375 |
358 files['manifest.json'] = createManifest(params, files) | 376 files['manifest.json'] = createManifest(params, files) |
359 if type == 'chrome': | 377 if type == 'chrome': |
360 fix_translations_for_chrome(files) | 378 fix_translations_for_chrome(files) |
361 | 379 |
362 if devenv: | 380 if devenv: |
363 import buildtools | 381 add_devenv_requirements(files, metadata, params) |
364 import random | |
365 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js
'), relpath='devenvPoller__.js') | |
366 files['devenvVersion__'] = str(random.random()) | |
367 | |
368 if metadata.has_option('general', 'testScripts'): | |
369 files['qunit/index.html'] = createScriptPage( | |
370 params, 'testIndex.html.tmpl', ('general', 'testScripts') | |
371 ) | |
372 | 382 |
373 zipdata = files.zipToString() | 383 zipdata = files.zipToString() |
374 signature = None | 384 signature = None |
375 pubkey = None | 385 pubkey = None |
376 if keyFile != None: | 386 if keyFile != None: |
377 signature = signBinary(zipdata, keyFile) | 387 signature = signBinary(zipdata, keyFile) |
378 pubkey = getPublicKey(keyFile) | 388 pubkey = getPublicKey(keyFile) |
379 writePackage(outFile, pubkey, signature, zipdata) | 389 writePackage(outFile, pubkey, signature, zipdata) |
LEFT | RIGHT |