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

Source Code for Module buildbot.process.factory

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