Skip to content

Commit

Permalink
Put workdir calculation in base Buildstep class
Browse files Browse the repository at this point in the history
The one is ShellCommand is generic logic enough to
be useful in base class.

Mark setDefaultWorkdir as deprecated

Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
  • Loading branch information
Pierre Tardy committed Dec 29, 2014
1 parent 2a53d7b commit deead86
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions master/buildbot/process/buildstep.py
Expand Up @@ -332,7 +332,8 @@ def setBuildSlave(self, buildslave):
self.buildslave = buildslave

def setDefaultWorkdir(self, workdir):
pass
if self.workdir is None:
self.workdir = workdir

def getWorkdir(self):
# default the workdir appropriately
Expand Down Expand Up @@ -1012,7 +1013,6 @@ def glob(self, glob):
class ShellMixin(object):

command = None
workdir = None
env = {}
want_stdout = True
want_stderr = True
Expand Down
1 change: 1 addition & 0 deletions master/buildbot/steps/package/rpm/rpmbuild.py
Expand Up @@ -117,6 +117,7 @@ def start(self):
# create the actual RemoteShellCommand instance now
kwargs = self.remote_kwargs
kwargs['command'] = self.command
kwargs['workdir'] = self.getWorkdir()
cmd = buildstep.RemoteShellCommand(**kwargs)
self.setupEnvironment(cmd)
self.startCommand(cmd)
Expand Down
1 change: 1 addition & 0 deletions master/buildbot/steps/shell.py
Expand Up @@ -127,6 +127,7 @@ def __init__(self, workdir=None,
# everything left over goes to the RemoteShellCommand
kwargs['usePTY'] = usePTY
self.remote_kwargs = kwargs
self.remote_kwargs['workdir'] = workdir

def setBuild(self, build):
buildstep.LoggingBuildStep.setBuild(self, build)
Expand Down
12 changes: 6 additions & 6 deletions master/buildbot/test/unit/test_process_buildstep.py
Expand Up @@ -881,7 +881,7 @@ class MySubclass(ShellMixinExample):

@defer.inlineCallbacks
def test_example(self):
self.setupStep(ShellMixinExample())
self.setupStep(ShellMixinExample(), wantDefaultWorkdir=False)
self.expectCommands(
ExpectShell(workdir='build', command=['./cleanup.sh'])
+ Expect.log('stdio', stderr="didn't go so well\n")
Expand All @@ -895,7 +895,7 @@ def test_example(self):

@defer.inlineCallbacks
def test_example_extra_logfile(self):
self.setupStep(ShellMixinExample(logfiles={'cleanup': 'cleanup.log'}))
self.setupStep(ShellMixinExample(logfiles={'cleanup': 'cleanup.log'}), wantDefaultWorkdir=False)
self.expectCommands(
ExpectShell(workdir='build', command=['./cleanup.sh'],
logfiles={'cleanup': 'cleanup.log'})
Expand All @@ -909,7 +909,7 @@ def test_example_extra_logfile(self):

@defer.inlineCallbacks
def test_example_build_workdir(self):
self.setupStep(ShellMixinExample())
self.setupStep(ShellMixinExample(), wantDefaultWorkdir=False)
self.build.workdir = '/alternate'
self.expectCommands(
ExpectShell(workdir='/alternate', command=['./cleanup.sh'])
Expand All @@ -931,7 +931,7 @@ def test_example_step_workdir(self):

@defer.inlineCallbacks
def test_example_env(self):
self.setupStep(ShellMixinExample(env={'BAR': 'BAR'}))
self.setupStep(ShellMixinExample(env={'BAR': 'BAR'}), wantDefaultWorkdir=False)
self.build.builder.config.env = {'FOO': 'FOO'}
self.expectCommands(
ExpectShell(workdir='build', command=['./cleanup.sh'],
Expand All @@ -944,7 +944,7 @@ def test_example_env(self):
@defer.inlineCallbacks
def test_example_old_slave(self):
self.setupStep(ShellMixinExample(usePTY=False, interruptSignal='DIE'),
slave_version={'*': "1.1"})
slave_version={'*': "1.1"}, wantDefaultWorkdir=False)
self.expectCommands(
ExpectShell(workdir='build', command=['./cleanup.sh'])
# note missing parameters
Expand All @@ -959,7 +959,7 @@ def test_example_old_slave(self):
@defer.inlineCallbacks
def test_description(self):
self.setupStep(SimpleShellCommand(
command=['foo', properties.Property('bar', 'BAR')]))
command=['foo', properties.Property('bar', 'BAR')]), wantDefaultWorkdir=False)
self.expectCommands(
ExpectShell(workdir='build', command=['foo', 'BAR'])
+ 0,
Expand Down
11 changes: 7 additions & 4 deletions master/buildbot/test/unit/test_steps_master.py
Expand Up @@ -68,7 +68,7 @@ def spawnProcess(pp, cmd, argv, path, usePTY, env):
def test_real_cmd(self):
cmd = [sys.executable, '-c', 'print "hello"']
self.setupStep(
master.MasterShellCommand(command=cmd))
master.MasterShellCommand(command=cmd), wantDefaultWorkdir=False)
if runtime.platformType == 'win32':
self.expectLogfile('stdio', "hello\r\n")
else:
Expand Down Expand Up @@ -127,7 +127,8 @@ def test_env_subst(self):
os.environ['WORLD'] = 'hello'
self.setupStep(
master.MasterShellCommand(command=cmd,
env={'HELLO': '${WORLD}'}))
env={'HELLO': '${WORLD}'}),
wantDefaultWorkdir=False)
if runtime.platformType == 'win32':
self.expectLogfile('stdio', "hello\r\n")
else:
Expand All @@ -147,7 +148,8 @@ def test_env_list_subst(self):
os.environ['LIST'] = 'world'
self.setupStep(
master.MasterShellCommand(command=cmd,
env={'HELLO': ['${WORLD}', '${LIST}']}))
env={'HELLO': ['${WORLD}', '${LIST}']}),
wantDefaultWorkdir=False)
if runtime.platformType == 'win32':
self.expectLogfile('stdio', "hello;world\r\n")
else:
Expand All @@ -168,7 +170,8 @@ def test_prop_rendering(self):
'project')]
self.setupStep(
master.MasterShellCommand(command=cmd,
env={'BUILD': WithProperties('%s', "project")}))
env={'BUILD': WithProperties('%s', "project")}),
wantDefaultWorkdir=False)
self.properties.setProperty("project", "BUILDBOT-TEST", "TEST")
if runtime.platformType == 'win32':
self.expectLogfile('stdio', "BUILDBOT-TEST\r\nBUILDBOT-TEST\r\n")
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/test/util/steps.py
Expand Up @@ -66,7 +66,7 @@ def tearDownBuildStep(self):
# utilities

def setupStep(self, step, slave_version={'*': "99.99"}, slave_env={},
buildFiles=[]):
buildFiles=[], wantDefaultWorkdir=True):
"""
Set up C{step} for testing. This begins by using C{step} as a factory
to create a I{new} step instance, thereby testing that the the factory
Expand Down Expand Up @@ -149,8 +149,8 @@ def addLogObserver(logname, observer):
addLogObserver(n, o)

# set defaults

step.setDefaultWorkdir('wkdir')
if wantDefaultWorkdir:
step.setDefaultWorkdir('wkdir')

# expectations

Expand Down
1 change: 1 addition & 0 deletions master/docs/developer/cls-buildsteps.rst
Expand Up @@ -151,6 +151,7 @@ BuildStep

This method is called at build startup with the default workdir for the build.
Steps which allow a workdir to be specified, but want to override it with the build's default workdir, can use this method to apply the default.

.. note::

This method is deprecated and should not be used anymore, as workdir is now a buildstep base argument
Expand Down

0 comments on commit deead86

Please sign in to comment.