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