Ported NinjaCommand.
diff --git a/zorg/buildbot/commands/NinjaCommand.py b/zorg/buildbot/commands/NinjaCommand.py
index 47054b8..2b55456 100644
--- a/zorg/buildbot/commands/NinjaCommand.py
+++ b/zorg/buildbot/commands/NinjaCommand.py
@@ -1,9 +1,11 @@
+# TODO: Use Interpolate instead of WithProperties.
import re
from buildbot.process.properties import WithProperties
from buildbot.steps.shell import WarningCountingShellCommand
class NinjaCommand(WarningCountingShellCommand):
+ DEFAULT_NINJA = 'ninja'
@staticmethod
def sanitize_kwargs(kwargs):
@@ -23,27 +25,37 @@
return sanitized_kwargs
+ name = "build"
+ haltOnFailure = True
+ description = ["building"]
+ descriptionDone = ["build"]
+ renderables = (
+ 'options',
+ 'targets',
+ 'ninja',
+ )
- def __init__(self, prefixCommand=None, options=None, targets=None, **kwargs):
- self.prefixCommand = prefixCommand
+ def __init__(self, options=None, targets=None, ninja=DEFAULT_NINJA, logObserver=None, **kwargs):
+ self.ninja = ninja
self.targets = targets
- command = []
- if prefixCommand:
- command += prefixCommand
-
- command += ["ninja"]
-
if options is None:
self.options = list()
else:
self.options = list(options)
+ if logObserver:
+ self.logObserver = logObserver
+ self.addLogObserver('stdio', self.logObserver)
+
j_opt = re.compile(r'^-j$|^-j\d+$')
l_opt = re.compile(r'^-l$|^-l\d+(\.(\d+)?)?$')
+ command = list()
+ command += [self.ninja]
+
# We can get jobs in the options. If so, we would use that.
- if not any(j_opt.search(opt) for opt in self.options if isinstance(opt, basestring)):
+ if not any(j_opt.search(opt) for opt in self.options if isinstance(opt, str)):
# Otherwise let's see if we got it in the kwargs.
if kwargs.get('jobs', None):
self.options += ["-j", kwargs['jobs']]
@@ -55,8 +67,8 @@
WithProperties("%(jobs:-)s"),
]
- # The same logic is for hanling the loadaverage option.
- if not any(l_opt.search(opt) for opt in self.options if isinstance(opt, basestring)):
+ # The same logic is for handling the loadaverage option.
+ if not any(l_opt.search(opt) for opt in self.options if isinstance(opt, str)):
if kwargs.get('loadaverage', None):
self.options += ["-l", kwargs['loadaverage']]
else:
@@ -68,8 +80,8 @@
if self.options:
command += self.options
- if targets:
- command += targets
+ if self.targets:
+ command += self.targets
# Remove here all the kwargs any of our LLVM buildbot command could consume.
# Note: We will remove all the empty items from the command at start, as we
@@ -79,26 +91,20 @@
sanitized_kwargs["command"] = command
# And upcall to let the base class do its work
- WarningCountingShellCommand.__init__(self, **sanitized_kwargs)
-
- self.addFactoryArguments(prefixCommand=prefixCommand,
- options=self.options,
- targets=targets)
-
+ super().__init__(**sanitized_kwargs)
def setupEnvironment(self, cmd):
# First upcall to get everything prepared.
- WarningCountingShellCommand.setupEnvironment(self, cmd)
+ super().setupEnvironment(cmd)
# Set default status format string.
if cmd.args['env'] is None:
cmd.args['env'] = {}
cmd.args['env']['NINJA_STATUS'] = cmd.args['env'].get('NINJA_STATUS', "%e [%u/%r/%f] ")
-
- def start(self):
- # Don't forget to remove all the empty items from the command,
- # which we could get because of WithProperties rendered as empty strings.
- self.command = filter(bool, self.command)
- # Then upcall.
- WarningCountingShellCommand.start(self)
+ def buildCommandKwargs(self, warnings):
+ kwargs = super().buildCommandKwargs(warnings)
+ # Remove all the empty items from the command list,
+ # which we could get if Interpolate rendered to empty strings.
+ kwargs['command'] = [cmd for cmd in kwargs['command'] if cmd]
+ return kwargs