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

Side by Side Diff: build.py

Issue 29562599: Issue 5751 - Removing legacy gecko support (Closed)
Patch Set: Created Oct. 2, 2017, 10:33 a.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 | lib/hooks.js » ('j') | localeTools.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 os 5 import os
6 import sys 6 import sys
7 import re 7 import re
8 import subprocess 8 import subprocess
9 import shutil 9 import shutil
10 import buildtools 10 import buildtools
11 from getopt import getopt, GetoptError 11 from getopt import getopt, GetoptError
12 from StringIO import StringIO 12 from StringIO import StringIO
13 from zipfile import ZipFile 13 from zipfile import ZipFile
14 14
15 knownTypes = ('gecko', 'gecko-webext', 'chrome', 'safari', 'generic', 'edge') 15 knownTypes = ('gecko-webext', 'chrome', 'safari', 'generic', 'edge')
16 16
17 17
18 class Command(object): 18 class Command(object):
19 name = property(lambda self: self._name) 19 name = property(lambda self: self._name)
20 shortDescription = property( 20 shortDescription = property(
21 lambda self: self._shortDescription, 21 lambda self: self._shortDescription,
22 lambda self, value: self.__dict__.update({'_shortDescription': value}) 22 lambda self, value: self.__dict__.update({'_shortDescription': value})
23 ) 23 )
24 description = property( 24 description = property(
25 lambda self: self._description, 25 lambda self: self._description,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 'name': command.name, 171 'name': command.name,
172 'params': command.params, 172 'params': command.params,
173 'description': description, 173 'description': description,
174 'options': '\n'.join(options) 174 'options': '\n'.join(options)
175 } 175 }
176 176
177 177
178 def runBuild(baseDir, scriptName, opts, args, type): 178 def runBuild(baseDir, scriptName, opts, args, type):
179 kwargs = {} 179 kwargs = {}
180 for option, value in opts: 180 for option, value in opts:
181 if option in {'-l', '--locales'} and type == 'gecko': 181 if option in {'-b', '--build'}:
182 kwargs['locales'] = value.split(',')
183 elif option in {'-b', '--build'}:
184 kwargs['buildNum'] = value 182 kwargs['buildNum'] = value
185 no_gecko_build = type not in {'gecko', 'gecko-webext'} 183 no_gecko_build = type != 'gecko-webext'
Sebastian Noack 2017/10/03 02:22:39 I guess we don't need this variable anymore to avo
tlucas 2017/10/04 11:48:38 Done.
186 if no_gecko_build and not kwargs['buildNum'].isdigit(): 184 if no_gecko_build and not kwargs['buildNum'].isdigit():
187 raise TypeError('Build number must be numerical') 185 raise TypeError('Build number must be numerical')
188 elif option in {'-k', '--key'}: 186 elif option in {'-k', '--key'}:
189 kwargs['keyFile'] = value 187 kwargs['keyFile'] = value
190 elif option in {'-m', '--multi-compartment'} and type == 'gecko':
191 kwargs['multicompartment'] = True
192 elif option in {'-r', '--release'}: 188 elif option in {'-r', '--release'}:
193 kwargs['releaseBuild'] = True 189 kwargs['releaseBuild'] = True
194 if len(args) > 0: 190 if len(args) > 0:
195 kwargs['outFile'] = args[0] 191 kwargs['outFile'] = args[0]
196 192
197 if type == 'gecko': 193 if type in {'chrome', 'gecko-webext'}:
198 import buildtools.packagerGecko as packager
199 elif type in {'chrome', 'gecko-webext'}:
200 import buildtools.packagerChrome as packager 194 import buildtools.packagerChrome as packager
201 elif type == 'safari': 195 elif type == 'safari':
202 import buildtools.packagerSafari as packager 196 import buildtools.packagerSafari as packager
203 elif type == 'edge': 197 elif type == 'edge':
204 import buildtools.packagerEdge as packager 198 import buildtools.packagerEdge as packager
205 199
206 packager.createBuild(baseDir, type=type, **kwargs) 200 packager.createBuild(baseDir, type=type, **kwargs)
207 201
208 202
209 def runAutoInstall(baseDir, scriptName, opts, args, type):
210 if len(args) == 0:
211 print 'Port of the Extension Auto-Installer needs to be specified'
212 usage(scriptName, type, 'autoinstall')
213 return
214
215 multicompartment = False
216 for option, value in opts:
217 if option in ('-m', '--multi-compartment'):
218 multicompartment = True
219
220 if ':' in args[0]:
221 host, port = args[0].rsplit(':', 1)
222 else:
223 host, port = ('localhost', args[0])
224
225 import buildtools.packagerGecko as packager
226 packager.autoInstall(baseDir, type, host, port, multicompartment=multicompar tment)
227
228
229 def createDevEnv(baseDir, scriptName, opts, args, type): 203 def createDevEnv(baseDir, scriptName, opts, args, type):
230 if type == 'safari': 204 if type == 'safari':
231 import buildtools.packagerSafari as packager 205 import buildtools.packagerSafari as packager
232 else: 206 else:
233 import buildtools.packagerChrome as packager 207 import buildtools.packagerChrome as packager
234 208
235 file = StringIO() 209 file = StringIO()
236 packager.createBuild(baseDir, type=type, outFile=file, devenv=True, releaseB uild=True) 210 packager.createBuild(baseDir, type=type, outFile=file, devenv=True, releaseB uild=True)
237 211
238 from buildtools.packager import getDevEnvPath 212 from buildtools.packager import getDevEnvPath
239 devenv_dir = getDevEnvPath(baseDir, type) 213 devenv_dir = getDevEnvPath(baseDir, type)
240 214
241 shutil.rmtree(devenv_dir, ignore_errors=True) 215 shutil.rmtree(devenv_dir, ignore_errors=True)
242 216
243 file.seek(0) 217 file.seek(0)
244 with ZipFile(file, 'r') as zip_file: 218 with ZipFile(file, 'r') as zip_file:
245 zip_file.extractall(devenv_dir) 219 zip_file.extractall(devenv_dir)
246 220
247 221
248 def readLocaleConfig(baseDir, type, metadata): 222 def readLocaleConfig(baseDir, type, metadata):
249 if type == 'gecko': 223 if type in {'chrome', 'gecko-webext'}:
250 import buildtools.packagerGecko as packager
251 localeDir = packager.getLocalesDir(baseDir)
252 localeConfig = {
253 'name_format': 'BCP-47',
254 'file_format': 'gecko-dtd',
255 'target_platforms': {'gecko'},
256 'default_locale': packager.defaultLocale
257 }
258 elif type in {'chrome', 'gecko-webext'}:
259 import buildtools.packagerChrome as packager 224 import buildtools.packagerChrome as packager
260 localeDir = os.path.join(baseDir, '_locales') 225 localeDir = os.path.join(baseDir, '_locales')
261 localeConfig = { 226 localeConfig = {
262 'name_format': 'ISO-15897', 227 'name_format': 'ISO-15897',
Sebastian Noack 2017/10/03 02:22:39 This information is no longer relevant. We should
Sebastian Noack 2017/10/04 01:39:33 Actually adblockplusui is using BCP-47, but it wou
tlucas 2017/10/04 11:48:38 Done.
263 'file_format': 'chrome-json', 228 'file_format': 'chrome-json',
Sebastian Noack 2017/10/04 01:39:33 file_format is irrelevant as well, if you drop sup
tlucas 2017/10/04 11:48:38 Done.
264 'target_platforms': {'chrome'}, 229 'target_platforms': {type},
265 'default_locale': packager.defaultLocale, 230 'default_locale': packager.defaultLocale,
266 } 231 }
267 else: 232 else:
268 localeDir = os.path.join( 233 localeDir = os.path.join(
269 baseDir, *metadata.get('locales', 'base_path').split('/') 234 baseDir, *metadata.get('locales', 'base_path').split('/')
270 ) 235 )
271 localeConfig = { 236 localeConfig = {
272 'name_format': metadata.get('locales', 'name_format'), 237 'name_format': metadata.get('locales', 'name_format'),
273 'file_format': metadata.get('locales', 'file_format'), 238 'file_format': metadata.get('locales', 'file_format'),
274 'target_platforms': set(metadata.get('locales', 239 'target_platforms': set(metadata.get('locales',
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 from buildtools.packager import readMetadata 325 from buildtools.packager import readMetadata
361 metadata = readMetadata(baseDir, type) 326 metadata = readMetadata(baseDir, type)
362 327
363 basename = metadata.get('general', 'basename') 328 basename = metadata.get('general', 'basename')
364 localeConfig = readLocaleConfig(baseDir, type, metadata) 329 localeConfig = readLocaleConfig(baseDir, type, metadata)
365 330
366 import buildtools.localeTools as localeTools 331 import buildtools.localeTools as localeTools
367 localeTools.getTranslations(localeConfig, basename, key) 332 localeTools.getTranslations(localeConfig, basename, key)
368 333
369 334
370 def showDescriptions(baseDir, scriptName, opts, args, type):
371 locales = None
372 for option, value in opts:
373 if option in ('-l', '--locales'):
374 locales = value.split(',')
375
376 import buildtools.packagerGecko as packager
377 if locales == None:
378 locales = packager.getLocales(baseDir)
379 elif locales == 'all':
380 locales = packager.getLocales(baseDir, True)
381
382 data = packager.readLocaleMetadata(baseDir, locales)
383 localeCodes = data.keys()
384 localeCodes.sort()
385 for localeCode in localeCodes:
386 locale = data[localeCode]
387 print ('''%s
388 %s
389 %s
390 %s
391 %s
392 ''' % (localeCode,
393 locale['name'] if 'name' in locale else 'None',
394 locale['description'] if 'description' in locale else 'None',
395 locale['description.short'] if 'description.short' in locale else 'N one',
396 locale['description.long'] if 'description.long' in locale else 'Non e',
397 )).encode('utf-8')
398
399
400 def generateDocs(baseDir, scriptName, opts, args, type): 335 def generateDocs(baseDir, scriptName, opts, args, type):
401 if len(args) == 0: 336 if len(args) == 0:
402 print 'No target directory specified for the documentation' 337 print 'No target directory specified for the documentation'
403 usage(scriptName, type, 'docs') 338 usage(scriptName, type, 'docs')
404 return 339 return
405 targetDir = args[0] 340 targetDir = args[0]
406 341
407 source_dir = os.path.join(baseDir, 'lib') 342 source_dir = os.path.join(baseDir, 'lib')
408 sources = [source_dir] 343 sources = [source_dir]
409 344
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 import buildtools.publicSuffixListUpdater as publicSuffixListUpdater 395 import buildtools.publicSuffixListUpdater as publicSuffixListUpdater
461 publicSuffixListUpdater.updatePSL(baseDir) 396 publicSuffixListUpdater.updatePSL(baseDir)
462 397
463 with addCommand(lambda baseDir, scriptName, opts, args, type: usage(scriptName, type), ('help', '-h', '--help')) as command: 398 with addCommand(lambda baseDir, scriptName, opts, args, type: usage(scriptName, type), ('help', '-h', '--help')) as command:
464 command.shortDescription = 'Show this message' 399 command.shortDescription = 'Show this message'
465 400
466 with addCommand(runBuild, 'build') as command: 401 with addCommand(runBuild, 'build') as command:
467 command.shortDescription = 'Create a build' 402 command.shortDescription = 'Create a build'
468 command.description = 'Creates an extension build with given file name. If o utput_file is missing a default name will be chosen.' 403 command.description = 'Creates an extension build with given file name. If o utput_file is missing a default name will be chosen.'
469 command.params = '[options] [output_file]' 404 command.params = '[options] [output_file]'
470 command.addOption('Only include the given locales (if omitted: all locales n ot marked as incomplete)', short='l', long='locales', value='l1,l2,l3', types=(' gecko'))
471 command.addOption('Use given build number (if omitted the build number will be retrieved from Mercurial)', short='b', long='build', value='num') 405 command.addOption('Use given build number (if omitted the build number will be retrieved from Mercurial)', short='b', long='build', value='num')
472 command.addOption('File containing private key and certificates required to sign the package', short='k', long='key', value='file', types=('chrome', 'safari ')) 406 command.addOption('File containing private key and certificates required to sign the package', short='k', long='key', value='file', types=('chrome', 'safari '))
473 command.addOption('Create a build for leak testing', short='m', long='multi- compartment', types=('gecko'))
474 command.addOption('Create a release build', short='r', long='release') 407 command.addOption('Create a release build', short='r', long='release')
475 command.supportedTypes = ('gecko', 'gecko-webext', 'chrome', 'safari', 'edge ') 408 command.supportedTypes = ('gecko-webext', 'chrome', 'safari', 'edge')
476
477 with addCommand(runAutoInstall, 'autoinstall') as command:
478 command.shortDescription = 'Install extension automatically'
479 command.description = 'Will automatically install the extension in a browser running Extension Auto-Installer. If host parameter is omitted assumes that the browser runs on localhost.'
480 command.params = '[<host>:]<port>'
481 command.addOption('Create a build for leak testing', short='m', long='multi- compartment')
482 command.supportedTypes = ('gecko')
483 409
484 with addCommand(createDevEnv, 'devenv') as command: 410 with addCommand(createDevEnv, 'devenv') as command:
485 command.shortDescription = 'Set up a development environment' 411 command.shortDescription = 'Set up a development environment'
486 command.description = 'Will set up or update the devenv folder as an unpacke d extension folder for development.' 412 command.description = 'Will set up or update the devenv folder as an unpacke d extension folder for development.'
487 command.supportedTypes = ('gecko-webext', 'chrome', 'safari') 413 command.supportedTypes = ('gecko-webext', 'chrome', 'safari')
488 414
489 with addCommand(setupTranslations, 'setuptrans') as command: 415 with addCommand(setupTranslations, 'setuptrans') as command:
490 command.shortDescription = 'Sets up translation languages' 416 command.shortDescription = 'Sets up translation languages'
491 command.description = 'Sets up translation languages for the project on crow din.net.' 417 command.description = 'Sets up translation languages for the project on crow din.net.'
492 command.params = '[options] project-key' 418 command.params = '[options] project-key'
493 command.supportedTypes = ('gecko', 'chrome', 'generic') 419 command.supportedTypes = ('chrome', 'generic')
494 420
495 with addCommand(updateTranslationMaster, 'translate') as command: 421 with addCommand(updateTranslationMaster, 'translate') as command:
496 command.shortDescription = 'Updates translation master files' 422 command.shortDescription = 'Updates translation master files'
497 command.description = 'Updates the translation master files in the project o n crowdin.net.' 423 command.description = 'Updates the translation master files in the project o n crowdin.net.'
498 command.params = '[options] project-key' 424 command.params = '[options] project-key'
499 command.supportedTypes = ('gecko', 'chrome', 'generic') 425 command.supportedTypes = ('chrome', 'generic')
500 426
501 with addCommand(uploadTranslations, 'uploadtrans') as command: 427 with addCommand(uploadTranslations, 'uploadtrans') as command:
502 command.shortDescription = 'Uploads existing translations' 428 command.shortDescription = 'Uploads existing translations'
503 command.description = 'Uploads already existing translations to the project on crowdin.net.' 429 command.description = 'Uploads already existing translations to the project on crowdin.net.'
504 command.params = '[options] project-key' 430 command.params = '[options] project-key'
505 command.supportedTypes = ('gecko', 'chrome', 'generic') 431 command.supportedTypes = ('chrome', 'generic')
506 432
507 with addCommand(getTranslations, 'gettranslations') as command: 433 with addCommand(getTranslations, 'gettranslations') as command:
508 command.shortDescription = 'Downloads translation updates' 434 command.shortDescription = 'Downloads translation updates'
509 command.description = 'Downloads updated translations from crowdin.net.' 435 command.description = 'Downloads updated translations from crowdin.net.'
510 command.params = '[options] project-key' 436 command.params = '[options] project-key'
511 command.supportedTypes = ('gecko', 'chrome', 'generic') 437 command.supportedTypes = ('chrome', 'generic')
512
513 with addCommand(showDescriptions, 'showdesc') as command:
514 command.shortDescription = 'Print description strings for all locales'
515 command.description = 'Display description strings for all locales as specif ied in the corresponding meta.properties files.'
516 command.addOption('Only include the given locales', short='l', long='locales ', value='l1,l2,l3')
517 command.params = '[options]'
518 command.supportedTypes = ('gecko')
519 438
520 with addCommand(generateDocs, 'docs') as command: 439 with addCommand(generateDocs, 'docs') as command:
521 command.shortDescription = 'Generate documentation (requires node.js)' 440 command.shortDescription = 'Generate documentation (requires node.js)'
522 command.description = ('Generate documentation files and write them into ' 441 command.description = ('Generate documentation files and write them into '
523 'the specified directory.') 442 'the specified directory.')
524 command.addOption('Suppress JsDoc output', short='q', long='quiet') 443 command.addOption('Suppress JsDoc output', short='q', long='quiet')
525 command.params = '[options] <directory>' 444 command.params = '[options] <directory>'
526 command.supportedTypes = ('gecko', 'chrome') 445 command.supportedTypes = ('chrome')
527 446
528 with addCommand(runReleaseAutomation, 'release') as command: 447 with addCommand(runReleaseAutomation, 'release') as command:
529 command.shortDescription = 'Run release automation' 448 command.shortDescription = 'Run release automation'
530 command.description = 'Note: If you are not the project owner then you ' "probably don't want to run this!\n\n" 'Runs release automation: crea tes downloads for the new version, tags ' 'source code repository as well as downloads and buildtools repository.' 449 command.description = 'Note: If you are not the project owner then you ' "probably don't want to run this!\n\n" 'Runs release automation: crea tes downloads for the new version, tags ' 'source code repository as well as downloads and buildtools repository.'
531 command.addOption('File containing private key and certificates required to sign the release.', short='k', long='key', value='file', types=('chrome', 'safar i', 'edge')) 450 command.addOption('File containing private key and certificates required to sign the release.', short='k', long='key', value='file', types=('chrome', 'safar i', 'edge'))
532 command.addOption('Directory containing downloads repository (if omitted ../ downloads is assumed)', short='d', long='downloads', value='dir') 451 command.addOption('Directory containing downloads repository (if omitted ../ downloads is assumed)', short='d', long='downloads', value='dir')
533 command.params = '[options] <version>' 452 command.params = '[options] <version>'
534 command.supportedTypes = ('gecko', 'chrome', 'safari', 'edge') 453 command.supportedTypes = ('chrome', 'safari', 'edge')
535 454
536 with addCommand(updatePSL, 'updatepsl') as command: 455 with addCommand(updatePSL, 'updatepsl') as command:
537 command.shortDescription = 'Updates Public Suffix List' 456 command.shortDescription = 'Updates Public Suffix List'
538 command.description = 'Downloads Public Suffix List (see http://publicsuffix .org/) and generates lib/publicSuffixList.js from it.' 457 command.description = 'Downloads Public Suffix List (see http://publicsuffix .org/) and generates lib/publicSuffixList.js from it.'
539 command.supportedTypes = ('chrome',) 458 command.supportedTypes = ('chrome',)
540 459
541 460
542 def getType(baseDir, scriptName, args): 461 def getType(baseDir, scriptName, args):
543 # Look for an explicit type parameter (has to be the first parameter) 462 # Look for an explicit type parameter (has to be the first parameter)
544 if len(args) >= 2 and args[0] == '-t': 463 if len(args) >= 2 and args[0] == '-t':
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 if option in ('-h', '--help'): 523 if option in ('-h', '--help'):
605 usage(scriptName, type, command) 524 usage(scriptName, type, command)
606 sys.exit() 525 sys.exit()
607 commands[command](baseDir, scriptName, opts, args, type) 526 commands[command](baseDir, scriptName, opts, args, type)
608 else: 527 else:
609 print 'Command %s is not supported for this application type' % comm and 528 print 'Command %s is not supported for this application type' % comm and
610 usage(scriptName, type) 529 usage(scriptName, type)
611 else: 530 else:
612 print 'Command %s is unrecognized' % command 531 print 'Command %s is unrecognized' % command
613 usage(scriptName, type) 532 usage(scriptName, type)
OLDNEW
« no previous file with comments | « no previous file | lib/hooks.js » ('j') | localeTools.py » ('J')

Powered by Google App Engine
This is Rietveld