Package buildbot :: Package process :: Module factory
[frames] | no frames]

Source Code for Module buildbot.process.factory

  1  # This file is part of Buildbot.  Buildbot is free software: you can 
  2  # redistribute it and/or modify it under the terms of the GNU General Public 
  3  # License as published by the Free Software Foundation, version 2. 
  4  # 
  5  # This program is distributed in the hope that it will be useful, but WITHOUT 
  6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  8  # details. 
  9  # 
 10  # You should have received a copy of the GNU General Public License along with 
 11  # this program; if not, write to the Free Software Foundation, Inc., 51 
 12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 13  # 
 14  # Copyright Buildbot Team Members 
 15   
 16  import warnings 
 17   
 18  from twisted.python import deprecate, versions 
 19   
 20  from buildbot import util 
 21  from buildbot.process.build import Build 
 22  from buildbot.process.buildstep import BuildStep 
 23  from buildbot.steps.source import CVS, SVN 
 24  from buildbot.steps.shell import Configure, Compile, Test, PerlModuleTest 
25 26 # deprecated, use BuildFactory.addStep 27 @deprecate.deprecated(versions.Version("buildbot", 0, 8, 6)) 28 -def s(steptype, **kwargs):
29 # convenience function for master.cfg files, to create step 30 # specification tuples 31 return (steptype, kwargs)
32
33 -class ArgumentsInTheWrongPlace(Exception):
34 """When calling BuildFactory.addStep(stepinstance), addStep() only takes 35 one argument. You passed extra arguments to addStep(), which you probably 36 intended to pass to your BuildStep constructor instead. For example, you 37 should do:: 38 39 f.addStep(ShellCommand(command=['echo','stuff'], haltOnFailure=True)) 40 41 instead of:: 42 43 f.addStep(ShellCommand(command=['echo','stuff']), haltOnFailure=True) 44 """
45
46 -class BuildFactory(util.ComparableMixin):
47 """ 48 @cvar buildClass: class to use when creating builds 49 @type buildClass: L{buildbot.process.build.Build} 50 """ 51 buildClass = Build 52 useProgress = 1 53 workdir = "build" 54 compare_attrs = ['buildClass', 'steps', 'useProgress', 'workdir'] 55
56 - def __init__(self, steps=None):
57 if steps is None: 58 steps = [] 59 self.steps = [self._makeStepFactory(s) for s in steps]
60
61 - def _makeStepFactory(self, step_or_factory):
62 if isinstance(step_or_factory, BuildStep): 63 return step_or_factory.getStepFactory() 64 warnings.warn( 65 "Passing a BuildStep subclass to factory.addStep is deprecated. " + 66 "Please pass a BuildStep instance instead. Support will be dropped in v0.8.7.", 67 DeprecationWarning, stacklevel=3) 68 return step_or_factory
69
70 - def newBuild(self, requests):
71 """Create a new Build instance. 72 73 @param requests: a list of buildrequest dictionaries describing what is 74 to be built 75 """ 76 b = self.buildClass(requests) 77 b.useProgress = self.useProgress 78 b.workdir = self.workdir 79 b.setStepFactories(self.steps) 80 return b
81
82 - def addStep(self, step_or_factory, **kwargs):
83 if isinstance(step_or_factory, BuildStep): 84 if kwargs: 85 raise ArgumentsInTheWrongPlace() 86 s = step_or_factory.getStepFactory() 87 elif type(step_or_factory) == type(BuildStep) and \ 88 issubclass(step_or_factory, BuildStep): 89 s = (step_or_factory, dict(kwargs)) 90 warnings.warn( 91 "Passing a BuildStep subclass to factory.addStep is deprecated. " + 92 "Please pass a BuildStep instance instead. Support will be dropped in v0.8.7.", 93 DeprecationWarning, stacklevel=2) 94 95 else: 96 raise ValueError('%r is not a BuildStep nor BuildStep subclass' % step_or_factory) 97 self.steps.append(s)
98
99 - def addSteps(self, steps):
100 for s in steps: 101 self.addStep(s)
102
103 # BuildFactory subclasses for common build tools 104 105 -class GNUAutoconf(BuildFactory):
106 - def __init__(self, source, configure="./configure", 107 configureEnv={}, 108 configureFlags=[], 109 compile=["make", "all"], 110 test=["make", "check"]):
111 BuildFactory.__init__(self, [source]) 112 if configure is not None: 113 # we either need to wind up with a string (which will be 114 # space-split), or with a list of strings (which will not). The 115 # list of strings is the preferred form. 116 if type(configure) is str: 117 if configureFlags: 118 assert not " " in configure # please use list instead 119 command = [configure] + configureFlags 120 else: 121 command = configure 122 else: 123 assert isinstance(configure, (list, tuple)) 124 command = configure + configureFlags 125 self.addStep(Configure, command=command, env=configureEnv) 126 if compile is not None: 127 self.addStep(Compile, command=compile) 128 if test is not None: 129 self.addStep(Test, command=test)
130
131 -class CPAN(BuildFactory):
132 - def __init__(self, source, perl="perl"):
133 BuildFactory.__init__(self, [source]) 134 self.addStep(Configure, command=[perl, "Makefile.PL"]) 135 self.addStep(Compile, command=["make"]) 136 self.addStep(PerlModuleTest, command=["make", "test"])
137
138 -class Distutils(BuildFactory):
139 - def __init__(self, source, python="python", test=None):
140 BuildFactory.__init__(self, [source]) 141 self.addStep(Compile, command=[python, "./setup.py", "build"]) 142 if test is not None: 143 self.addStep(Test, command=test)
144
145 -class Trial(BuildFactory):
146 """Build a python module that uses distutils and trial. Set 'tests' to 147 the module in which the tests can be found, or set useTestCaseNames=True 148 to always have trial figure out which tests to run (based upon which 149 files have been changed). 150 151 See docs/factories.xhtml for usage samples. Not all of the Trial 152 BuildStep options are available here, only the most commonly used ones. 153 To get complete access, you will need to create a custom 154 BuildFactory.""" 155 156 trial = "trial" 157 randomly = False 158 recurse = False 159
160 - def __init__(self, source, 161 buildpython=["python"], trialpython=[], trial=None, 162 testpath=".", randomly=None, recurse=None, 163 tests=None, useTestCaseNames=False, env=None):
164 BuildFactory.__init__(self, [source]) 165 assert tests or useTestCaseNames, "must use one or the other" 166 if trial is not None: 167 self.trial = trial 168 if randomly is not None: 169 self.randomly = randomly 170 if recurse is not None: 171 self.recurse = recurse 172 173 from buildbot.steps.python_twisted import Trial 174 buildcommand = buildpython + ["./setup.py", "build"] 175 self.addStep(Compile, command=buildcommand, env=env) 176 self.addStep(Trial, 177 python=trialpython, trial=self.trial, 178 testpath=testpath, 179 tests=tests, testChanges=useTestCaseNames, 180 randomly=self.randomly, 181 recurse=self.recurse, 182 env=env, 183 )
184 185 186 # compatibility classes, will go away. Note that these only offer 187 # compatibility at the constructor level: if you have subclassed these 188 # factories, your subclasses are unlikely to still work correctly. 189 190 ConfigurableBuildFactory = BuildFactory
191 192 -class BasicBuildFactory(GNUAutoconf):
193 # really a "GNU Autoconf-created tarball -in-CVS tree" builder 194
195 - def __init__(self, cvsroot, cvsmodule, 196 configure=None, configureEnv={}, 197 compile="make all", 198 test="make check", cvsCopy=False):
199 mode = "clobber" 200 if cvsCopy: 201 mode = "copy" 202 source = s(CVS, cvsroot=cvsroot, cvsmodule=cvsmodule, mode=mode) 203 GNUAutoconf.__init__(self, source, 204 configure=configure, configureEnv=configureEnv, 205 compile=compile, 206 test=test)
207
208 -class QuickBuildFactory(BasicBuildFactory):
209 useProgress = False 210
211 - def __init__(self, cvsroot, cvsmodule, 212 configure=None, configureEnv={}, 213 compile="make all", 214 test="make check", cvsCopy=False):
215 mode = "update" 216 source = s(CVS, cvsroot=cvsroot, cvsmodule=cvsmodule, mode=mode) 217 GNUAutoconf.__init__(self, source, 218 configure=configure, configureEnv=configureEnv, 219 compile=compile, 220 test=test)
221
222 -class BasicSVN(GNUAutoconf):
223
224 - def __init__(self, svnurl, 225 configure=None, configureEnv={}, 226 compile="make all", 227 test="make check"):
228 source = s(SVN, svnurl=svnurl, mode="update") 229 GNUAutoconf.__init__(self, source, 230 configure=configure, configureEnv=configureEnv, 231 compile=compile, 232 test=test)
233