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
):
17 @cvar buildClass: class to use when creating builds
18 @type buildClass: L{buildbot.process.base.Build}
22 compare_attrs
= ['buildClass', 'steps', 'useProgress']
24 def __init__(self
, steps
=None):
29 def newBuild(self
, request
):
30 """Create a new Build instance.
31 @param request: a L{base.BuildRequest} describing what is to be built
33 b
= self
.buildClass(request
)
34 b
.useProgress
= self
.useProgress
35 b
.setSteps(self
.steps
)
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",
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:
59 assert not " " in configure
# please use list instead
60 command
= [configure
] + configureFlags
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)
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"])
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
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:
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
)
124 python
=trialpython
, trial
=self
.trial
,
126 tests
=tests
, testChanges
=useTestCaseNames
,
127 randomly
=self
.randomly
,
128 recurse
=self
.recurse
,
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
={},
145 test
="make check", cvsCopy
=False):
149 source
= s(CVS
, cvsroot
=cvsroot
, cvsmodule
=cvsmodule
, mode
=mode
)
150 GNUAutoconf
.__init
__(self
, source
,
151 configure
=configure
, configureEnv
=configureEnv
,
155 class QuickBuildFactory(BasicBuildFactory
):
158 def __init__(self
, cvsroot
, cvsmodule
,
159 configure
=None, configureEnv
={},
161 test
="make check", cvsCopy
=False):
163 source
= s(CVS
, cvsroot
=cvsroot
, cvsmodule
=cvsmodule
, mode
=mode
)
164 GNUAutoconf
.__init
__(self
, source
,
165 configure
=configure
, configureEnv
=configureEnv
,
169 class BasicSVN(GNUAutoconf
):
171 def __init__(self
, svnurl
,
172 configure
=None, configureEnv
={},
175 source
= s(SVN
, svnurl
=svnurl
, mode
="update")
176 GNUAutoconf
.__init
__(self
, source
,
177 configure
=configure
, configureEnv
=configureEnv
,