blob: eb6cf81c7cf24c7b963d7ae763476fa04d764cd9 [file] [log] [blame]
Daniel Dunbar235aa412009-07-18 07:16:15 +00001import buildbot
2import buildbot.process.factory
Renato Goline6c1b3b2015-07-01 15:52:22 +00003import copy
David Deanf8b35442012-12-11 00:35:12 +00004import os
Daniel Sandersfa222332015-12-04 14:30:39 +00005from datetime import datetime
David Deanf8b35442012-12-11 00:35:12 +00006
Reid Kleckner25a26b02015-03-09 22:30:25 +00007from buildbot.process.properties import WithProperties, Property
David Blaikie8cbf62f2013-01-12 21:32:31 +00008from buildbot.steps.shell import Configure, ShellCommand, SetProperty
Daniel Dunbar44abe742009-07-19 01:59:03 +00009from buildbot.steps.shell import WarningCountingShellCommand
David Deanf8b35442012-12-11 00:35:12 +000010from buildbot.steps.source import SVN
Daniel Dunbar44abe742009-07-19 01:59:03 +000011from buildbot.steps.transfer import FileDownload
Michael Gottesmana6b5be82013-06-28 21:57:20 +000012
Michael Gottesman960bcfa2013-08-30 05:46:15 +000013import zorg.buildbot.util.artifacts as artifacts
Michael Gottesmana6b5be82013-06-28 21:57:20 +000014import zorg.buildbot.builders.Util as builders_util
Michael Gottesmandc771a02013-08-30 05:46:22 +000015import zorg.buildbot.util.phasedbuilderutils as phasedbuilderutils
Michael Gottesmana6b5be82013-06-28 21:57:20 +000016import zorg.buildbot.commands as commands
17import zorg.buildbot.commands.BatchFileDownload as batch_file_download
18import zorg.buildbot.commands.LitTestCommand as lit_test_command
Galina Kistanova49cbd602017-04-14 23:46:03 +000019from zorg.buildbot.conditions.FileConditions import FileDoesNotExist
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +000020
Galina Kistanovaf4d79352011-10-20 20:46:52 +000021def getClangBuildFactory(
22 triple=None,
23 clean=True,
24 test=True,
25 package_dst=None,
26 run_cxx_tests=False,
27 examples=False,
28 valgrind=False,
29 valgrindLeakCheck=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +000030 useTwoStage=False,
31 completely_clean=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +000032 make='make',
33 jobs="%(jobs)s",
34 stage1_config='Debug+Asserts',
35 stage2_config='Release+Asserts',
36 env={}, # Environmental variables for all steps.
37 extra_configure_args=[],
Vassil Vassilev5a9b9ed2016-05-25 17:10:03 +000038 stage2_extra_configure_args=[],
Galina Kistanovaf4d79352011-10-20 20:46:52 +000039 use_pty_in_tests=False,
Peter Collingbourned49ac282011-10-25 14:38:45 +000040 trunk_revision=None,
41 force_checkout=False,
Peter Collingbourne7a95b0c2011-10-26 16:40:17 +000042 extra_clean_step=None,
David Blaikiea76da842012-08-13 22:24:46 +000043 checkout_compiler_rt=False,
Galina Kistanova2ab1e2d2016-11-22 00:23:43 +000044 checkout_lld=False,
David Blaikiea76da842012-08-13 22:24:46 +000045 run_gdb=False,
David Blaikiedad03d52012-11-16 22:37:12 +000046 run_modern_gdb=False,
Vassil Vassilev0c647ef2016-06-30 21:16:45 +000047 run_gcc=False):
Galina Kistanovaf4d79352011-10-20 20:46:52 +000048 # Prepare environmental variables. Set here all env we want everywhere.
49 merged_env = {
50 'TERM' : 'dumb' # Make sure Clang doesn't use color escape sequences.
51 }
52 if env is not None:
53 # Overwrite pre-set items with the given ones, so user can set anything.
54 merged_env.update(env)
David Blaikie2f7eb282012-08-24 18:37:00 +000055
Jonathan Roelofs62415e52015-02-28 00:03:17 +000056 llvm_srcdir = "llvm.src"
57 llvm_1_objdir = "llvm.obj"
58 llvm_1_installdir = "llvm.install.1"
59 llvm_2_objdir = "llvm.obj.2"
60 llvm_2_installdir = "llvm.install"
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +000061
Daniel Dunbar235aa412009-07-18 07:16:15 +000062 f = buildbot.process.factory.BuildFactory()
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +000063
64 # Determine the build directory.
65 f.addStep(buildbot.steps.shell.SetProperty(name="get_builddir",
66 command=["pwd"],
67 property="builddir",
68 description="set build dir",
Galina Kistanovaf4d79352011-10-20 20:46:52 +000069 workdir=".",
70 env=merged_env))
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +000071
Daniel Dunbar06b20f12010-04-08 18:29:38 +000072 # Blow away completely, if requested.
73 if completely_clean:
74 f.addStep(ShellCommand(name="rm-llvm.src",
75 command=["rm", "-rf", llvm_srcdir],
76 haltOnFailure=True,
77 description=["rm src dir", "llvm"],
Galina Kistanovaf4d79352011-10-20 20:46:52 +000078 workdir=".",
79 env=merged_env))
Daniel Dunbar06b20f12010-04-08 18:29:38 +000080
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +000081 # Checkout sources.
Peter Collingbourned49ac282011-10-25 14:38:45 +000082 if trunk_revision:
83 # The SVN build step provides no mechanism to check out a specific revision
84 # based on a property, so just run the commands directly here.
85 svn_co = ['svn', 'checkout']
86 if force_checkout:
87 svn_co += ['--force']
88 svn_co += ['--revision', WithProperties(trunk_revision)]
89
90 svn_co_llvm = svn_co + \
91 [WithProperties('http://llvm.org/svn/llvm-project/llvm/trunk@%s' %
92 trunk_revision),
93 llvm_srcdir]
94 svn_co_clang = svn_co + \
95 [WithProperties('http://llvm.org/svn/llvm-project/cfe/trunk@%s' %
96 trunk_revision),
97 '%s/tools/clang' % llvm_srcdir]
David Blaikie845ae0d2012-08-10 00:51:38 +000098 svn_co_clang_tools_extra = svn_co + \
99 [WithProperties('http://llvm.org/svn/llvm-project/clang-tools-extra/trunk@%s' %
100 trunk_revision),
101 '%s/tools/clang/tools/extra' % llvm_srcdir]
Peter Collingbourned49ac282011-10-25 14:38:45 +0000102
103 f.addStep(ShellCommand(name='svn-llvm',
104 command=svn_co_llvm,
105 haltOnFailure=True,
106 workdir='.'))
107 f.addStep(ShellCommand(name='svn-clang',
108 command=svn_co_clang,
109 haltOnFailure=True,
110 workdir='.'))
David Blaikie845ae0d2012-08-10 00:51:38 +0000111 f.addStep(ShellCommand(name='svn-clang-tools-extra',
112 command=svn_co_clang_tools_extra,
113 haltOnFailure=True,
114 workdir='.'))
Peter Collingbourned49ac282011-10-25 14:38:45 +0000115 else:
116 f.addStep(SVN(name='svn-llvm',
Daniel Dunbarf4e23eb2010-09-20 21:13:02 +0000117 mode='update',
Peter Collingbourned49ac282011-10-25 14:38:45 +0000118 baseURL='http://llvm.org/svn/llvm-project/llvm/',
Daniel Dunbarf4e23eb2010-09-20 21:13:02 +0000119 defaultBranch='trunk',
Peter Collingbourned49ac282011-10-25 14:38:45 +0000120 workdir=llvm_srcdir))
121 f.addStep(SVN(name='svn-clang',
122 mode='update',
123 baseURL='http://llvm.org/svn/llvm-project/cfe/',
124 defaultBranch='trunk',
125 workdir='%s/tools/clang' % llvm_srcdir))
David Blaikie845ae0d2012-08-10 00:51:38 +0000126 f.addStep(SVN(name='svn-clang-tools-extra',
127 mode='update',
128 baseURL='http://llvm.org/svn/llvm-project/clang-tools-extra/',
129 defaultBranch='trunk',
130 workdir='%s/tools/clang/tools/extra' % llvm_srcdir))
Peter Collingbourned49ac282011-10-25 14:38:45 +0000131 if checkout_compiler_rt:
132 f.addStep(SVN(name='svn-compiler-rt',
133 mode='update',
134 baseURL='http://llvm.org/svn/llvm-project/compiler-rt/',
135 defaultBranch='trunk',
136 workdir='%s/projects/compiler-rt' % llvm_srcdir))
Daniel Dunbarfa0e0222009-11-09 06:08:28 +0000137
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000138 # Clean up llvm (stage 1); unless in-dir.
139 if clean and llvm_srcdir != llvm_1_objdir:
140 f.addStep(ShellCommand(name="rm-llvm.obj.stage1",
141 command=["rm", "-rf", llvm_1_objdir],
142 haltOnFailure=True,
143 description=["rm build dir", "llvm"],
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000144 workdir=".",
145 env=merged_env))
Andrew Trick70fa9d22011-08-25 23:38:51 +0000146
David Blaikie8cbf62f2013-01-12 21:32:31 +0000147 if not clean:
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000148 expected_makefile = 'Makefile'
David Blaikie8cbf62f2013-01-12 21:32:31 +0000149 f.addStep(SetProperty(name="Makefile_isready",
150 workdir=llvm_1_objdir,
151 command=["sh", "-c",
Richard Smith02389162014-09-26 23:53:06 +0000152 "test -e %s && echo OK || echo Missing" % expected_makefile],
David Blaikie8cbf62f2013-01-12 21:32:31 +0000153 flunkOnFailure=False,
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000154 property="exists_Makefile"))
Richard Smith02389162014-09-26 23:53:06 +0000155
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000156 cmake_triple_arg = []
157 if triple:
158 cmake_triple_arg = ['-DLLVM_HOST_TRIPLE=%s' % triple]
159 f.addStep(ShellCommand(name='cmake',
160 command=['cmake',
161 '-DLLVM_BUILD_TESTS=ON',
162 '-DCMAKE_BUILD_TYPE=%s' % stage1_config] +
163 cmake_triple_arg +
164 extra_configure_args +
165 ["../" + llvm_srcdir],
166 description='cmake stage1',
167 workdir=llvm_1_objdir,
168 env=merged_env,
169 doStepIf=lambda step: step.build.getProperty("exists_Makefile") != "OK"))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000170
171 # Make clean if using in-dir builds.
172 if clean and llvm_srcdir == llvm_1_objdir:
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +0000173 f.addStep(WarningCountingShellCommand(name="clean-llvm",
Daniel Dunbard20468a2009-11-24 18:27:23 +0000174 command=[make, "clean"],
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +0000175 haltOnFailure=True,
176 description="cleaning llvm",
177 descriptionDone="clean llvm",
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000178 workdir=llvm_1_objdir,
Peter Collingbourne7a95b0c2011-10-26 16:40:17 +0000179 doStepIf=clean,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000180 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000181
Peter Collingbourne7a95b0c2011-10-26 16:40:17 +0000182 if extra_clean_step:
183 f.addStep(extra_clean_step)
184
Daniel Dunbar7e959c82009-09-28 04:01:19 +0000185 f.addStep(WarningCountingShellCommand(name="compile",
Daniel Dunbard20468a2009-11-24 18:27:23 +0000186 command=['nice', '-n', '10',
187 make, WithProperties("-j%s" % jobs)],
Daniel Dunbar7e959c82009-09-28 04:01:19 +0000188 haltOnFailure=True,
David Blaikie05517332013-12-19 23:29:12 +0000189 flunkOnFailure=not run_gdb,
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000190 description=["compiling", stage1_config],
191 descriptionDone=["compile", stage1_config],
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000192 workdir=llvm_1_objdir,
193 env=merged_env))
Daniel Dunbar256fed42009-11-25 21:11:08 +0000194
195 if examples:
196 f.addStep(WarningCountingShellCommand(name="compile.examples",
197 command=['nice', '-n', '10',
198 make, WithProperties("-j%s" % jobs),
199 "BUILD_EXAMPLES=1"],
200 haltOnFailure=True,
Richard Smith65e6f5d2014-09-25 18:18:35 +0000201 description=["compiling", stage1_config, "examples"],
Daniel Dunbar256fed42009-11-25 21:11:08 +0000202 descriptionDone=["compile", stage1_config, "examples"],
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000203 workdir=llvm_1_objdir,
204 env=merged_env))
Daniel Dunbar256fed42009-11-25 21:11:08 +0000205
NAKAMURA Takumi1a4666b2013-01-19 03:39:07 +0000206 clangTestArgs = '-v -j %s' % jobs
Daniel Dunbarfa0e0222009-11-09 06:08:28 +0000207 if valgrind:
Daniel Dunbar89184b92010-04-18 19:09:32 +0000208 clangTestArgs += ' --vg'
Daniel Dunbara1bebce2010-03-21 01:24:00 +0000209 if valgrindLeakCheck:
210 clangTestArgs += ' --vg-leak'
Nick Lewycky8d26e472011-08-27 21:18:56 +0000211 clangTestArgs += ' --vg-arg --suppressions=%(builddir)s/llvm/tools/clang/utils/valgrind/x86_64-pc-linux-gnu_gcc-4.3.3.supp --vg-arg --suppressions=%(builddir)s/llvm/utils/valgrind/x86_64-pc-linux-gnu.supp'
Daniel Dunbarfa0e0222009-11-09 06:08:28 +0000212 extraTestDirs = ''
213 if run_cxx_tests:
214 extraTestDirs += '%(builddir)s/llvm/tools/clang/utils/C++Tests'
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +0000215 if test:
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000216 f.addStep(lit_test_command.LitTestCommand(name='check-all',
David Blaikie7e6f8a12012-08-31 20:46:27 +0000217 command=[make, "check-all", "VERBOSE=1",
NAKAMURA Takumi1a4666b2013-01-19 03:39:07 +0000218 WithProperties("LIT_ARGS=%s" % clangTestArgs),
David Blaikiebc684012012-12-27 20:44:19 +0000219 WithProperties("EXTRA_TESTDIRS=%s" % extraTestDirs)],
David Blaikie05517332013-12-19 23:29:12 +0000220 flunkOnFailure=not run_gdb,
David Blaikie7e6f8a12012-08-31 20:46:27 +0000221 description=["checking"],
222 descriptionDone=["checked"],
Daniel Dunbar469e8ca2010-05-19 21:26:48 +0000223 workdir=llvm_1_objdir,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000224 usePTY=use_pty_in_tests,
225 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000226
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000227 # TODO: Install llvm and clang for stage1.
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000228
David Blaikiedad03d52012-11-16 22:37:12 +0000229 if run_gdb or run_gcc or run_modern_gdb:
David Blaikiea76da842012-08-13 22:24:46 +0000230 ignores = getClangTestsIgnoresFromPath(os.path.expanduser('~/public/clang-tests'), 'clang-x86_64-darwin10')
231 install_prefix = "%%(builddir)s/%s" % llvm_1_installdir
232 if run_gdb:
233 addClangGDBTests(f, ignores, install_prefix)
David Blaikiedad03d52012-11-16 22:37:12 +0000234 if run_modern_gdb:
David Blaikie41d09c32013-01-02 21:11:09 +0000235 addModernClangGDBTests(f, jobs, install_prefix)
David Blaikiea76da842012-08-13 22:24:46 +0000236 if run_gcc:
237 addClangGCCTests(f, ignores, install_prefix)
238
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000239 if not useTwoStage:
Daniel Dunbardedf6572010-11-13 00:23:34 +0000240 if package_dst:
241 name = WithProperties(
242 "%(builddir)s/" + llvm_1_objdir +
243 "/clang-r%(got_revision)s-b%(buildnumber)s.tgz")
244 f.addStep(ShellCommand(name='pkg.tar',
245 description="tar root",
246 command=["tar", "zcvf", name, "./"],
247 workdir=llvm_1_installdir,
248 warnOnFailure=True,
249 flunkOnFailure=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000250 haltOnFailure=False,
251 env=merged_env))
Daniel Dunbardedf6572010-11-13 00:23:34 +0000252 f.addStep(ShellCommand(name='pkg.upload',
Andrew Trick70fa9d22011-08-25 23:38:51 +0000253 description="upload root",
Daniel Dunbardedf6572010-11-13 00:23:34 +0000254 command=["scp", name,
255 WithProperties(
256 package_dst + "/%(buildername)s")],
257 workdir=".",
258 warnOnFailure=True,
259 flunkOnFailure=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000260 haltOnFailure=False,
261 env=merged_env))
Daniel Dunbardedf6572010-11-13 00:23:34 +0000262
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000263 return f
264
265 # Clean up llvm (stage 2).
Richard Smith02389162014-09-26 23:53:06 +0000266 #
Galina Kistanova79900972015-11-16 17:30:42 +0000267 # We always cleanly build the stage 2. If the compiler has been
268 # changed on the stage 1, we cannot trust any of the intermediate file
269 # from the old compiler. And if the stage 1 compiler is the same, we should
270 # not build in the first place.
271 f.addStep(ShellCommand(name="rm-llvm.obj.stage2",
272 command=["rm", "-rf", llvm_2_objdir],
273 haltOnFailure=True,
274 description=["rm build dir", "llvm", "(stage 2)"],
275 workdir=".",
276 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000277
278 # Configure llvm (stage 2).
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000279 f.addStep(ShellCommand(name='cmake',
Vassil Vassilev5a9b9ed2016-05-25 17:10:03 +0000280 command=['cmake'] + stage2_extra_configure_args + [
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000281 '-DLLVM_BUILD_TESTS=ON',
282 WithProperties('-DCMAKE_C_COMPILER=%%(builddir)s/%s/bin/clang' % llvm_1_objdir), # FIXME use installdir
283 WithProperties('-DCMAKE_CXX_COMPILER=%%(builddir)s/%s/bin/clang++' % llvm_1_objdir),
284 '-DCMAKE_BUILD_TYPE=%s' % stage2_config,
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000285 "../" + llvm_srcdir],
286 description='cmake stage2',
287 workdir=llvm_2_objdir,
288 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000289
290 # Build llvm (stage 2).
291 f.addStep(WarningCountingShellCommand(name="compile.llvm.stage2",
292 command=['nice', '-n', '10',
293 make, WithProperties("-j%s" % jobs)],
294 haltOnFailure=True,
295 description=["compiling", "(stage 2)",
296 stage2_config],
297 descriptionDone=["compile", "(stage 2)",
298 stage2_config],
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000299 workdir=llvm_2_objdir,
300 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000301
302 if test:
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000303 f.addStep(lit_test_command.LitTestCommand(name='check-all',
David Blaikie7e6f8a12012-08-31 20:46:27 +0000304 command=[make, "check-all", "VERBOSE=1",
NAKAMURA Takumi1a4666b2013-01-19 03:39:07 +0000305 WithProperties("LIT_ARGS=%s" % clangTestArgs),
David Blaikiebc684012012-12-27 20:44:19 +0000306 WithProperties("EXTRA_TESTDIRS=%s" % extraTestDirs)],
David Blaikie7e6f8a12012-08-31 20:46:27 +0000307 description=["checking"],
308 descriptionDone=["checked"],
Daniel Dunbar469e8ca2010-05-19 21:26:48 +0000309 workdir=llvm_2_objdir,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000310 usePTY=use_pty_in_tests,
311 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000312
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000313 # TODO: Install llvm and clang for stage2.
Daniel Dunbar3efb7822010-02-26 19:20:00 +0000314
315 if package_dst:
316 name = WithProperties(
317 "%(builddir)s/" + llvm_2_objdir +
318 "/clang-r%(got_revision)s-b%(buildnumber)s.tgz")
319 f.addStep(ShellCommand(name='pkg.tar',
320 description="tar root",
321 command=["tar", "zcvf", name, "./"],
322 workdir=llvm_2_installdir,
323 warnOnFailure=True,
324 flunkOnFailure=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000325 haltOnFailure=False,
326 env=merged_env))
Daniel Dunbar3efb7822010-02-26 19:20:00 +0000327 f.addStep(ShellCommand(name='pkg.upload',
Andrew Trick70fa9d22011-08-25 23:38:51 +0000328 description="upload root",
Daniel Dunbar3efb7822010-02-26 19:20:00 +0000329 command=["scp", name,
330 WithProperties(
331 package_dst + "/%(buildername)s")],
332 workdir=".",
333 warnOnFailure=True,
334 flunkOnFailure=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000335 haltOnFailure=False,
336 env=merged_env))
Daniel Dunbar3efb7822010-02-26 19:20:00 +0000337
Daniel Dunbar235aa412009-07-18 07:16:15 +0000338 return f
Daniel Dunbar44abe742009-07-19 01:59:03 +0000339
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000340def addSVNUpdateSteps(f,
341 checkout_clang_tools_extra,
342 checkout_compiler_rt,
Renato Golin0bd2a532016-11-20 16:14:35 +0000343 checkout_test_suite,
Artem Belevich16fcd0e2016-12-21 21:15:56 +0000344 checkout_lld,
345 checkout_libcxx):
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000346 # We *must* checkout at least Clang+LLVM
347 f.addStep(SVN(name='svn-llvm',
348 mode='update', baseURL='http://llvm.org/svn/llvm-project/llvm/',
349 defaultBranch='trunk',
350 workdir='llvm'))
351 f.addStep(SVN(name='svn-clang',
352 mode='update', baseURL='http://llvm.org/svn/llvm-project/cfe/',
353 defaultBranch='trunk',
354 workdir='llvm/tools/clang'))
355
356 # Extra stuff that will be built/tested
357 if checkout_clang_tools_extra:
358 f.addStep(SVN(name='svn-clang-tools-extra',
359 mode='update', baseURL='http://llvm.org/svn/llvm-project/clang-tools-extra/',
360 defaultBranch='trunk',
361 workdir='llvm/tools/clang/tools/extra'))
362 if checkout_compiler_rt:
363 f.addStep(SVN(name='svn-compiler-rt',
364 mode='update', baseURL='http://llvm.org/svn/llvm-project/compiler-rt/',
365 defaultBranch='trunk',
366 workdir='llvm/projects/compiler-rt'))
367 if checkout_test_suite:
368 f.addStep(SVN(name='svn-lnt',
369 mode='update', baseURL='http://llvm.org/svn/llvm-project/lnt/',
370 defaultBranch='trunk',
371 workdir='test/lnt'))
372 f.addStep(SVN(name='svn-test-suite',
Galina Kistanovaa86d0c72018-04-04 00:54:30 +0000373 mode='update', baseURL='https://llvm.org/svn/llvm-project/test-suite/',
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000374 defaultBranch='trunk',
375 workdir='test/test-suite'))
Renato Golin0bd2a532016-11-20 16:14:35 +0000376 if checkout_lld:
377 f.addStep(SVN(name='svn-lld',
378 mode='update', baseURL='http://llvm.org/svn/llvm-project/lld/',
379 defaultBranch='trunk',
380 workdir='llvm/tools/lld'))
Artem Belevich16fcd0e2016-12-21 21:15:56 +0000381 if checkout_libcxx:
382 f.addStep(SVN(name='svn-libcxx',
383 mode='update',
384 baseURL='http://llvm.org/svn/llvm-project/libcxx/',
385 defaultBranch='trunk',
386 workdir='llvm/projects/libcxx'))
387 f.addStep(SVN(name='svn-libcxxabi',
388 mode='update',
389 baseURL='http://llvm.org/svn/llvm-project/libcxxabi/',
390 defaultBranch='trunk',
391 workdir='llvm/projects/libcxxabi'))
392 f.addStep(SVN(name='svn-libunwind',
393 mode='update',
394 baseURL='http://llvm.org/svn/llvm-project/libunwind/',
395 defaultBranch='trunk',
396 workdir='llvm/projects/libunwind'))
Renato Goline402f582014-09-04 19:25:24 +0000397
Daniel Sandersfa222332015-12-04 14:30:39 +0000398def addGCSUploadSteps(f, package_name, install_prefix, gcs_directory, env,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000399 gcs_url_property=None, use_pixz_compression=False,
400 xz_compression_factor=6):
Daniel Sandersfa222332015-12-04 14:30:39 +0000401 """
402 Add steps to upload to the Google Cloud Storage bucket.
403
404 f - The BuildFactory to modify.
405 package_name - The name of this package for the descriptions (e.g.
406 'stage 1')
407 install_prefix - The directory the build has been installed to.
408 gcs_directory - The subdirectory of the bucket root to upload to. This
409 should match the builder name.
410 env - The environment to use. Set BOTO_CONFIG to use a configuration file
411 in a non-standard location, and BUCKET to use a different GCS bucket.
412 gcs_url_property - Property to assign the GCS url to.
413 """
414
415 gcs_url_fmt = ('gs://%(gcs_bucket)s/%(gcs_directory)s/'
416 'clang-r%(got_revision)s-t%(now)s-b%(buildnumber)s.tar.xz')
417 time_fmt = '%Y-%m-%d_%H-%M-%S'
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000418 output_file_name = '../install.tar.xz'
419
Daniel Sandersfa222332015-12-04 14:30:39 +0000420 gcs_url = \
421 WithProperties(
422 gcs_url_fmt,
423 gcs_bucket=lambda _: env.get('BUCKET', 'llvm-build-artifacts'),
424 gcs_directory=lambda _: gcs_directory,
425 now=lambda _: datetime.utcnow().strftime(time_fmt))
426
427 if gcs_url_property:
428 f.addStep(SetProperty(
429 name="record GCS url for " + package_name,
430 command=['echo', gcs_url],
431 property=gcs_url_property))
432
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000433 if use_pixz_compression:
434 # tweak the xz compression level to generate packages faster
435 tar_command = ['tar', '-Ipixz', '-cvf', output_file_name, '.']
436 else:
437 xz_command = 'xz -{0}'.format(xz_compression_factor)
438 tar_command = ['tar', '-I', xz_command, '-cvf', output_file_name, '.']
439
Daniel Sandersfa222332015-12-04 14:30:39 +0000440 f.addStep(ShellCommand(name='package ' + package_name,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000441 command=tar_command,
Daniel Sandersfa222332015-12-04 14:30:39 +0000442 description='packaging ' + package_name + '...',
443 workdir=install_prefix,
444 env=env))
445
446 f.addStep(ShellCommand(
447 name='upload ' + package_name + ' to storage bucket',
448 command=['gsutil', 'cp', '../install.tar.xz', gcs_url],
449 description=('uploading ' + package_name +
450 'to storage bucket ...'),
451 workdir=install_prefix,
452 env=env))
453
454def getClangCMakeGCSBuildFactory(
455 clean=True,
456 test=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000457 cmake='cmake',
Daniel Sandersfa222332015-12-04 14:30:39 +0000458 jobs=None,
459
460 # VS tools environment variable if using MSVC. For example,
461 # %VS120COMNTOOLS% selects the 2013 toolchain.
462 vs=None,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000463 vs_target_arch='x86',
Daniel Sandersfa222332015-12-04 14:30:39 +0000464
465 # Multi-stage compilation
466 useTwoStage=False,
467 testStage1=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000468 stage1_config='Release',
469 stage2_config='Release',
Daniel Sandersfa222332015-12-04 14:30:39 +0000470
471 # Test-suite
472 runTestSuite=False,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000473 nt_flags=[],
Kristof Beylsf4639b52017-08-10 08:53:52 +0000474 testsuite_flags=[],
Daniel Sandersfa222332015-12-04 14:30:39 +0000475 submitURL=None,
476 testerName=None,
477
478 # Environmental variables for all steps.
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000479 env={},
480 extra_cmake_args=[],
Daniel Sandersfa222332015-12-04 14:30:39 +0000481
482 # Extra repositories
483 checkout_clang_tools_extra=True,
484 checkout_compiler_rt=True,
Renato Golin0bd2a532016-11-20 16:14:35 +0000485 checkout_lld=True,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000486 checkout_libcxx=False,
Daniel Sandersfa222332015-12-04 14:30:39 +0000487
488 # Upload artifacts to Google Cloud Storage (for the llvmbisect tool)
489 stage1_upload_directory=None,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000490
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000491 # Use a lower compression level to generate the build-cache package faster.
492 # defuault is 6 according to xz documentation
493 xz_compression_factor=6,
494 use_pixz_compression=False,
495
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000496 # Triggers
497 trigger_after_stage1=[]):
Daniel Sandersfa222332015-12-04 14:30:39 +0000498 return _getClangCMakeBuildFactory(
Stella Stamenovae9bbc272018-10-26 18:17:50 +0000499 clean=clean, test=test, cmake=cmake, jobs=jobs, vs=vs,
500 vs_target_arch=vs_target_arch, useTwoStage=useTwoStage,
Daniel Sandersfa222332015-12-04 14:30:39 +0000501 testStage1=testStage1, stage1_config=stage1_config,
502 stage2_config=stage2_config, runTestSuite=runTestSuite,
Kristof Beylsf4639b52017-08-10 08:53:52 +0000503 nt_flags=nt_flags, testsuite_flags=testsuite_flags,
504 submitURL=submitURL, testerName=testerName,
Daniel Sandersfa222332015-12-04 14:30:39 +0000505 env=env, extra_cmake_args=extra_cmake_args,
506 checkout_clang_tools_extra=checkout_clang_tools_extra,
507 checkout_compiler_rt=checkout_compiler_rt,
Renato Golin0bd2a532016-11-20 16:14:35 +0000508 checkout_lld=checkout_lld,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000509 checkout_libcxx=checkout_libcxx,
Daniel Sandersfa222332015-12-04 14:30:39 +0000510 stage1_upload_directory=stage1_upload_directory,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000511 xz_compression_factor=xz_compression_factor,
512 use_pixz_compression=use_pixz_compression,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000513 trigger_after_stage1=trigger_after_stage1)
Reid Kleckner25a26b02015-03-09 22:30:25 +0000514
515def getClangCMakeBuildFactory(
516 clean=True,
517 test=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000518 cmake='cmake',
Reid Kleckner25a26b02015-03-09 22:30:25 +0000519 jobs=None,
520
521 # VS tools environment variable if using MSVC. For example,
522 # %VS120COMNTOOLS% selects the 2013 toolchain.
523 vs=None,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000524 vs_target_arch='x86',
Reid Kleckner25a26b02015-03-09 22:30:25 +0000525
526 # Multi-stage compilation
527 useTwoStage=False,
528 testStage1=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000529 stage1_config='Release',
530 stage2_config='Release',
Reid Kleckner25a26b02015-03-09 22:30:25 +0000531
Renato Golin61aed7f2015-06-17 19:12:50 +0000532 # Test-suite
533 runTestSuite=False,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000534 nt_flags=[],
Kristof Beylsf4639b52017-08-10 08:53:52 +0000535 testsuite_flags=[],
Renato Golin61aed7f2015-06-17 19:12:50 +0000536 submitURL=None,
537 testerName=None,
538
Reid Kleckner25a26b02015-03-09 22:30:25 +0000539 # Environmental variables for all steps.
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000540 env={},
541 extra_cmake_args=[],
Reid Kleckner25a26b02015-03-09 22:30:25 +0000542
543 # Extra repositories
544 checkout_clang_tools_extra=True,
Renato Golin0bd2a532016-11-20 16:14:35 +0000545 checkout_compiler_rt=True,
Artem Belevich16fcd0e2016-12-21 21:15:56 +0000546 checkout_lld=True,
547 checkout_libcxx=False,
548 checkout_test_suite=False):
Daniel Sandersfa222332015-12-04 14:30:39 +0000549 return _getClangCMakeBuildFactory(
Stella Stamenovae9bbc272018-10-26 18:17:50 +0000550 clean=clean, test=test, cmake=cmake, jobs=jobs, vs=vs,
551 vs_target_arch=vs_target_arch, useTwoStage=useTwoStage,
Daniel Sandersfa222332015-12-04 14:30:39 +0000552 testStage1=testStage1, stage1_config=stage1_config,
553 stage2_config=stage2_config, runTestSuite=runTestSuite,
Kristof Beylsf4639b52017-08-10 08:53:52 +0000554 nt_flags=nt_flags, testsuite_flags=testsuite_flags,
555 submitURL=submitURL, testerName=testerName,
Daniel Sandersfa222332015-12-04 14:30:39 +0000556 env=env, extra_cmake_args=extra_cmake_args,
557 checkout_clang_tools_extra=checkout_clang_tools_extra,
Renato Golin0bd2a532016-11-20 16:14:35 +0000558 checkout_lld=checkout_lld,
Artem Belevich16fcd0e2016-12-21 21:15:56 +0000559 checkout_compiler_rt=checkout_compiler_rt,
560 checkout_libcxx=checkout_libcxx,
561 checkout_test_suite=checkout_test_suite)
Daniel Sandersfa222332015-12-04 14:30:39 +0000562
563def _getClangCMakeBuildFactory(
564 clean=True,
565 test=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000566 cmake='cmake',
Daniel Sandersfa222332015-12-04 14:30:39 +0000567 jobs=None,
568
569 # VS tools environment variable if using MSVC. For example,
570 # %VS120COMNTOOLS% selects the 2013 toolchain.
571 vs=None,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000572 vs_target_arch='x86',
Daniel Sandersfa222332015-12-04 14:30:39 +0000573
574 # Multi-stage compilation
575 useTwoStage=False,
576 testStage1=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000577 stage1_config='Release',
578 stage2_config='Release',
Daniel Sandersfa222332015-12-04 14:30:39 +0000579
580 # Test-suite
581 runTestSuite=False,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000582 nt_flags=[],
Kristof Beylsf4639b52017-08-10 08:53:52 +0000583 testsuite_flags=[],
Daniel Sandersfa222332015-12-04 14:30:39 +0000584 submitURL=None,
585 testerName=None,
586
587 # Environmental variables for all steps.
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000588 env={},
589 extra_cmake_args=[],
Daniel Sandersfa222332015-12-04 14:30:39 +0000590
591 # Extra repositories
592 checkout_clang_tools_extra=True,
593 checkout_compiler_rt=True,
Renato Golin0bd2a532016-11-20 16:14:35 +0000594 checkout_lld=True,
Artem Belevich16fcd0e2016-12-21 21:15:56 +0000595 checkout_libcxx=False,
596 checkout_test_suite=False,
Daniel Sandersfa222332015-12-04 14:30:39 +0000597
598 # Upload artifacts to Google Cloud Storage (for the llvmbisect tool)
599 stage1_upload_directory=None,
600
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000601 # Use a lower compression level to generate the build-cache package faster
602 # default is 6 according to documentation
603 xz_compression_factor=6,
604 use_pixz_compression=False,
605
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000606 # Triggers
607 trigger_after_stage1=[]):
Reid Kleckner25a26b02015-03-09 22:30:25 +0000608
609 ############# PREPARING
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000610 f = buildbot.process.factory.BuildFactory()
Reid Kleckner25a26b02015-03-09 22:30:25 +0000611
Galina Kistanova49cbd602017-04-14 23:46:03 +0000612 clean_build_requested = lambda step: clean or step.build.getProperty("clean")
613
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000614 addSVNUpdateSteps(f,
615 checkout_clang_tools_extra=checkout_clang_tools_extra,
616 checkout_compiler_rt=checkout_compiler_rt,
Renato Golin0bd2a532016-11-20 16:14:35 +0000617 checkout_lld=checkout_lld,
Artem Belevich16fcd0e2016-12-21 21:15:56 +0000618 checkout_test_suite=runTestSuite or checkout_test_suite,
619 checkout_libcxx=checkout_libcxx)
Reid Kleckner25a26b02015-03-09 22:30:25 +0000620
Renato Goline402f582014-09-04 19:25:24 +0000621 # If jobs not defined, Ninja will choose a suitable value
Renato Golincc83db32015-06-17 19:23:40 +0000622 jobs_cmd = []
623 lit_args = "'-v"
Renato Goline402f582014-09-04 19:25:24 +0000624 if jobs is not None:
Renato Golincc83db32015-06-17 19:23:40 +0000625 jobs_cmd = ["-j"+str(jobs)]
626 lit_args += " -j"+str(jobs)+"'"
Renato Goline402f582014-09-04 19:25:24 +0000627 else:
Renato Golincc83db32015-06-17 19:23:40 +0000628 lit_args += "'"
629 ninja_cmd = ['ninja'] + jobs_cmd
630 ninja_install_cmd = ['ninja', 'install'] + jobs_cmd
631 ninja_check_cmd = ['ninja', 'check-all'] + jobs_cmd
Renato Goline402f582014-09-04 19:25:24 +0000632
633 # Global configurations
Renato Golincc83db32015-06-17 19:23:40 +0000634 stage1_build = 'stage1'
635 stage1_install = 'stage1.install'
636 stage2_build = 'stage2'
637 stage2_install = 'stage2.install'
Renato Goline402f582014-09-04 19:25:24 +0000638
Reid Kleckner25a26b02015-03-09 22:30:25 +0000639 # Set up VS environment, if appropriate.
Stella Stamenovae9bbc272018-10-26 18:17:50 +0000640 if vs:
Reid Kleckner25a26b02015-03-09 22:30:25 +0000641 f.addStep(SetProperty(
Stella Stamenovae9bbc272018-10-26 18:17:50 +0000642 command=builders_util.getVisualStudioEnvironment(vs, vs_target_arch),
Reid Kleckner25a26b02015-03-09 22:30:25 +0000643 extract_fn=builders_util.extractSlaveEnvironment))
644 assert not env, "Can't have custom builder env vars with VS"
645 env = Property('slave_env')
646
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000647
Renato Goline402f582014-09-04 19:25:24 +0000648 ############# CLEANING
Galina Kistanova49cbd602017-04-14 23:46:03 +0000649 f.addStep(ShellCommand(name='clean stage 1',
650 command=['rm','-rf',stage1_build],
651 warnOnFailure=True,
652 haltOnFailure=False,
653 flunkOnFailure=False,
654 description='cleaning stage 1',
655 descriptionDone='clean',
656 workdir='.',
657 doStepIf=clean_build_requested))
Renato Goline402f582014-09-04 19:25:24 +0000658
659
660 ############# STAGE 1
661 f.addStep(ShellCommand(name='cmake stage 1',
662 command=[cmake, "-G", "Ninja", "../llvm",
663 "-DCMAKE_BUILD_TYPE="+stage1_config,
664 "-DLLVM_ENABLE_ASSERTIONS=True",
665 "-DLLVM_LIT_ARGS="+lit_args,
666 "-DCMAKE_INSTALL_PREFIX=../"+stage1_install]
667 + extra_cmake_args,
668 haltOnFailure=True,
669 description='cmake stage 1',
670 workdir=stage1_build,
Galina Kistanova49cbd602017-04-14 23:46:03 +0000671 doStepIf=FileDoesNotExist("build.ninja"),
Renato Goline402f582014-09-04 19:25:24 +0000672 env=env))
673
674 f.addStep(WarningCountingShellCommand(name='build stage 1',
675 command=ninja_cmd,
676 haltOnFailure=True,
677 description='ninja all',
678 workdir=stage1_build,
679 env=env))
680
681 if test and testStage1:
Renato Golind1c46742015-08-06 18:05:34 +0000682 haltOnStage1Check = not useTwoStage and not runTestSuite
Renato Golincfbd5702014-09-06 19:09:16 +0000683 f.addStep(lit_test_command.LitTestCommand(name='ninja check 1',
684 command=ninja_check_cmd,
Renato Golind1c46742015-08-06 18:05:34 +0000685 haltOnFailure=haltOnStage1Check,
Renato Golincfbd5702014-09-06 19:09:16 +0000686 description=["checking stage 1"],
687 descriptionDone=["stage 1 checked"],
688 workdir=stage1_build,
689 env=env))
Renato Goline402f582014-09-04 19:25:24 +0000690
Daniel Sandersfa222332015-12-04 14:30:39 +0000691 if useTwoStage or runTestSuite or stage1_upload_directory:
Galina Kistanova49cbd602017-04-14 23:46:03 +0000692 f.addStep(ShellCommand(name='clean stage 1 install',
693 command=['rm','-rf',stage1_install],
694 warnOnFailure=True,
695 haltOnFailure=False,
696 flunkOnFailure=False,
697 description='cleaning stage 1 install',
698 descriptionDone='clean',
699 workdir='.'))
Renato Golin61aed7f2015-06-17 19:12:50 +0000700 f.addStep(ShellCommand(name='install stage 1',
701 command=ninja_install_cmd,
702 description='ninja install',
703 workdir=stage1_build,
Renato Goline402f582014-09-04 19:25:24 +0000704 env=env))
Renato Goline402f582014-09-04 19:25:24 +0000705
Daniel Sandersfa222332015-12-04 14:30:39 +0000706 if stage1_upload_directory:
707 addGCSUploadSteps(f, 'stage 1', stage1_install, stage1_upload_directory,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000708 env, gcs_url_property='stage1_package_gcs_url',
709 use_pixz_compression=use_pixz_compression,
710 xz_compression_factor=xz_compression_factor)
Daniel Sandersfa222332015-12-04 14:30:39 +0000711
Reid Kleckner25a26b02015-03-09 22:30:25 +0000712 # Compute the cmake define flag to set the C and C++ compiler to clang. Use
713 # clang-cl if we used MSVC for stage1.
714 if not vs:
715 cc = 'clang'
716 cxx = 'clang++'
717 else:
718 cc = 'clang-cl.exe'
719 cxx = 'clang-cl.exe'
720
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000721
Renato Golin61aed7f2015-06-17 19:12:50 +0000722 ############# STAGE 2
723 if useTwoStage:
Galina Kistanova79900972015-11-16 17:30:42 +0000724 # We always cleanly build the stage 2. If the compiler has been
725 # changed on the stage 1, we cannot trust any of the intermediate file
726 # from the old compiler. And if the stage 1 compiler is the same, we
727 # should not build in the first place.
728 f.addStep(ShellCommand(name='clean stage 2',
729 command=['rm','-rf',stage2_build],
730 warnOnFailure=True,
731 description='cleaning stage 2',
732 descriptionDone='clean',
Galina Kistanova49cbd602017-04-14 23:46:03 +0000733 workdir='.'))
Reid Kleckner25a26b02015-03-09 22:30:25 +0000734
Renato Golin61aed7f2015-06-17 19:12:50 +0000735 # Set the compiler using the CC and CXX environment variables to work around
736 # backslash string escaping bugs somewhere between buildbot and cmake. The
737 # env.exe helper is required to run the tests, so hopefully it's already on
738 # PATH.
739 cmake_cmd2 = ['env',
740 WithProperties('CC=%(workdir)s/'+stage1_install+'/bin/'+cc),
741 WithProperties('CXX=%(workdir)s/'+stage1_install+'/bin/'+cxx),
742 cmake, "-G", "Ninja", "../llvm",
743 "-DCMAKE_BUILD_TYPE="+stage2_config,
744 "-DLLVM_ENABLE_ASSERTIONS=True",
745 "-DLLVM_LIT_ARGS="+lit_args,
746 "-DCMAKE_INSTALL_PREFIX=../"+stage2_install] + extra_cmake_args
Reid Kleckner25a26b02015-03-09 22:30:25 +0000747
Renato Golin61aed7f2015-06-17 19:12:50 +0000748 f.addStep(ShellCommand(name='cmake stage 2',
749 command=cmake_cmd2,
750 haltOnFailure=True,
751 description='cmake stage 2',
752 workdir=stage2_build,
Renato Golin61aed7f2015-06-17 19:12:50 +0000753 env=env))
754
755 f.addStep(WarningCountingShellCommand(name='build stage 2',
756 command=ninja_cmd,
757 haltOnFailure=True,
758 description='ninja all',
759 workdir=stage2_build,
760 env=env))
761
762 if test:
763 f.addStep(lit_test_command.LitTestCommand(name='ninja check 2',
764 command=ninja_check_cmd,
765 haltOnFailure=not runTestSuite,
766 description=["checking stage 2"],
767 descriptionDone=["stage 2 checked"],
768 workdir=stage2_build,
769 env=env))
770
771 ############# TEST SUITE
772 ## Test-Suite (stage 2 if built, stage 1 otherwise)
773 if runTestSuite:
774 compiler_path = stage1_install
775 if useTwoStage:
776 compiler_path=stage2_install
Galina Kistanova49cbd602017-04-14 23:46:03 +0000777 f.addStep(ShellCommand(name='clean stage 2 install',
778 command=['rm','-rf',stage2_install],
779 warnOnFailure=True,
780 description='cleaning stage 2 install',
781 descriptionDone='clean',
782 workdir='.'))
Renato Golin61aed7f2015-06-17 19:12:50 +0000783 f.addStep(ShellCommand(name='install stage 2',
784 command=ninja_install_cmd,
785 description='ninja install 2',
Renato Golincfbd5702014-09-06 19:09:16 +0000786 workdir=stage2_build,
787 env=env))
Renato Goline402f582014-09-04 19:25:24 +0000788
Renato Golin61aed7f2015-06-17 19:12:50 +0000789 # Get generated python, lnt
790 python = WithProperties('%(workdir)s/test/sandbox/bin/python')
791 lnt = WithProperties('%(workdir)s/test/sandbox/bin/lnt')
792 lnt_setup = WithProperties('%(workdir)s/test/lnt/setup.py')
793
794 # Paths
795 sandbox = WithProperties('%(workdir)s/test/sandbox')
796 test_suite_dir = WithProperties('%(workdir)s/test/test-suite')
797
798 # Get latest built Clang (stage1 or stage2)
799 cc = WithProperties('%(workdir)s/'+compiler_path+'/bin/'+cc)
800 cxx = WithProperties('%(workdir)s/'+compiler_path+'/bin/'+cxx)
801
Renato Golin593e0d62016-09-21 17:24:56 +0000802 # LNT Command line (don't pass -jN. Users need to pass both --threads
Kristof Beylsf4639b52017-08-10 08:53:52 +0000803 # and --build-threads in nt_flags/test_suite_flags to get the same effect)
804 use_runtest_testsuite = len(nt_flags) == 0
805 if not use_runtest_testsuite:
806 test_suite_cmd = [python, lnt, 'runtest', 'nt',
807 '--no-timestamp',
808 '--sandbox', sandbox,
809 '--test-suite', test_suite_dir,
810 '--cc', cc,
811 '--cxx', cxx]
812 # Append any option provided by the user
813 test_suite_cmd.extend(nt_flags)
814 else:
815 lit = WithProperties('%(workdir)s/'+stage1_build+'/bin/llvm-lit')
816 test_suite_cmd = [python, lnt, 'runtest', 'test-suite',
817 '--no-timestamp',
818 '--sandbox', sandbox,
819 '--test-suite', test_suite_dir,
820 '--cc', cc,
821 '--cxx', cxx,
822 '--use-lit', lit]
823 # Append any option provided by the user
824 test_suite_cmd.extend(testsuite_flags)
825
Renato Golin61aed7f2015-06-17 19:12:50 +0000826 # Only submit if a URL has been specified
827 if submitURL is not None:
828 if not isinstance(submitURL, list):
829 submitURL = [submitURL]
830 for url in submitURL:
831 test_suite_cmd.extend(['--submit', url])
Kristof Beylsf4639b52017-08-10 08:53:52 +0000832 # lnt runtest test-suite doesn't understand --no-machdep-info:
833 if testerName and not use_runtest_testsuite:
Renato Golin61aed7f2015-06-17 19:12:50 +0000834 test_suite_cmd.extend(['--no-machdep-info', testerName])
835 # CC and CXX are needed as env for build-tools
Renato Goline6c1b3b2015-07-01 15:52:22 +0000836 test_suite_env = copy.deepcopy(env)
Renato Golin61aed7f2015-06-17 19:12:50 +0000837 test_suite_env['CC'] = cc
838 test_suite_env['CXX'] = cxx
839
840 # Steps to prepare, build and run LNT
841 f.addStep(ShellCommand(name='clean sandbox',
842 command=['rm', '-rf', 'sandbox'],
843 haltOnFailure=True,
844 description='removing sandbox directory',
845 workdir='test',
846 env=env))
847 f.addStep(ShellCommand(name='recreate sandbox',
848 command=['virtualenv', 'sandbox'],
849 haltOnFailure=True,
850 description='recreating sandbox',
851 workdir='test',
852 env=env))
853 f.addStep(ShellCommand(name='setup lit',
854 command=[python, lnt_setup, 'develop'],
855 haltOnFailure=True,
856 description='setting up LNT in sandbox',
857 workdir='test/sandbox',
858 env=env))
859 f.addStep(commands.LitTestCommand.LitTestCommand(
860 name='test-suite',
861 command=test_suite_cmd,
862 haltOnFailure=True,
863 description=['running the test suite'],
864 workdir='test/sandbox',
865 logfiles={'configure.log' : 'build/configure.log',
866 'build-tools.log' : 'build/build-tools.log',
867 'test.log' : 'build/test.log',
868 'report.json' : 'build/report.json'},
869 env=test_suite_env))
870
Renato Goline402f582014-09-04 19:25:24 +0000871 return f
872
Daniel Dunbar7363d032011-02-27 03:22:35 +0000873def addClangGCCTests(f, ignores={}, install_prefix="%(builddir)s/llvm.install",
874 languages = ('gcc', 'g++', 'objc', 'obj-c++')):
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000875 make_vars = [WithProperties(
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000876 'CC_UNDER_TEST=%s/bin/clang' % install_prefix),
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000877 WithProperties(
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000878 'CXX_UNDER_TEST=%s/bin/clang++' % install_prefix)]
David Blaikie05517332013-12-19 23:29:12 +0000879 f.addStep(SVN(name='svn-clang-gcc-tests', mode='update',
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000880 baseURL='http://llvm.org/svn/llvm-project/clang-tests/',
881 defaultBranch='trunk', workdir='clang-tests'))
882 gcc_dg_ignores = ignores.get('gcc-4_2-testsuite', {})
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000883 for lang in languages:
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000884 f.addStep(commands.SuppressionDejaGNUCommand.SuppressionDejaGNUCommand(
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000885 name='test-gcc-4_2-testsuite-%s' % lang,
886 command=["make", "-k", "check-%s" % lang] + make_vars,
887 description="gcc-4_2-testsuite (%s)" % lang,
888 workdir='clang-tests/gcc-4_2-testsuite',
David Dean2bd0c3a2011-10-18 16:36:28 +0000889 logfiles={ 'dg.sum' : 'obj/%s/%s.sum' % (lang, lang),
890 '%s.log' % lang : 'obj/%s/%s.log' % (lang, lang)},
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000891 ignore=gcc_dg_ignores.get(lang, [])))
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000892
Daniel Dunbar7363d032011-02-27 03:22:35 +0000893def addClangGDBTests(f, ignores={}, install_prefix="%(builddir)s/llvm.install"):
894 make_vars = [WithProperties(
895 'CC_UNDER_TEST=%s/bin/clang' % install_prefix),
896 WithProperties(
897 'CXX_UNDER_TEST=%s/bin/clang++' % install_prefix)]
David Blaikie05517332013-12-19 23:29:12 +0000898 f.addStep(SVN(name='svn-clang-gdb-tests', mode='update',
Daniel Dunbar7363d032011-02-27 03:22:35 +0000899 baseURL='http://llvm.org/svn/llvm-project/clang-tests/',
900 defaultBranch='trunk', workdir='clang-tests'))
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000901 f.addStep(commands.SuppressionDejaGNUCommand.SuppressionDejaGNUCommand(
Daniel Dunbar7363d032011-02-27 03:22:35 +0000902 name='test-gdb-1472-testsuite',
903 command=["make", "-k", "check"] + make_vars,
904 description="gdb-1472-testsuite",
905 workdir='clang-tests/gdb-1472-testsuite',
David Blaikie7ec695f2012-10-09 22:17:09 +0000906 logfiles={ 'dg.sum' : 'obj/filtered.gdb.sum',
David Blaikie624f4392012-11-05 22:34:35 +0000907 'gdb.log' : 'obj/gdb.log' }))
Daniel Dunbar7363d032011-02-27 03:22:35 +0000908
David Blaikie41d09c32013-01-02 21:11:09 +0000909def addModernClangGDBTests(f, jobs, install_prefix):
David Blaikie1bc5c372012-12-05 05:29:12 +0000910 make_vars = [WithProperties('RUNTESTFLAGS=CC_FOR_TARGET=\'{0}/bin/clang\' '
911 'CXX_FOR_TARGET=\'{0}/bin/clang++\' '
David Blaikie759bb752013-04-18 23:13:11 +0000912 'CFLAGS_FOR_TARGET=\'-w -fno-limit-debug-info\''
David Blaikief89877b2013-01-29 23:46:26 +0000913 .format(install_prefix))]
David Blaikie05517332013-12-19 23:29:12 +0000914 f.addStep(SVN(name='svn-clang-modern-gdb-tests', mode='update',
David Blaikief3f300b2012-11-17 01:13:41 +0000915 svnurl='http://llvm.org/svn/llvm-project/clang-tests-external/trunk/gdb/7.5',
David Blaikiedad03d52012-11-16 22:37:12 +0000916 workdir='clang-tests/src'))
David Blaikieb83bfdf2012-12-05 04:33:42 +0000917 f.addStep(Configure(command='../src/configure',
David Blaikief3f300b2012-11-17 01:13:41 +0000918 workdir='clang-tests/build/'))
David Blaikieb83bfdf2012-12-05 04:33:42 +0000919 f.addStep(WarningCountingShellCommand(name='gdb-75-build',
920 command=['make', WithProperties('-j%s' % jobs)],
921 haltOnFailure=True,
922 workdir='clang-tests/build'))
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000923 f.addStep(commands.DejaGNUCommand.DejaGNUCommand(
David Blaikiedad03d52012-11-16 22:37:12 +0000924 name='gdb-75-check',
David Blaikieb83bfdf2012-12-05 04:33:42 +0000925 command=['make', '-k', WithProperties('-j%s' % jobs), 'check'] + make_vars,
David Blaikiedad03d52012-11-16 22:37:12 +0000926 workdir='clang-tests/build',
David Blaikie1bc5c372012-12-05 05:29:12 +0000927 logfiles={'dg.sum':'gdb/testsuite/gdb.sum',
928 'gdb.log':'gdb/testsuite/gdb.log'}))
David Blaikiedad03d52012-11-16 22:37:12 +0000929
930
931
Daniel Dunbar7363d032011-02-27 03:22:35 +0000932# FIXME: Deprecated.
933addClangTests = addClangGCCTests
934
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000935def getClangTestsIgnoresFromPath(path, key):
936 def readList(path):
937 if not os.path.exists(path):
938 return []
939
940 f = open(path)
941 lines = [ln.strip() for ln in f]
942 f.close()
943 return lines
944
945 ignores = {}
946
947 gcc_dg_ignores = {}
948 for lang in ('gcc', 'g++', 'objc', 'obj-c++'):
949 lang_path = os.path.join(path, 'gcc-4_2-testsuite', 'expected_results',
950 key, lang)
951 gcc_dg_ignores[lang] = (
952 readList(os.path.join(lang_path, 'FAIL.txt')) +
953 readList(os.path.join(lang_path, 'UNRESOLVED.txt')) +
954 readList(os.path.join(lang_path, 'XPASS.txt')))
955 ignores['gcc-4_2-testsuite' ] = gcc_dg_ignores
956
Daniel Dunbar7363d032011-02-27 03:22:35 +0000957 ignores_path = os.path.join(path, 'gdb-1472-testsuite', 'expected_results',
958 key)
959 gdb_dg_ignores = (
960 readList(os.path.join(ignores_path, 'FAIL.txt')) +
961 readList(os.path.join(ignores_path, 'UNRESOLVED.txt')) +
962 readList(os.path.join(ignores_path, 'XPASS.txt')))
963 ignores['gdb-1472-testsuite' ] = gdb_dg_ignores
964
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000965 return ignores