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

Unified Diff: build.py

Issue 9259023: Use platform-dependent metadata files to allow multiple builds from the same repository (Closed)
Patch Set: The -t command line flag is now properly documented in the help output, it`s still a very special c… Created Jan. 25, 2013, 8:22 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | packager.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build.py
===================================================================
--- a/build.py
+++ b/build.py
@@ -13,16 +13,18 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
import os, sys, re, subprocess, buildtools
from getopt import getopt, GetoptError
+knownTypes = ('gecko', 'chrome')
+
class Command(object):
name = property(lambda self: self._name)
shortDescription = property(lambda self: self._shortDescription,
lambda self, value: self.__dict__.update({'_shortDescription': value}))
description = property(lambda self: self._description,
lambda self, value: self.__dict__.update({'_description': value}))
params = property(lambda self: self._params,
lambda self, value: self.__dict__.update({'_params': value}))
@@ -106,28 +108,29 @@ def usage(scriptName, type, commandName=
if commandName == None:
global commandsList
descriptions = []
for command in commandsList:
if not command.isSupported(type):
continue
commandText = ('%s %s' % (command.name, command.params)).ljust(39)
descriptionParts = splitByLength(command.shortDescription, 29)
- descriptions.append(' %s %s %s' % (scriptName, commandText, descriptionParts[0]))
+ descriptions.append(' %s [-t %s] %s %s' % (scriptName, type, commandText, descriptionParts[0]))
for part in descriptionParts[1:]:
- descriptions.append(' %s %s %s' % (' ' * len(scriptName), ' ' * len(commandText), part))
+ descriptions.append(' %s %s %s %s' % (' ' * len(scriptName), ' ' * len(type), ' ' * len(commandText), part))
print '''Usage:
%(descriptions)s
For details on a command run:
- %(scriptName)s <command> --help
+ %(scriptName)s [-t %(type)s] <command> --help
''' % {
'scriptName': scriptName,
+ 'type': type,
'descriptions': '\n'.join(descriptions)
}
else:
global commands
command = commands[commandName]
description = '\n'.join(map(lambda s: '\n'.join(splitByLength(s, 80)), command.description.split('\n')))
options = []
for descr, short, long, value, types in command.options:
@@ -144,24 +147,25 @@ For details on a command run:
elif value == None:
longText = '--%s' % long
else:
longText = '--%s=%s' % (long, value)
descrParts = splitByLength(descr, 46)
options.append(' %s %s %s' % (shortText.ljust(11), longText.ljust(19), descrParts[0]))
for part in descrParts[1:]:
options.append(' %s %s %s' % (' ' * 11, ' ' * 19, part))
- print '''%(scriptName)s %(name)s %(params)s
+ print '''%(scriptName)s [-t %(type)s] %(name)s %(params)s
%(description)s
Options:
%(options)s
''' % {
'scriptName': scriptName,
+ 'type': type,
'name': command.name,
'params': command.params,
'description': description,
'options': '\n'.join(options)
}
def runBuild(baseDir, scriptName, opts, args, type):
@@ -497,21 +501,59 @@ with addCommand(syncLocales, 'synclocale
command.params = '<firefox_addon_directory>'
command.supportedTypes = ('chrome')
with addCommand(updatePSL, 'updatepsl') as command:
command.shortDescription = 'Updates Public Suffix List'
command.description = 'Downloads Public Suffix List (see http://publicsuffix.org/) and generates lib/publicSuffixList.js from it.'
command.supportedTypes = ('chrome')
-def processArgs(baseDir, args, type='gecko'):
+def getType(baseDir, scriptName, args):
+ # Look for an explicit type parameter (has to be the first parameter)
+ if len(args) >= 2 and args[0] == '-t':
Felix Dahlke 2013/01/25 08:30:49 Hard coding that -t needs to be the very first par
+ type = args[1]
+ del args[1]
+ del args[0]
+ if type not in knownTypes:
+ print '''
+Unknown type %s specified, supported types are: %s
+''' % (type, ', '.join(knownTypes))
+ return None
+ return type
+
+ # Try to guess repository type
+ types = []
+ for t in knownTypes:
+ if os.path.exists(os.path.join(baseDir, 'metadata.%s' % t)):
+ types.append(t)
+
+ if len(types) == 1:
+ return types[0]
+ elif len(types) > 1:
+ print '''
+Ambiguous repository type, please specify -t parameter explicitly, e.g.
+%s -t %s build
+''' % (scriptName, types[0])
+ return None
+ else:
+ print '''
+No metadata file found in this repository, a metadata file like
+metadata.%s is required.
+''' % knownTypes[0]
+ return None
+
+def processArgs(baseDir, args):
global commands
scriptName = os.path.basename(args[0])
args = args[1:]
+ type = getType(baseDir, scriptName, args)
Felix Dahlke 2013/01/25 08:30:49 There's a rogue white space before "args". Utter n
Wladimir Palant 2013/01/25 10:23:49 Fixed that before pushing.
+ if type == None:
+ return
+
if len(args) == 0:
args = ['build']
print '''
No command given, assuming "build". For a list of commands run:
%s help
''' % scriptName
« no previous file with comments | « no previous file | packager.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld