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