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

Delta Between Two Patch Sets: build.py

Issue 29562599: Issue 5751 - Removing legacy gecko support (Closed)
Left Patch Set: Created Oct. 2, 2017, 10:33 a.m.
Right Patch Set: Rebase against current master ( 489:293593da6033 ) Created Oct. 10, 2017, 9:25 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 | « LocaleTester.pm ('k') | lib/hooks.js » ('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 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
11 from getopt import getopt, GetoptError 10 from getopt import getopt, GetoptError
12 from StringIO import StringIO 11 from StringIO import StringIO
13 from zipfile import ZipFile 12 from zipfile import ZipFile
14 13
15 knownTypes = ('gecko-webext', 'chrome', 'safari', 'generic', 'edge') 14 knownTypes = ('gecko-webext', 'chrome', 'safari', 'generic', 'edge')
16 15
17 16
18 class Command(object): 17 class Command(object):
19 name = property(lambda self: self._name) 18 name = property(lambda self: self._name)
20 shortDescription = property( 19 shortDescription = property(
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 'description': description, 172 'description': description,
174 'options': '\n'.join(options) 173 'options': '\n'.join(options)
175 } 174 }
176 175
177 176
178 def runBuild(baseDir, scriptName, opts, args, type): 177 def runBuild(baseDir, scriptName, opts, args, type):
179 kwargs = {} 178 kwargs = {}
180 for option, value in opts: 179 for option, value in opts:
181 if option in {'-b', '--build'}: 180 if option in {'-b', '--build'}:
182 kwargs['buildNum'] = value 181 kwargs['buildNum'] = value
183 no_gecko_build = type != 'gecko-webext' 182 if type != 'gecko-webext' and not kwargs['buildNum'].isdigit():
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.
184 if no_gecko_build and not kwargs['buildNum'].isdigit():
185 raise TypeError('Build number must be numerical') 183 raise TypeError('Build number must be numerical')
186 elif option in {'-k', '--key'}: 184 elif option in {'-k', '--key'}:
187 kwargs['keyFile'] = value 185 kwargs['keyFile'] = value
188 elif option in {'-r', '--release'}: 186 elif option in {'-r', '--release'}:
189 kwargs['releaseBuild'] = True 187 kwargs['releaseBuild'] = True
190 if len(args) > 0: 188 if len(args) > 0:
191 kwargs['outFile'] = args[0] 189 kwargs['outFile'] = args[0]
192 190
193 if type in {'chrome', 'gecko-webext'}: 191 if type in {'chrome', 'gecko-webext'}:
194 import buildtools.packagerChrome as packager 192 import buildtools.packagerChrome as packager
(...skipping 18 matching lines...) Expand all
213 devenv_dir = getDevEnvPath(baseDir, type) 211 devenv_dir = getDevEnvPath(baseDir, type)
214 212
215 shutil.rmtree(devenv_dir, ignore_errors=True) 213 shutil.rmtree(devenv_dir, ignore_errors=True)
216 214
217 file.seek(0) 215 file.seek(0)
218 with ZipFile(file, 'r') as zip_file: 216 with ZipFile(file, 'r') as zip_file:
219 zip_file.extractall(devenv_dir) 217 zip_file.extractall(devenv_dir)
220 218
221 219
222 def readLocaleConfig(baseDir, type, metadata): 220 def readLocaleConfig(baseDir, type, metadata):
223 if type in {'chrome', 'gecko-webext'}: 221 if type != 'generic':
Vasily Kuznetsov 2017/10/10 12:44:33 We could swap the branches of this if statement to
tlucas 2017/10/10 12:50:13 Well, imho the "not generic" platforms are those m
224 import buildtools.packagerChrome as packager 222 import buildtools.packagerChrome as packager
225 localeDir = os.path.join(baseDir, '_locales') 223 localeDir = os.path.join(baseDir, '_locales')
226 localeConfig = { 224 localeConfig = {
227 'name_format': 'ISO-15897',
228 'file_format': 'chrome-json',
229 'target_platforms': {type},
230 'default_locale': packager.defaultLocale, 225 'default_locale': packager.defaultLocale,
231 } 226 }
232 else: 227 else:
233 localeDir = os.path.join( 228 localeDir = os.path.join(
234 baseDir, *metadata.get('locales', 'base_path').split('/') 229 baseDir, *metadata.get('locales', 'base_path').split('/')
235 ) 230 )
236 localeConfig = { 231 localeConfig = {
237 'name_format': metadata.get('locales', 'name_format'),
238 'file_format': metadata.get('locales', 'file_format'),
239 'target_platforms': set(metadata.get('locales',
240 'target_platforms').split()),
241 'default_locale': metadata.get('locales', 'default_locale') 232 'default_locale': metadata.get('locales', 'default_locale')
242 } 233 }
243 234
244 localeConfig['base_path'] = localeDir 235 localeConfig['base_path'] = localeDir
245 236
246 locales = [(locale, os.path.join(localeDir, locale)) 237 locales = [(locale.replace('_', '-'), os.path.join(localeDir, locale))
247 for locale in os.listdir(localeDir)] 238 for locale in os.listdir(localeDir)]
248 if localeConfig['name_format'] == 'ISO-15897':
249 locales = [(locale.replace('_', '-'), localePath)
250 for locale, localePath in locales]
251 localeConfig['locales'] = dict(locales) 239 localeConfig['locales'] = dict(locales)
252 240
253 return localeConfig 241 return localeConfig
254 242
255 243
256 def setupTranslations(baseDir, scriptName, opts, args, type): 244 def setupTranslations(baseDir, scriptName, opts, args, type):
257 if len(args) < 1: 245 if len(args) < 1:
258 print 'Project key is required to update translation master files.' 246 print 'Project key is required to update translation master files.'
259 usage(scriptName, type, 'setuptrans') 247 usage(scriptName, type, 'setuptrans')
260 return 248 return
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 key = args[0] 290 key = args[0]
303 291
304 from buildtools.packager import readMetadata 292 from buildtools.packager import readMetadata
305 metadata = readMetadata(baseDir, type) 293 metadata = readMetadata(baseDir, type)
306 294
307 basename = metadata.get('general', 'basename') 295 basename = metadata.get('general', 'basename')
308 localeConfig = readLocaleConfig(baseDir, type, metadata) 296 localeConfig = readLocaleConfig(baseDir, type, metadata)
309 297
310 import buildtools.localeTools as localeTools 298 import buildtools.localeTools as localeTools
311 for locale, localeDir in localeConfig['locales'].iteritems(): 299 for locale, localeDir in localeConfig['locales'].iteritems():
312 if locale != localeConfig['default_locale']: 300 if locale != localeConfig['default_locale'].replace('_', '-'):
313 localeTools.uploadTranslations(localeConfig, metadata, localeDir, lo cale, 301 localeTools.uploadTranslations(localeConfig, metadata, localeDir, lo cale,
314 basename, key) 302 basename, key)
315 303
316 304
317 def getTranslations(baseDir, scriptName, opts, args, type): 305 def getTranslations(baseDir, scriptName, opts, args, type):
318 if len(args) < 1: 306 if len(args) < 1:
319 print 'Project key is required to update translation master files.' 307 print 'Project key is required to update translation master files.'
320 usage(scriptName, type, 'translate') 308 usage(scriptName, type, 'translate')
321 return 309 return
322 310
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 return 376 return
389 377
390 import buildtools.releaseAutomation as releaseAutomation 378 import buildtools.releaseAutomation as releaseAutomation
391 releaseAutomation.run(baseDir, type, version, keyFile, downloadsRepo) 379 releaseAutomation.run(baseDir, type, version, keyFile, downloadsRepo)
392 380
393 381
394 def updatePSL(baseDir, scriptName, opts, args, type): 382 def updatePSL(baseDir, scriptName, opts, args, type):
395 import buildtools.publicSuffixListUpdater as publicSuffixListUpdater 383 import buildtools.publicSuffixListUpdater as publicSuffixListUpdater
396 publicSuffixListUpdater.updatePSL(baseDir) 384 publicSuffixListUpdater.updatePSL(baseDir)
397 385
386
398 with addCommand(lambda baseDir, scriptName, opts, args, type: usage(scriptName, type), ('help', '-h', '--help')) as command: 387 with addCommand(lambda baseDir, scriptName, opts, args, type: usage(scriptName, type), ('help', '-h', '--help')) as command:
399 command.shortDescription = 'Show this message' 388 command.shortDescription = 'Show this message'
400 389
401 with addCommand(runBuild, 'build') as command: 390 with addCommand(runBuild, 'build') as command:
402 command.shortDescription = 'Create a build' 391 command.shortDescription = 'Create a build'
403 command.description = 'Creates an extension build with given file name. If o utput_file is missing a default name will be chosen.' 392 command.description = 'Creates an extension build with given file name. If o utput_file is missing a default name will be chosen.'
404 command.params = '[options] [output_file]' 393 command.params = '[options] [output_file]'
405 command.addOption('Use given build number (if omitted the build number will be retrieved from Mercurial)', short='b', long='build', value='num') 394 command.addOption('Use given build number (if omitted the build number will be retrieved from Mercurial)', short='b', long='build', value='num')
406 command.addOption('File containing private key and certificates required to sign the package', short='k', long='key', value='file', types=('chrome', 'safari ')) 395 command.addOption('File containing private key and certificates required to sign the package', short='k', long='key', value='file', types=('chrome', 'safari '))
407 command.addOption('Create a release build', short='r', long='release') 396 command.addOption('Create a release build', short='r', long='release')
408 command.supportedTypes = ('gecko-webext', 'chrome', 'safari', 'edge') 397 command.supportedTypes = ('gecko-webext', 'chrome', 'safari', 'edge')
409 398
410 with addCommand(createDevEnv, 'devenv') as command: 399 with addCommand(createDevEnv, 'devenv') as command:
411 command.shortDescription = 'Set up a development environment' 400 command.shortDescription = 'Set up a development environment'
412 command.description = 'Will set up or update the devenv folder as an unpacke d extension folder for development.' 401 command.description = 'Will set up or update the devenv folder as an unpacke d extension folder for development.'
413 command.supportedTypes = ('gecko-webext', 'chrome', 'safari') 402 command.supportedTypes = ('gecko-webext', 'chrome', 'safari')
414 403
415 with addCommand(setupTranslations, 'setuptrans') as command: 404 with addCommand(setupTranslations, 'setuptrans') as command:
416 command.shortDescription = 'Sets up translation languages' 405 command.shortDescription = 'Sets up translation languages'
417 command.description = 'Sets up translation languages for the project on crow din.net.' 406 command.description = 'Sets up translation languages for the project on crow din.net.'
418 command.params = '[options] project-key' 407 command.params = '[options] project-key'
419 command.supportedTypes = ('chrome', 'generic')
420 408
421 with addCommand(updateTranslationMaster, 'translate') as command: 409 with addCommand(updateTranslationMaster, 'translate') as command:
422 command.shortDescription = 'Updates translation master files' 410 command.shortDescription = 'Updates translation master files'
423 command.description = 'Updates the translation master files in the project o n crowdin.net.' 411 command.description = 'Updates the translation master files in the project o n crowdin.net.'
424 command.params = '[options] project-key' 412 command.params = '[options] project-key'
425 command.supportedTypes = ('chrome', 'generic')
426 413
427 with addCommand(uploadTranslations, 'uploadtrans') as command: 414 with addCommand(uploadTranslations, 'uploadtrans') as command:
428 command.shortDescription = 'Uploads existing translations' 415 command.shortDescription = 'Uploads existing translations'
429 command.description = 'Uploads already existing translations to the project on crowdin.net.' 416 command.description = 'Uploads already existing translations to the project on crowdin.net.'
430 command.params = '[options] project-key' 417 command.params = '[options] project-key'
431 command.supportedTypes = ('chrome', 'generic')
432 418
433 with addCommand(getTranslations, 'gettranslations') as command: 419 with addCommand(getTranslations, 'gettranslations') as command:
434 command.shortDescription = 'Downloads translation updates' 420 command.shortDescription = 'Downloads translation updates'
435 command.description = 'Downloads updated translations from crowdin.net.' 421 command.description = 'Downloads updated translations from crowdin.net.'
436 command.params = '[options] project-key' 422 command.params = '[options] project-key'
437 command.supportedTypes = ('chrome', 'generic')
438 423
439 with addCommand(generateDocs, 'docs') as command: 424 with addCommand(generateDocs, 'docs') as command:
440 command.shortDescription = 'Generate documentation (requires node.js)' 425 command.shortDescription = 'Generate documentation (requires node.js)'
441 command.description = ('Generate documentation files and write them into ' 426 command.description = ('Generate documentation files and write them into '
442 'the specified directory.') 427 'the specified directory.')
443 command.addOption('Suppress JsDoc output', short='q', long='quiet') 428 command.addOption('Suppress JsDoc output', short='q', long='quiet')
444 command.params = '[options] <directory>' 429 command.params = '[options] <directory>'
445 command.supportedTypes = ('chrome') 430 command.supportedTypes = ('chrome',)
446 431
447 with addCommand(runReleaseAutomation, 'release') as command: 432 with addCommand(runReleaseAutomation, 'release') as command:
448 command.shortDescription = 'Run release automation' 433 command.shortDescription = 'Run release automation'
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.' 434 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.'
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')) 435 command.addOption('File containing private key and certificates required to sign the release.', short='k', long='key', value='file', types=('chrome', 'safar i', 'edge'))
451 command.addOption('Directory containing downloads repository (if omitted ../ downloads is assumed)', short='d', long='downloads', value='dir') 436 command.addOption('Directory containing downloads repository (if omitted ../ downloads is assumed)', short='d', long='downloads', value='dir')
452 command.params = '[options] <version>' 437 command.params = '[options] <version>'
453 command.supportedTypes = ('chrome', 'safari', 'edge') 438 command.supportedTypes = ('chrome', 'safari', 'edge')
454 439
455 with addCommand(updatePSL, 'updatepsl') as command: 440 with addCommand(updatePSL, 'updatepsl') as command:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 if option in ('-h', '--help'): 508 if option in ('-h', '--help'):
524 usage(scriptName, type, command) 509 usage(scriptName, type, command)
525 sys.exit() 510 sys.exit()
526 commands[command](baseDir, scriptName, opts, args, type) 511 commands[command](baseDir, scriptName, opts, args, type)
527 else: 512 else:
528 print 'Command %s is not supported for this application type' % comm and 513 print 'Command %s is not supported for this application type' % comm and
529 usage(scriptName, type) 514 usage(scriptName, type)
530 else: 515 else:
531 print 'Command %s is unrecognized' % command 516 print 'Command %s is unrecognized' % command
532 usage(scriptName, type) 517 usage(scriptName, type)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld