blob: 39709aed26b28d04e8855c2217116925c8310457 [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
Galina Kistanovab28be6d2019-10-18 05:31:36 +000020from zorg.buildbot.commands.CmakeCommand import CmakeCommand
Galina Kistanova5921add2018-11-14 05:34:46 +000021from zorg.buildbot.process.factory import LLVMBuildFactory
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +000022
Galina Kistanovab28be6d2019-10-18 05:31:36 +000023# FIXME: This method is deprecated and will be removed. Please use getClangCMakeBuildFactory instead.
Galina Kistanovaf4d79352011-10-20 20:46:52 +000024def getClangBuildFactory(
25 triple=None,
26 clean=True,
27 test=True,
28 package_dst=None,
29 run_cxx_tests=False,
30 examples=False,
31 valgrind=False,
32 valgrindLeakCheck=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +000033 useTwoStage=False,
34 completely_clean=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +000035 make='make',
36 jobs="%(jobs)s",
37 stage1_config='Debug+Asserts',
38 stage2_config='Release+Asserts',
39 env={}, # Environmental variables for all steps.
40 extra_configure_args=[],
Vassil Vassilev5a9b9ed2016-05-25 17:10:03 +000041 stage2_extra_configure_args=[],
Galina Kistanovaf4d79352011-10-20 20:46:52 +000042 use_pty_in_tests=False,
Peter Collingbourned49ac282011-10-25 14:38:45 +000043 trunk_revision=None,
44 force_checkout=False,
Peter Collingbourne7a95b0c2011-10-26 16:40:17 +000045 extra_clean_step=None,
David Blaikiea76da842012-08-13 22:24:46 +000046 checkout_compiler_rt=False,
Galina Kistanova2ab1e2d2016-11-22 00:23:43 +000047 checkout_lld=False,
David Blaikiea76da842012-08-13 22:24:46 +000048 run_gdb=False,
David Blaikiedad03d52012-11-16 22:37:12 +000049 run_modern_gdb=False,
Vassil Vassilev0c647ef2016-06-30 21:16:45 +000050 run_gcc=False):
Galina Kistanovaf4d79352011-10-20 20:46:52 +000051 # Prepare environmental variables. Set here all env we want everywhere.
52 merged_env = {
53 'TERM' : 'dumb' # Make sure Clang doesn't use color escape sequences.
54 }
55 if env is not None:
56 # Overwrite pre-set items with the given ones, so user can set anything.
57 merged_env.update(env)
David Blaikie2f7eb282012-08-24 18:37:00 +000058
Jonathan Roelofs62415e52015-02-28 00:03:17 +000059 llvm_srcdir = "llvm.src"
60 llvm_1_objdir = "llvm.obj"
61 llvm_1_installdir = "llvm.install.1"
62 llvm_2_objdir = "llvm.obj.2"
63 llvm_2_installdir = "llvm.install"
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +000064
Daniel Dunbar235aa412009-07-18 07:16:15 +000065 f = buildbot.process.factory.BuildFactory()
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +000066
67 # Determine the build directory.
68 f.addStep(buildbot.steps.shell.SetProperty(name="get_builddir",
69 command=["pwd"],
70 property="builddir",
71 description="set build dir",
Galina Kistanovaf4d79352011-10-20 20:46:52 +000072 workdir=".",
73 env=merged_env))
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +000074
Daniel Dunbar06b20f12010-04-08 18:29:38 +000075 # Blow away completely, if requested.
76 if completely_clean:
77 f.addStep(ShellCommand(name="rm-llvm.src",
78 command=["rm", "-rf", llvm_srcdir],
79 haltOnFailure=True,
80 description=["rm src dir", "llvm"],
Galina Kistanovaf4d79352011-10-20 20:46:52 +000081 workdir=".",
82 env=merged_env))
Daniel Dunbar06b20f12010-04-08 18:29:38 +000083
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +000084 # Checkout sources.
Peter Collingbourned49ac282011-10-25 14:38:45 +000085 if trunk_revision:
86 # The SVN build step provides no mechanism to check out a specific revision
87 # based on a property, so just run the commands directly here.
88 svn_co = ['svn', 'checkout']
89 if force_checkout:
90 svn_co += ['--force']
91 svn_co += ['--revision', WithProperties(trunk_revision)]
92
93 svn_co_llvm = svn_co + \
94 [WithProperties('http://llvm.org/svn/llvm-project/llvm/trunk@%s' %
95 trunk_revision),
96 llvm_srcdir]
97 svn_co_clang = svn_co + \
98 [WithProperties('http://llvm.org/svn/llvm-project/cfe/trunk@%s' %
99 trunk_revision),
100 '%s/tools/clang' % llvm_srcdir]
David Blaikie845ae0d2012-08-10 00:51:38 +0000101 svn_co_clang_tools_extra = svn_co + \
102 [WithProperties('http://llvm.org/svn/llvm-project/clang-tools-extra/trunk@%s' %
103 trunk_revision),
104 '%s/tools/clang/tools/extra' % llvm_srcdir]
Peter Collingbourned49ac282011-10-25 14:38:45 +0000105
106 f.addStep(ShellCommand(name='svn-llvm',
107 command=svn_co_llvm,
108 haltOnFailure=True,
109 workdir='.'))
110 f.addStep(ShellCommand(name='svn-clang',
111 command=svn_co_clang,
112 haltOnFailure=True,
113 workdir='.'))
David Blaikie845ae0d2012-08-10 00:51:38 +0000114 f.addStep(ShellCommand(name='svn-clang-tools-extra',
115 command=svn_co_clang_tools_extra,
116 haltOnFailure=True,
117 workdir='.'))
Peter Collingbourned49ac282011-10-25 14:38:45 +0000118 else:
119 f.addStep(SVN(name='svn-llvm',
Daniel Dunbarf4e23eb2010-09-20 21:13:02 +0000120 mode='update',
Peter Collingbourned49ac282011-10-25 14:38:45 +0000121 baseURL='http://llvm.org/svn/llvm-project/llvm/',
Daniel Dunbarf4e23eb2010-09-20 21:13:02 +0000122 defaultBranch='trunk',
Peter Collingbourned49ac282011-10-25 14:38:45 +0000123 workdir=llvm_srcdir))
124 f.addStep(SVN(name='svn-clang',
125 mode='update',
126 baseURL='http://llvm.org/svn/llvm-project/cfe/',
127 defaultBranch='trunk',
128 workdir='%s/tools/clang' % llvm_srcdir))
David Blaikie845ae0d2012-08-10 00:51:38 +0000129 f.addStep(SVN(name='svn-clang-tools-extra',
130 mode='update',
131 baseURL='http://llvm.org/svn/llvm-project/clang-tools-extra/',
132 defaultBranch='trunk',
133 workdir='%s/tools/clang/tools/extra' % llvm_srcdir))
Peter Collingbourned49ac282011-10-25 14:38:45 +0000134 if checkout_compiler_rt:
135 f.addStep(SVN(name='svn-compiler-rt',
136 mode='update',
137 baseURL='http://llvm.org/svn/llvm-project/compiler-rt/',
138 defaultBranch='trunk',
139 workdir='%s/projects/compiler-rt' % llvm_srcdir))
Daniel Dunbarfa0e0222009-11-09 06:08:28 +0000140
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000141 # Clean up llvm (stage 1); unless in-dir.
142 if clean and llvm_srcdir != llvm_1_objdir:
143 f.addStep(ShellCommand(name="rm-llvm.obj.stage1",
144 command=["rm", "-rf", llvm_1_objdir],
145 haltOnFailure=True,
146 description=["rm build dir", "llvm"],
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000147 workdir=".",
148 env=merged_env))
Andrew Trick70fa9d22011-08-25 23:38:51 +0000149
David Blaikie8cbf62f2013-01-12 21:32:31 +0000150 if not clean:
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000151 expected_makefile = 'Makefile'
David Blaikie8cbf62f2013-01-12 21:32:31 +0000152 f.addStep(SetProperty(name="Makefile_isready",
153 workdir=llvm_1_objdir,
154 command=["sh", "-c",
Richard Smith02389162014-09-26 23:53:06 +0000155 "test -e %s && echo OK || echo Missing" % expected_makefile],
David Blaikie8cbf62f2013-01-12 21:32:31 +0000156 flunkOnFailure=False,
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000157 property="exists_Makefile"))
Richard Smith02389162014-09-26 23:53:06 +0000158
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000159 cmake_triple_arg = []
160 if triple:
161 cmake_triple_arg = ['-DLLVM_HOST_TRIPLE=%s' % triple]
162 f.addStep(ShellCommand(name='cmake',
163 command=['cmake',
164 '-DLLVM_BUILD_TESTS=ON',
165 '-DCMAKE_BUILD_TYPE=%s' % stage1_config] +
166 cmake_triple_arg +
167 extra_configure_args +
168 ["../" + llvm_srcdir],
169 description='cmake stage1',
170 workdir=llvm_1_objdir,
171 env=merged_env,
172 doStepIf=lambda step: step.build.getProperty("exists_Makefile") != "OK"))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000173
174 # Make clean if using in-dir builds.
175 if clean and llvm_srcdir == llvm_1_objdir:
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +0000176 f.addStep(WarningCountingShellCommand(name="clean-llvm",
Daniel Dunbard20468a2009-11-24 18:27:23 +0000177 command=[make, "clean"],
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +0000178 haltOnFailure=True,
179 description="cleaning llvm",
180 descriptionDone="clean llvm",
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000181 workdir=llvm_1_objdir,
Peter Collingbourne7a95b0c2011-10-26 16:40:17 +0000182 doStepIf=clean,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000183 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000184
Peter Collingbourne7a95b0c2011-10-26 16:40:17 +0000185 if extra_clean_step:
186 f.addStep(extra_clean_step)
187
Daniel Dunbar7e959c82009-09-28 04:01:19 +0000188 f.addStep(WarningCountingShellCommand(name="compile",
Daniel Dunbard20468a2009-11-24 18:27:23 +0000189 command=['nice', '-n', '10',
190 make, WithProperties("-j%s" % jobs)],
Daniel Dunbar7e959c82009-09-28 04:01:19 +0000191 haltOnFailure=True,
David Blaikie05517332013-12-19 23:29:12 +0000192 flunkOnFailure=not run_gdb,
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000193 description=["compiling", stage1_config],
194 descriptionDone=["compile", stage1_config],
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000195 workdir=llvm_1_objdir,
196 env=merged_env))
Daniel Dunbar256fed42009-11-25 21:11:08 +0000197
198 if examples:
199 f.addStep(WarningCountingShellCommand(name="compile.examples",
200 command=['nice', '-n', '10',
201 make, WithProperties("-j%s" % jobs),
202 "BUILD_EXAMPLES=1"],
203 haltOnFailure=True,
Richard Smith65e6f5d2014-09-25 18:18:35 +0000204 description=["compiling", stage1_config, "examples"],
Daniel Dunbar256fed42009-11-25 21:11:08 +0000205 descriptionDone=["compile", stage1_config, "examples"],
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000206 workdir=llvm_1_objdir,
207 env=merged_env))
Daniel Dunbar256fed42009-11-25 21:11:08 +0000208
NAKAMURA Takumi1a4666b2013-01-19 03:39:07 +0000209 clangTestArgs = '-v -j %s' % jobs
Daniel Dunbarfa0e0222009-11-09 06:08:28 +0000210 if valgrind:
Daniel Dunbar89184b92010-04-18 19:09:32 +0000211 clangTestArgs += ' --vg'
Daniel Dunbara1bebce2010-03-21 01:24:00 +0000212 if valgrindLeakCheck:
213 clangTestArgs += ' --vg-leak'
Nick Lewycky8d26e472011-08-27 21:18:56 +0000214 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 +0000215 extraTestDirs = ''
216 if run_cxx_tests:
217 extraTestDirs += '%(builddir)s/llvm/tools/clang/utils/C++Tests'
Daniel Dunbarb51f6ab2009-11-09 03:09:23 +0000218 if test:
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000219 f.addStep(lit_test_command.LitTestCommand(name='check-all',
David Blaikie7e6f8a12012-08-31 20:46:27 +0000220 command=[make, "check-all", "VERBOSE=1",
NAKAMURA Takumi1a4666b2013-01-19 03:39:07 +0000221 WithProperties("LIT_ARGS=%s" % clangTestArgs),
David Blaikiebc684012012-12-27 20:44:19 +0000222 WithProperties("EXTRA_TESTDIRS=%s" % extraTestDirs)],
David Blaikie05517332013-12-19 23:29:12 +0000223 flunkOnFailure=not run_gdb,
David Blaikie7e6f8a12012-08-31 20:46:27 +0000224 description=["checking"],
225 descriptionDone=["checked"],
Daniel Dunbar469e8ca2010-05-19 21:26:48 +0000226 workdir=llvm_1_objdir,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000227 usePTY=use_pty_in_tests,
228 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000229
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000230 # TODO: Install llvm and clang for stage1.
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000231
David Blaikiedad03d52012-11-16 22:37:12 +0000232 if run_gdb or run_gcc or run_modern_gdb:
David Blaikiea76da842012-08-13 22:24:46 +0000233 ignores = getClangTestsIgnoresFromPath(os.path.expanduser('~/public/clang-tests'), 'clang-x86_64-darwin10')
234 install_prefix = "%%(builddir)s/%s" % llvm_1_installdir
235 if run_gdb:
236 addClangGDBTests(f, ignores, install_prefix)
David Blaikiedad03d52012-11-16 22:37:12 +0000237 if run_modern_gdb:
David Blaikie41d09c32013-01-02 21:11:09 +0000238 addModernClangGDBTests(f, jobs, install_prefix)
David Blaikiea76da842012-08-13 22:24:46 +0000239 if run_gcc:
240 addClangGCCTests(f, ignores, install_prefix)
241
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000242 if not useTwoStage:
Daniel Dunbardedf6572010-11-13 00:23:34 +0000243 if package_dst:
244 name = WithProperties(
245 "%(builddir)s/" + llvm_1_objdir +
246 "/clang-r%(got_revision)s-b%(buildnumber)s.tgz")
247 f.addStep(ShellCommand(name='pkg.tar',
248 description="tar root",
249 command=["tar", "zcvf", name, "./"],
250 workdir=llvm_1_installdir,
251 warnOnFailure=True,
252 flunkOnFailure=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000253 haltOnFailure=False,
254 env=merged_env))
Daniel Dunbardedf6572010-11-13 00:23:34 +0000255 f.addStep(ShellCommand(name='pkg.upload',
Andrew Trick70fa9d22011-08-25 23:38:51 +0000256 description="upload root",
Daniel Dunbardedf6572010-11-13 00:23:34 +0000257 command=["scp", name,
258 WithProperties(
259 package_dst + "/%(buildername)s")],
260 workdir=".",
261 warnOnFailure=True,
262 flunkOnFailure=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000263 haltOnFailure=False,
264 env=merged_env))
Daniel Dunbardedf6572010-11-13 00:23:34 +0000265
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000266 return f
267
268 # Clean up llvm (stage 2).
Richard Smith02389162014-09-26 23:53:06 +0000269 #
Galina Kistanova79900972015-11-16 17:30:42 +0000270 # We always cleanly build the stage 2. If the compiler has been
271 # changed on the stage 1, we cannot trust any of the intermediate file
272 # from the old compiler. And if the stage 1 compiler is the same, we should
273 # not build in the first place.
274 f.addStep(ShellCommand(name="rm-llvm.obj.stage2",
275 command=["rm", "-rf", llvm_2_objdir],
276 haltOnFailure=True,
277 description=["rm build dir", "llvm", "(stage 2)"],
278 workdir=".",
279 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000280
281 # Configure llvm (stage 2).
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000282 f.addStep(ShellCommand(name='cmake',
Vassil Vassilev5a9b9ed2016-05-25 17:10:03 +0000283 command=['cmake'] + stage2_extra_configure_args + [
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000284 '-DLLVM_BUILD_TESTS=ON',
285 WithProperties('-DCMAKE_C_COMPILER=%%(builddir)s/%s/bin/clang' % llvm_1_objdir), # FIXME use installdir
286 WithProperties('-DCMAKE_CXX_COMPILER=%%(builddir)s/%s/bin/clang++' % llvm_1_objdir),
287 '-DCMAKE_BUILD_TYPE=%s' % stage2_config,
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000288 "../" + llvm_srcdir],
289 description='cmake stage2',
290 workdir=llvm_2_objdir,
291 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000292
293 # Build llvm (stage 2).
294 f.addStep(WarningCountingShellCommand(name="compile.llvm.stage2",
295 command=['nice', '-n', '10',
296 make, WithProperties("-j%s" % jobs)],
297 haltOnFailure=True,
298 description=["compiling", "(stage 2)",
299 stage2_config],
300 descriptionDone=["compile", "(stage 2)",
301 stage2_config],
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000302 workdir=llvm_2_objdir,
303 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000304
305 if test:
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000306 f.addStep(lit_test_command.LitTestCommand(name='check-all',
David Blaikie7e6f8a12012-08-31 20:46:27 +0000307 command=[make, "check-all", "VERBOSE=1",
NAKAMURA Takumi1a4666b2013-01-19 03:39:07 +0000308 WithProperties("LIT_ARGS=%s" % clangTestArgs),
David Blaikiebc684012012-12-27 20:44:19 +0000309 WithProperties("EXTRA_TESTDIRS=%s" % extraTestDirs)],
David Blaikie7e6f8a12012-08-31 20:46:27 +0000310 description=["checking"],
311 descriptionDone=["checked"],
Daniel Dunbar469e8ca2010-05-19 21:26:48 +0000312 workdir=llvm_2_objdir,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000313 usePTY=use_pty_in_tests,
314 env=merged_env))
Daniel Dunbar8a89a6f2009-11-25 04:27:32 +0000315
Galina Kistanovaa06e4c82016-04-14 21:41:30 +0000316 # TODO: Install llvm and clang for stage2.
Daniel Dunbar3efb7822010-02-26 19:20:00 +0000317
318 if package_dst:
319 name = WithProperties(
320 "%(builddir)s/" + llvm_2_objdir +
321 "/clang-r%(got_revision)s-b%(buildnumber)s.tgz")
322 f.addStep(ShellCommand(name='pkg.tar',
323 description="tar root",
324 command=["tar", "zcvf", name, "./"],
325 workdir=llvm_2_installdir,
326 warnOnFailure=True,
327 flunkOnFailure=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000328 haltOnFailure=False,
329 env=merged_env))
Daniel Dunbar3efb7822010-02-26 19:20:00 +0000330 f.addStep(ShellCommand(name='pkg.upload',
Andrew Trick70fa9d22011-08-25 23:38:51 +0000331 description="upload root",
Daniel Dunbar3efb7822010-02-26 19:20:00 +0000332 command=["scp", name,
333 WithProperties(
334 package_dst + "/%(buildername)s")],
335 workdir=".",
336 warnOnFailure=True,
337 flunkOnFailure=False,
Galina Kistanovaf4d79352011-10-20 20:46:52 +0000338 haltOnFailure=False,
339 env=merged_env))
Daniel Dunbar3efb7822010-02-26 19:20:00 +0000340
Daniel Dunbar235aa412009-07-18 07:16:15 +0000341 return f
Daniel Dunbar44abe742009-07-19 01:59:03 +0000342
Daniel Sandersfa222332015-12-04 14:30:39 +0000343def addGCSUploadSteps(f, package_name, install_prefix, gcs_directory, env,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000344 gcs_url_property=None, use_pixz_compression=False,
345 xz_compression_factor=6):
Daniel Sandersfa222332015-12-04 14:30:39 +0000346 """
347 Add steps to upload to the Google Cloud Storage bucket.
348
349 f - The BuildFactory to modify.
350 package_name - The name of this package for the descriptions (e.g.
351 'stage 1')
352 install_prefix - The directory the build has been installed to.
353 gcs_directory - The subdirectory of the bucket root to upload to. This
354 should match the builder name.
355 env - The environment to use. Set BOTO_CONFIG to use a configuration file
356 in a non-standard location, and BUCKET to use a different GCS bucket.
357 gcs_url_property - Property to assign the GCS url to.
358 """
359
360 gcs_url_fmt = ('gs://%(gcs_bucket)s/%(gcs_directory)s/'
361 'clang-r%(got_revision)s-t%(now)s-b%(buildnumber)s.tar.xz')
362 time_fmt = '%Y-%m-%d_%H-%M-%S'
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000363 output_file_name = '../install.tar.xz'
364
Daniel Sandersfa222332015-12-04 14:30:39 +0000365 gcs_url = \
366 WithProperties(
367 gcs_url_fmt,
368 gcs_bucket=lambda _: env.get('BUCKET', 'llvm-build-artifacts'),
369 gcs_directory=lambda _: gcs_directory,
370 now=lambda _: datetime.utcnow().strftime(time_fmt))
371
372 if gcs_url_property:
373 f.addStep(SetProperty(
374 name="record GCS url for " + package_name,
375 command=['echo', gcs_url],
376 property=gcs_url_property))
377
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000378 if use_pixz_compression:
379 # tweak the xz compression level to generate packages faster
380 tar_command = ['tar', '-Ipixz', '-cvf', output_file_name, '.']
381 else:
382 xz_command = 'xz -{0}'.format(xz_compression_factor)
383 tar_command = ['tar', '-I', xz_command, '-cvf', output_file_name, '.']
384
Daniel Sandersfa222332015-12-04 14:30:39 +0000385 f.addStep(ShellCommand(name='package ' + package_name,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000386 command=tar_command,
Daniel Sandersfa222332015-12-04 14:30:39 +0000387 description='packaging ' + package_name + '...',
388 workdir=install_prefix,
389 env=env))
390
391 f.addStep(ShellCommand(
392 name='upload ' + package_name + ' to storage bucket',
393 command=['gsutil', 'cp', '../install.tar.xz', gcs_url],
394 description=('uploading ' + package_name +
395 'to storage bucket ...'),
396 workdir=install_prefix,
397 env=env))
398
399def getClangCMakeGCSBuildFactory(
400 clean=True,
401 test=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000402 cmake='cmake',
Daniel Sandersfa222332015-12-04 14:30:39 +0000403 jobs=None,
404
405 # VS tools environment variable if using MSVC. For example,
406 # %VS120COMNTOOLS% selects the 2013 toolchain.
407 vs=None,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000408 vs_target_arch='x86',
Daniel Sandersfa222332015-12-04 14:30:39 +0000409
410 # Multi-stage compilation
411 useTwoStage=False,
412 testStage1=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000413 stage1_config='Release',
414 stage2_config='Release',
Daniel Sandersfa222332015-12-04 14:30:39 +0000415
416 # Test-suite
417 runTestSuite=False,
Galina Kistanova84b11952019-10-17 04:07:11 +0000418 nt_flags=None,
419 testsuite_flags=None,
Daniel Sandersfa222332015-12-04 14:30:39 +0000420 submitURL=None,
421 testerName=None,
422
423 # Environmental variables for all steps.
Galina Kistanova84b11952019-10-17 04:07:11 +0000424 env=None,
425 extra_cmake_args=None,
Daniel Sandersfa222332015-12-04 14:30:39 +0000426
427 # Extra repositories
428 checkout_clang_tools_extra=True,
429 checkout_compiler_rt=True,
Renato Golin0bd2a532016-11-20 16:14:35 +0000430 checkout_lld=True,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000431 checkout_libcxx=False,
Daniel Sandersfa222332015-12-04 14:30:39 +0000432
433 # Upload artifacts to Google Cloud Storage (for the llvmbisect tool)
434 stage1_upload_directory=None,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000435
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000436 # Use a lower compression level to generate the build-cache package faster.
437 # defuault is 6 according to xz documentation
438 xz_compression_factor=6,
439 use_pixz_compression=False,
440
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000441 # Triggers
Galina Kistanova84b11952019-10-17 04:07:11 +0000442 trigger_after_stage1=None):
Daniel Sandersfa222332015-12-04 14:30:39 +0000443 return _getClangCMakeBuildFactory(
Stella Stamenovae9bbc272018-10-26 18:17:50 +0000444 clean=clean, test=test, cmake=cmake, jobs=jobs, vs=vs,
445 vs_target_arch=vs_target_arch, useTwoStage=useTwoStage,
Daniel Sandersfa222332015-12-04 14:30:39 +0000446 testStage1=testStage1, stage1_config=stage1_config,
447 stage2_config=stage2_config, runTestSuite=runTestSuite,
Kristof Beylsf4639b52017-08-10 08:53:52 +0000448 nt_flags=nt_flags, testsuite_flags=testsuite_flags,
449 submitURL=submitURL, testerName=testerName,
Daniel Sandersfa222332015-12-04 14:30:39 +0000450 env=env, extra_cmake_args=extra_cmake_args,
451 checkout_clang_tools_extra=checkout_clang_tools_extra,
452 checkout_compiler_rt=checkout_compiler_rt,
Renato Golin0bd2a532016-11-20 16:14:35 +0000453 checkout_lld=checkout_lld,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000454 checkout_libcxx=checkout_libcxx,
Daniel Sandersfa222332015-12-04 14:30:39 +0000455 stage1_upload_directory=stage1_upload_directory,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000456 xz_compression_factor=xz_compression_factor,
457 use_pixz_compression=use_pixz_compression,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000458 trigger_after_stage1=trigger_after_stage1)
Reid Kleckner25a26b02015-03-09 22:30:25 +0000459
460def getClangCMakeBuildFactory(
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000461 is_legacy_mode=True,
Reid Kleckner25a26b02015-03-09 22:30:25 +0000462 clean=True,
463 test=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000464 cmake='cmake',
Reid Kleckner25a26b02015-03-09 22:30:25 +0000465 jobs=None,
466
467 # VS tools environment variable if using MSVC. For example,
468 # %VS120COMNTOOLS% selects the 2013 toolchain.
469 vs=None,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000470 vs_target_arch='x86',
Reid Kleckner25a26b02015-03-09 22:30:25 +0000471
472 # Multi-stage compilation
473 useTwoStage=False,
474 testStage1=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000475 stage1_config='Release',
476 stage2_config='Release',
Reid Kleckner25a26b02015-03-09 22:30:25 +0000477
Renato Golin61aed7f2015-06-17 19:12:50 +0000478 # Test-suite
479 runTestSuite=False,
Galina Kistanova84b11952019-10-17 04:07:11 +0000480 nt_flags=None,
481 testsuite_flags=None,
Renato Golin61aed7f2015-06-17 19:12:50 +0000482 submitURL=None,
483 testerName=None,
484
Reid Kleckner25a26b02015-03-09 22:30:25 +0000485 # Environmental variables for all steps.
Galina Kistanova84b11952019-10-17 04:07:11 +0000486 env=None,
487 extra_cmake_args=None,
Reid Kleckner25a26b02015-03-09 22:30:25 +0000488
489 # Extra repositories
490 checkout_clang_tools_extra=True,
Renato Golin0bd2a532016-11-20 16:14:35 +0000491 checkout_compiler_rt=True,
Artem Belevich16fcd0e2016-12-21 21:15:56 +0000492 checkout_lld=True,
493 checkout_libcxx=False,
494 checkout_test_suite=False):
Daniel Sandersfa222332015-12-04 14:30:39 +0000495 return _getClangCMakeBuildFactory(
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000496 is_legacy_mode=is_legacy_mode,
Stella Stamenovae9bbc272018-10-26 18:17:50 +0000497 clean=clean, test=test, cmake=cmake, jobs=jobs, vs=vs,
498 vs_target_arch=vs_target_arch, useTwoStage=useTwoStage,
Daniel Sandersfa222332015-12-04 14:30:39 +0000499 testStage1=testStage1, stage1_config=stage1_config,
500 stage2_config=stage2_config, runTestSuite=runTestSuite,
Kristof Beylsf4639b52017-08-10 08:53:52 +0000501 nt_flags=nt_flags, testsuite_flags=testsuite_flags,
502 submitURL=submitURL, testerName=testerName,
Daniel Sandersfa222332015-12-04 14:30:39 +0000503 env=env, extra_cmake_args=extra_cmake_args,
504 checkout_clang_tools_extra=checkout_clang_tools_extra,
Renato Golin0bd2a532016-11-20 16:14:35 +0000505 checkout_lld=checkout_lld,
Artem Belevich16fcd0e2016-12-21 21:15:56 +0000506 checkout_compiler_rt=checkout_compiler_rt,
507 checkout_libcxx=checkout_libcxx,
508 checkout_test_suite=checkout_test_suite)
Daniel Sandersfa222332015-12-04 14:30:39 +0000509
510def _getClangCMakeBuildFactory(
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000511 is_legacy_mode=True,
Daniel Sandersfa222332015-12-04 14:30:39 +0000512 clean=True,
513 test=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000514 cmake='cmake',
Daniel Sandersfa222332015-12-04 14:30:39 +0000515 jobs=None,
516
517 # VS tools environment variable if using MSVC. For example,
518 # %VS120COMNTOOLS% selects the 2013 toolchain.
519 vs=None,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000520 vs_target_arch='x86',
Daniel Sandersfa222332015-12-04 14:30:39 +0000521
522 # Multi-stage compilation
523 useTwoStage=False,
524 testStage1=True,
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000525 stage1_config='Release',
526 stage2_config='Release',
Daniel Sandersfa222332015-12-04 14:30:39 +0000527
528 # Test-suite
529 runTestSuite=False,
Galina Kistanova84b11952019-10-17 04:07:11 +0000530 nt_flags=None,
531 testsuite_flags=None,
Daniel Sandersfa222332015-12-04 14:30:39 +0000532 submitURL=None,
533 testerName=None,
534
535 # Environmental variables for all steps.
Galina Kistanova84b11952019-10-17 04:07:11 +0000536 env=None,
537 extra_cmake_args=None,
Daniel Sandersfa222332015-12-04 14:30:39 +0000538
539 # Extra repositories
540 checkout_clang_tools_extra=True,
541 checkout_compiler_rt=True,
Renato Golin0bd2a532016-11-20 16:14:35 +0000542 checkout_lld=True,
Artem Belevich16fcd0e2016-12-21 21:15:56 +0000543 checkout_libcxx=False,
544 checkout_test_suite=False,
Daniel Sandersfa222332015-12-04 14:30:39 +0000545
546 # Upload artifacts to Google Cloud Storage (for the llvmbisect tool)
547 stage1_upload_directory=None,
548
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000549 # Use a lower compression level to generate the build-cache package faster
550 # default is 6 according to documentation
551 xz_compression_factor=6,
552 use_pixz_compression=False,
553
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000554 # Triggers
Galina Kistanova84b11952019-10-17 04:07:11 +0000555 trigger_after_stage1=None):
Reid Kleckner25a26b02015-03-09 22:30:25 +0000556
557 ############# PREPARING
Galina Kistanova84b11952019-10-17 04:07:11 +0000558 if nt_flags is None:
559 nt_flags = []
560 if testsuite_flags is None:
561 testsuite_flags = []
562 if env is None:
563 env = {}
564 if extra_cmake_args is None:
565 extra_cmake_args = []
566 if trigger_after_stage1 is None:
567 trigger_after_stage1 = []
568
Galina Kistanova5921add2018-11-14 05:34:46 +0000569 clean_build_requested = lambda step: \
570 step.build.getProperty( \
571 "clean", \
572 default=step.build.getProperty("clean_obj") \
573 ) or clean
Reid Kleckner25a26b02015-03-09 22:30:25 +0000574
Galina Kistanova5921add2018-11-14 05:34:46 +0000575 # We *must* checkout at least Clang+LLVM
576 depends_on_projects = ['llvm', 'clang']
577 if checkout_clang_tools_extra:
578 depends_on_projects.append('clang-tools-extra')
579 if checkout_compiler_rt:
580 depends_on_projects.append('compiler-rt')
581 if checkout_lld:
582 depends_on_projects.append('lld')
Galina Kistanova5921add2018-11-14 05:34:46 +0000583 if checkout_libcxx:
584 depends_on_projects.append('libcxx')
585 depends_on_projects.append('libcxxabi')
586 depends_on_projects.append('libunwind')
Galina Kistanova49cbd602017-04-14 23:46:03 +0000587
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000588 # Some projects are not a part of the monorepo.
589 # So, depending on the legacy mode, we
590 # would have to checkout them differently.
591 if is_legacy_mode and (runTestSuite or checkout_test_suite):
592 depends_on_projects.append('lnt')
593 depends_on_projects.append('test-suite')
594
Galina Kistanova5921add2018-11-14 05:34:46 +0000595 f = LLVMBuildFactory(
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000596 is_legacy_mode=is_legacy_mode,
Galina Kistanova5921add2018-11-14 05:34:46 +0000597 depends_on_projects=depends_on_projects,
598 llvm_srcdir='llvm')
599
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000600 # If we get the source code form the monorepo,
601 # we need to checkout the latest code for LNT
602 # and the test-suite separately. Le's do this first,
603 # so we wouldn't poison got_revision property.
604 if not is_legacy_mode and (runTestSuite or checkout_test_suite):
605 f.addGetSourcecodeForProject(
606 project='lnt',
607 src_dir='lnt',
608 alwaysUseLatest=True)
609 f.addGetSourcecodeForProject(
610 project='test-suite',
611 src_dir='test-suite',
612 alwaysUseLatest=True)
613
614 # Then get the LLVM source code revision this particular build is for.
615 f.addGetSourcecodeSteps()
Reid Kleckner25a26b02015-03-09 22:30:25 +0000616
Renato Goline402f582014-09-04 19:25:24 +0000617 # If jobs not defined, Ninja will choose a suitable value
Renato Golincc83db32015-06-17 19:23:40 +0000618 jobs_cmd = []
619 lit_args = "'-v"
Renato Goline402f582014-09-04 19:25:24 +0000620 if jobs is not None:
Renato Golincc83db32015-06-17 19:23:40 +0000621 jobs_cmd = ["-j"+str(jobs)]
622 lit_args += " -j"+str(jobs)+"'"
Renato Goline402f582014-09-04 19:25:24 +0000623 else:
Renato Golincc83db32015-06-17 19:23:40 +0000624 lit_args += "'"
625 ninja_cmd = ['ninja'] + jobs_cmd
626 ninja_install_cmd = ['ninja', 'install'] + jobs_cmd
627 ninja_check_cmd = ['ninja', 'check-all'] + jobs_cmd
Renato Goline402f582014-09-04 19:25:24 +0000628
629 # Global configurations
Renato Golincc83db32015-06-17 19:23:40 +0000630 stage1_build = 'stage1'
631 stage1_install = 'stage1.install'
632 stage2_build = 'stage2'
633 stage2_install = 'stage2.install'
Renato Goline402f582014-09-04 19:25:24 +0000634
Reid Kleckner25a26b02015-03-09 22:30:25 +0000635 # Set up VS environment, if appropriate.
Stella Stamenovae9bbc272018-10-26 18:17:50 +0000636 if vs:
Reid Kleckner25a26b02015-03-09 22:30:25 +0000637 f.addStep(SetProperty(
Stella Stamenovae9bbc272018-10-26 18:17:50 +0000638 command=builders_util.getVisualStudioEnvironment(vs, vs_target_arch),
Reid Kleckner25a26b02015-03-09 22:30:25 +0000639 extract_fn=builders_util.extractSlaveEnvironment))
640 assert not env, "Can't have custom builder env vars with VS"
641 env = Property('slave_env')
642
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000643
Renato Goline402f582014-09-04 19:25:24 +0000644 ############# CLEANING
Galina Kistanova49cbd602017-04-14 23:46:03 +0000645 f.addStep(ShellCommand(name='clean stage 1',
646 command=['rm','-rf',stage1_build],
647 warnOnFailure=True,
648 haltOnFailure=False,
649 flunkOnFailure=False,
650 description='cleaning stage 1',
651 descriptionDone='clean',
652 workdir='.',
653 doStepIf=clean_build_requested))
Renato Goline402f582014-09-04 19:25:24 +0000654
655
656 ############# STAGE 1
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000657 if not f.is_legacy_mode:
658 CmakeCommand.applyRequiredOptions(extra_cmake_args, [
659 ('-DLLVM_ENABLE_PROJECTS=', ";".join(f.depends_on_projects)),
660 ])
661 rel_src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, stage1_build)
662
Renato Goline402f582014-09-04 19:25:24 +0000663 f.addStep(ShellCommand(name='cmake stage 1',
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000664 command=[cmake, "-G", "Ninja", rel_src_dir,
Renato Goline402f582014-09-04 19:25:24 +0000665 "-DCMAKE_BUILD_TYPE="+stage1_config,
666 "-DLLVM_ENABLE_ASSERTIONS=True",
667 "-DLLVM_LIT_ARGS="+lit_args,
668 "-DCMAKE_INSTALL_PREFIX=../"+stage1_install]
669 + extra_cmake_args,
670 haltOnFailure=True,
671 description='cmake stage 1',
672 workdir=stage1_build,
Galina Kistanova49cbd602017-04-14 23:46:03 +0000673 doStepIf=FileDoesNotExist("build.ninja"),
Renato Goline402f582014-09-04 19:25:24 +0000674 env=env))
675
676 f.addStep(WarningCountingShellCommand(name='build stage 1',
677 command=ninja_cmd,
678 haltOnFailure=True,
679 description='ninja all',
680 workdir=stage1_build,
681 env=env))
682
683 if test and testStage1:
Renato Golind1c46742015-08-06 18:05:34 +0000684 haltOnStage1Check = not useTwoStage and not runTestSuite
Renato Golincfbd5702014-09-06 19:09:16 +0000685 f.addStep(lit_test_command.LitTestCommand(name='ninja check 1',
686 command=ninja_check_cmd,
Renato Golind1c46742015-08-06 18:05:34 +0000687 haltOnFailure=haltOnStage1Check,
Renato Golincfbd5702014-09-06 19:09:16 +0000688 description=["checking stage 1"],
689 descriptionDone=["stage 1 checked"],
690 workdir=stage1_build,
691 env=env))
Renato Goline402f582014-09-04 19:25:24 +0000692
Daniel Sandersfa222332015-12-04 14:30:39 +0000693 if useTwoStage or runTestSuite or stage1_upload_directory:
Galina Kistanova49cbd602017-04-14 23:46:03 +0000694 f.addStep(ShellCommand(name='clean stage 1 install',
695 command=['rm','-rf',stage1_install],
696 warnOnFailure=True,
697 haltOnFailure=False,
698 flunkOnFailure=False,
699 description='cleaning stage 1 install',
700 descriptionDone='clean',
701 workdir='.'))
Renato Golin61aed7f2015-06-17 19:12:50 +0000702 f.addStep(ShellCommand(name='install stage 1',
703 command=ninja_install_cmd,
704 description='ninja install',
705 workdir=stage1_build,
Renato Goline402f582014-09-04 19:25:24 +0000706 env=env))
Renato Goline402f582014-09-04 19:25:24 +0000707
Daniel Sandersfa222332015-12-04 14:30:39 +0000708 if stage1_upload_directory:
709 addGCSUploadSteps(f, 'stage 1', stage1_install, stage1_upload_directory,
Leandro Nunes7b83ba42018-06-25 13:54:50 +0000710 env, gcs_url_property='stage1_package_gcs_url',
711 use_pixz_compression=use_pixz_compression,
712 xz_compression_factor=xz_compression_factor)
Daniel Sandersfa222332015-12-04 14:30:39 +0000713
Reid Kleckner25a26b02015-03-09 22:30:25 +0000714 # Compute the cmake define flag to set the C and C++ compiler to clang. Use
715 # clang-cl if we used MSVC for stage1.
716 if not vs:
717 cc = 'clang'
718 cxx = 'clang++'
719 else:
720 cc = 'clang-cl.exe'
721 cxx = 'clang-cl.exe'
722
Galina Kistanovaff5e78a2016-09-06 17:44:53 +0000723
Renato Golin61aed7f2015-06-17 19:12:50 +0000724 ############# STAGE 2
725 if useTwoStage:
Galina Kistanova79900972015-11-16 17:30:42 +0000726 # We always cleanly build the stage 2. If the compiler has been
727 # changed on the stage 1, we cannot trust any of the intermediate file
728 # from the old compiler. And if the stage 1 compiler is the same, we
729 # should not build in the first place.
730 f.addStep(ShellCommand(name='clean stage 2',
731 command=['rm','-rf',stage2_build],
732 warnOnFailure=True,
733 description='cleaning stage 2',
734 descriptionDone='clean',
Galina Kistanova49cbd602017-04-14 23:46:03 +0000735 workdir='.'))
Reid Kleckner25a26b02015-03-09 22:30:25 +0000736
Renato Golin61aed7f2015-06-17 19:12:50 +0000737 # Set the compiler using the CC and CXX environment variables to work around
738 # backslash string escaping bugs somewhere between buildbot and cmake. The
739 # env.exe helper is required to run the tests, so hopefully it's already on
740 # PATH.
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000741 rel_src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, stage2_build)
Renato Golin61aed7f2015-06-17 19:12:50 +0000742 cmake_cmd2 = ['env',
743 WithProperties('CC=%(workdir)s/'+stage1_install+'/bin/'+cc),
744 WithProperties('CXX=%(workdir)s/'+stage1_install+'/bin/'+cxx),
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000745 cmake, "-G", "Ninja", rel_src_dir,
Renato Golin61aed7f2015-06-17 19:12:50 +0000746 "-DCMAKE_BUILD_TYPE="+stage2_config,
747 "-DLLVM_ENABLE_ASSERTIONS=True",
748 "-DLLVM_LIT_ARGS="+lit_args,
749 "-DCMAKE_INSTALL_PREFIX=../"+stage2_install] + extra_cmake_args
Reid Kleckner25a26b02015-03-09 22:30:25 +0000750
Renato Golin61aed7f2015-06-17 19:12:50 +0000751 f.addStep(ShellCommand(name='cmake stage 2',
752 command=cmake_cmd2,
753 haltOnFailure=True,
754 description='cmake stage 2',
755 workdir=stage2_build,
Renato Golin61aed7f2015-06-17 19:12:50 +0000756 env=env))
757
758 f.addStep(WarningCountingShellCommand(name='build stage 2',
759 command=ninja_cmd,
760 haltOnFailure=True,
761 description='ninja all',
762 workdir=stage2_build,
763 env=env))
764
765 if test:
766 f.addStep(lit_test_command.LitTestCommand(name='ninja check 2',
767 command=ninja_check_cmd,
768 haltOnFailure=not runTestSuite,
769 description=["checking stage 2"],
770 descriptionDone=["stage 2 checked"],
771 workdir=stage2_build,
772 env=env))
773
774 ############# TEST SUITE
775 ## Test-Suite (stage 2 if built, stage 1 otherwise)
776 if runTestSuite:
777 compiler_path = stage1_install
778 if useTwoStage:
779 compiler_path=stage2_install
Galina Kistanova49cbd602017-04-14 23:46:03 +0000780 f.addStep(ShellCommand(name='clean stage 2 install',
781 command=['rm','-rf',stage2_install],
782 warnOnFailure=True,
783 description='cleaning stage 2 install',
784 descriptionDone='clean',
785 workdir='.'))
Renato Golin61aed7f2015-06-17 19:12:50 +0000786 f.addStep(ShellCommand(name='install stage 2',
787 command=ninja_install_cmd,
788 description='ninja install 2',
Renato Golincfbd5702014-09-06 19:09:16 +0000789 workdir=stage2_build,
790 env=env))
Renato Goline402f582014-09-04 19:25:24 +0000791
Renato Golin61aed7f2015-06-17 19:12:50 +0000792 # Get generated python, lnt
793 python = WithProperties('%(workdir)s/test/sandbox/bin/python')
794 lnt = WithProperties('%(workdir)s/test/sandbox/bin/lnt')
795 lnt_setup = WithProperties('%(workdir)s/test/lnt/setup.py')
796
797 # Paths
798 sandbox = WithProperties('%(workdir)s/test/sandbox')
799 test_suite_dir = WithProperties('%(workdir)s/test/test-suite')
800
801 # Get latest built Clang (stage1 or stage2)
802 cc = WithProperties('%(workdir)s/'+compiler_path+'/bin/'+cc)
803 cxx = WithProperties('%(workdir)s/'+compiler_path+'/bin/'+cxx)
804
Renato Golin593e0d62016-09-21 17:24:56 +0000805 # LNT Command line (don't pass -jN. Users need to pass both --threads
Kristof Beylsf4639b52017-08-10 08:53:52 +0000806 # and --build-threads in nt_flags/test_suite_flags to get the same effect)
807 use_runtest_testsuite = len(nt_flags) == 0
808 if not use_runtest_testsuite:
809 test_suite_cmd = [python, lnt, 'runtest', 'nt',
810 '--no-timestamp',
811 '--sandbox', sandbox,
812 '--test-suite', test_suite_dir,
813 '--cc', cc,
814 '--cxx', cxx]
815 # Append any option provided by the user
816 test_suite_cmd.extend(nt_flags)
817 else:
818 lit = WithProperties('%(workdir)s/'+stage1_build+'/bin/llvm-lit')
819 test_suite_cmd = [python, lnt, 'runtest', 'test-suite',
820 '--no-timestamp',
821 '--sandbox', sandbox,
822 '--test-suite', test_suite_dir,
823 '--cc', cc,
824 '--cxx', cxx,
825 '--use-lit', lit]
826 # Append any option provided by the user
827 test_suite_cmd.extend(testsuite_flags)
828
Renato Golin61aed7f2015-06-17 19:12:50 +0000829 # Only submit if a URL has been specified
830 if submitURL is not None:
831 if not isinstance(submitURL, list):
832 submitURL = [submitURL]
833 for url in submitURL:
834 test_suite_cmd.extend(['--submit', url])
Kristof Beylsf4639b52017-08-10 08:53:52 +0000835 # lnt runtest test-suite doesn't understand --no-machdep-info:
836 if testerName and not use_runtest_testsuite:
Renato Golin61aed7f2015-06-17 19:12:50 +0000837 test_suite_cmd.extend(['--no-machdep-info', testerName])
838 # CC and CXX are needed as env for build-tools
Renato Goline6c1b3b2015-07-01 15:52:22 +0000839 test_suite_env = copy.deepcopy(env)
Renato Golin61aed7f2015-06-17 19:12:50 +0000840 test_suite_env['CC'] = cc
841 test_suite_env['CXX'] = cxx
842
843 # Steps to prepare, build and run LNT
844 f.addStep(ShellCommand(name='clean sandbox',
845 command=['rm', '-rf', 'sandbox'],
846 haltOnFailure=True,
847 description='removing sandbox directory',
848 workdir='test',
849 env=env))
850 f.addStep(ShellCommand(name='recreate sandbox',
851 command=['virtualenv', 'sandbox'],
852 haltOnFailure=True,
853 description='recreating sandbox',
854 workdir='test',
855 env=env))
856 f.addStep(ShellCommand(name='setup lit',
857 command=[python, lnt_setup, 'develop'],
858 haltOnFailure=True,
859 description='setting up LNT in sandbox',
860 workdir='test/sandbox',
861 env=env))
862 f.addStep(commands.LitTestCommand.LitTestCommand(
863 name='test-suite',
864 command=test_suite_cmd,
865 haltOnFailure=True,
866 description=['running the test suite'],
867 workdir='test/sandbox',
868 logfiles={'configure.log' : 'build/configure.log',
869 'build-tools.log' : 'build/build-tools.log',
870 'test.log' : 'build/test.log',
871 'report.json' : 'build/report.json'},
872 env=test_suite_env))
873
Renato Goline402f582014-09-04 19:25:24 +0000874 return f
875
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000876# FIXME: Deprecated.
Daniel Dunbar7363d032011-02-27 03:22:35 +0000877def addClangGCCTests(f, ignores={}, install_prefix="%(builddir)s/llvm.install",
878 languages = ('gcc', 'g++', 'objc', 'obj-c++')):
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000879 make_vars = [WithProperties(
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000880 'CC_UNDER_TEST=%s/bin/clang' % install_prefix),
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000881 WithProperties(
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000882 'CXX_UNDER_TEST=%s/bin/clang++' % install_prefix)]
David Blaikie05517332013-12-19 23:29:12 +0000883 f.addStep(SVN(name='svn-clang-gcc-tests', mode='update',
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000884 baseURL='http://llvm.org/svn/llvm-project/clang-tests/',
885 defaultBranch='trunk', workdir='clang-tests'))
886 gcc_dg_ignores = ignores.get('gcc-4_2-testsuite', {})
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000887 for lang in languages:
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000888 f.addStep(commands.SuppressionDejaGNUCommand.SuppressionDejaGNUCommand(
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000889 name='test-gcc-4_2-testsuite-%s' % lang,
890 command=["make", "-k", "check-%s" % lang] + make_vars,
891 description="gcc-4_2-testsuite (%s)" % lang,
892 workdir='clang-tests/gcc-4_2-testsuite',
David Dean2bd0c3a2011-10-18 16:36:28 +0000893 logfiles={ 'dg.sum' : 'obj/%s/%s.sum' % (lang, lang),
894 '%s.log' % lang : 'obj/%s/%s.log' % (lang, lang)},
Daniel Dunbar22d594a2010-07-31 05:29:16 +0000895 ignore=gcc_dg_ignores.get(lang, [])))
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000896
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000897# FIXME: Deprecated.
Daniel Dunbar7363d032011-02-27 03:22:35 +0000898def addClangGDBTests(f, ignores={}, install_prefix="%(builddir)s/llvm.install"):
899 make_vars = [WithProperties(
900 'CC_UNDER_TEST=%s/bin/clang' % install_prefix),
901 WithProperties(
902 'CXX_UNDER_TEST=%s/bin/clang++' % install_prefix)]
David Blaikie05517332013-12-19 23:29:12 +0000903 f.addStep(SVN(name='svn-clang-gdb-tests', mode='update',
Daniel Dunbar7363d032011-02-27 03:22:35 +0000904 baseURL='http://llvm.org/svn/llvm-project/clang-tests/',
905 defaultBranch='trunk', workdir='clang-tests'))
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000906 f.addStep(commands.SuppressionDejaGNUCommand.SuppressionDejaGNUCommand(
Daniel Dunbar7363d032011-02-27 03:22:35 +0000907 name='test-gdb-1472-testsuite',
908 command=["make", "-k", "check"] + make_vars,
909 description="gdb-1472-testsuite",
910 workdir='clang-tests/gdb-1472-testsuite',
David Blaikie7ec695f2012-10-09 22:17:09 +0000911 logfiles={ 'dg.sum' : 'obj/filtered.gdb.sum',
David Blaikie624f4392012-11-05 22:34:35 +0000912 'gdb.log' : 'obj/gdb.log' }))
Daniel Dunbar7363d032011-02-27 03:22:35 +0000913
Galina Kistanovab28be6d2019-10-18 05:31:36 +0000914# FIXME: Deprecated.
David Blaikie41d09c32013-01-02 21:11:09 +0000915def addModernClangGDBTests(f, jobs, install_prefix):
David Blaikie1bc5c372012-12-05 05:29:12 +0000916 make_vars = [WithProperties('RUNTESTFLAGS=CC_FOR_TARGET=\'{0}/bin/clang\' '
917 'CXX_FOR_TARGET=\'{0}/bin/clang++\' '
David Blaikie759bb752013-04-18 23:13:11 +0000918 'CFLAGS_FOR_TARGET=\'-w -fno-limit-debug-info\''
David Blaikief89877b2013-01-29 23:46:26 +0000919 .format(install_prefix))]
David Blaikie05517332013-12-19 23:29:12 +0000920 f.addStep(SVN(name='svn-clang-modern-gdb-tests', mode='update',
David Blaikief3f300b2012-11-17 01:13:41 +0000921 svnurl='http://llvm.org/svn/llvm-project/clang-tests-external/trunk/gdb/7.5',
David Blaikiedad03d52012-11-16 22:37:12 +0000922 workdir='clang-tests/src'))
David Blaikieb83bfdf2012-12-05 04:33:42 +0000923 f.addStep(Configure(command='../src/configure',
David Blaikief3f300b2012-11-17 01:13:41 +0000924 workdir='clang-tests/build/'))
David Blaikieb83bfdf2012-12-05 04:33:42 +0000925 f.addStep(WarningCountingShellCommand(name='gdb-75-build',
926 command=['make', WithProperties('-j%s' % jobs)],
927 haltOnFailure=True,
928 workdir='clang-tests/build'))
Michael Gottesmana6b5be82013-06-28 21:57:20 +0000929 f.addStep(commands.DejaGNUCommand.DejaGNUCommand(
David Blaikiedad03d52012-11-16 22:37:12 +0000930 name='gdb-75-check',
David Blaikieb83bfdf2012-12-05 04:33:42 +0000931 command=['make', '-k', WithProperties('-j%s' % jobs), 'check'] + make_vars,
David Blaikiedad03d52012-11-16 22:37:12 +0000932 workdir='clang-tests/build',
David Blaikie1bc5c372012-12-05 05:29:12 +0000933 logfiles={'dg.sum':'gdb/testsuite/gdb.sum',
934 'gdb.log':'gdb/testsuite/gdb.log'}))
David Blaikiedad03d52012-11-16 22:37:12 +0000935
936
937
Daniel Dunbar7363d032011-02-27 03:22:35 +0000938# FIXME: Deprecated.
939addClangTests = addClangGCCTests
940
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000941def getClangTestsIgnoresFromPath(path, key):
942 def readList(path):
943 if not os.path.exists(path):
944 return []
945
946 f = open(path)
947 lines = [ln.strip() for ln in f]
948 f.close()
949 return lines
950
951 ignores = {}
952
953 gcc_dg_ignores = {}
954 for lang in ('gcc', 'g++', 'objc', 'obj-c++'):
955 lang_path = os.path.join(path, 'gcc-4_2-testsuite', 'expected_results',
956 key, lang)
957 gcc_dg_ignores[lang] = (
958 readList(os.path.join(lang_path, 'FAIL.txt')) +
959 readList(os.path.join(lang_path, 'UNRESOLVED.txt')) +
960 readList(os.path.join(lang_path, 'XPASS.txt')))
961 ignores['gcc-4_2-testsuite' ] = gcc_dg_ignores
962
Daniel Dunbar7363d032011-02-27 03:22:35 +0000963 ignores_path = os.path.join(path, 'gdb-1472-testsuite', 'expected_results',
964 key)
965 gdb_dg_ignores = (
966 readList(os.path.join(ignores_path, 'FAIL.txt')) +
967 readList(os.path.join(ignores_path, 'UNRESOLVED.txt')) +
968 readList(os.path.join(ignores_path, 'XPASS.txt')))
969 ignores['gdb-1472-testsuite' ] = gdb_dg_ignores
970
Daniel Dunbar2b67e8f2011-02-11 21:03:41 +0000971 return ignores