blob: d745b3a7c506b3fa4d57e6b3d4133bc761ca863a [file] [log] [blame]
David Greene55820a62011-02-21 19:23:22 +00001#!/usr/bin/python3
2##===- utils/llvmbuild - Build the LLVM project ----------------*-python-*-===##
David Greenea15b16f2013-01-28 22:05:50 +00003#
David Greene55820a62011-02-21 19:23:22 +00004# The LLVM Compiler Infrastructure
5#
6# This file is distributed under the University of Illinois Open Source
7# License. See LICENSE.TXT for details.
David Greenea15b16f2013-01-28 22:05:50 +00008#
David Greene55820a62011-02-21 19:23:22 +00009##===----------------------------------------------------------------------===##
10#
11# This script builds many different flavors of the LLVM ecosystem. It
David Greenec26e5fb2012-01-27 23:01:35 +000012# will build LLVM, Clang and dragonegg as well as run tests on them.
13# This script is convenient to use to check builds and tests before
14# committing changes to the upstream repository
David Greene55820a62011-02-21 19:23:22 +000015#
16# A typical source setup uses three trees and looks like this:
17#
18# official
19# dragonegg
David Greene55820a62011-02-21 19:23:22 +000020# llvm
David Greenec26e5fb2012-01-27 23:01:35 +000021# tools
22# clang
David Greene55820a62011-02-21 19:23:22 +000023# staging
24# dragonegg
David Greene55820a62011-02-21 19:23:22 +000025# llvm
David Greenec26e5fb2012-01-27 23:01:35 +000026# tools
27# clang
David Greene55820a62011-02-21 19:23:22 +000028# commit
29# dragonegg
David Greene55820a62011-02-21 19:23:22 +000030# llvm
David Greenec26e5fb2012-01-27 23:01:35 +000031# tools
32# clang
David Greene55820a62011-02-21 19:23:22 +000033#
34# In a typical workflow, the "official" tree always contains unchanged
35# sources from the main LLVM project repositories. The "staging" tree
36# is where local work is done. A set of changes resides there waiting
37# to be moved upstream. The "commit" tree is where changes from
38# "staging" make their way upstream. Individual incremental changes
39# from "staging" are applied to "commit" and committed upstream after
40# a successful build and test run. A successful build is one in which
41# testing results in no more failures than seen in the testing of the
42# "official" tree.
43#
44# A build may be invoked as such:
45#
David Greenec26e5fb2012-01-27 23:01:35 +000046# llvmbuild --src=~/llvm/commit --src=~/llvm/staging --src=~/llvm/official
David Greene55820a62011-02-21 19:23:22 +000047# --build=debug --build=release --build=paranoid
48# --prefix=/home/greened/install --builddir=/home/greened/build
49#
David Greenec26e5fb2012-01-27 23:01:35 +000050# This will build the LLVM ecosystem, including LLVM, Clangand
51# dragonegg, putting build results in ~/build and installing tools in
52# ~/install. llvm-compilers-check creates separate build and install
53# directories for each source/build flavor. In the above example,
54# llvmbuild will build debug, release and paranoid (debug+checks)
55# flavors from each source tree (official, staging and commit) for a
56# total of nine builds. All builds will be run in parallel.
David Greene55820a62011-02-21 19:23:22 +000057#
58# The user may control parallelism via the --jobs and --threads
David Greenec26e5fb2012-01-27 23:01:35 +000059# switches. --jobs tells llvm-compilers-checl the maximum total
60# number of builds to activate in parallel. The user may think of it
61# as equivalent to the GNU make -j switch. --threads tells
62# llvm-compilers-check how many worker threads to use to accomplish
63# those builds. If --threads is less than --jobs, --threads workers
64# will be launched and each one will pick a source/flavor combination
65# to build. Then llvm-compilers-check will invoke GNU make with -j
66# (--jobs / --threads) to use up the remaining job capacity. Once a
67# worker is finished with a build, it will pick another combination
68# off the list and start building it.
David Greene55820a62011-02-21 19:23:22 +000069#
70##===----------------------------------------------------------------------===##
71
72import optparse
73import os
74import sys
75import threading
76import queue
77import logging
78import traceback
79import subprocess
80import re
81
82# TODO: Use shutil.which when it is available (3.2 or later)
83def find_executable(executable, path=None):
84 """Try to find 'executable' in the directories listed in 'path' (a
85 string listing directories separated by 'os.pathsep'; defaults to
86 os.environ['PATH']). Returns the complete filename or None if not
87 found
88 """
89 if path is None:
90 path = os.environ['PATH']
91 paths = path.split(os.pathsep)
92 extlist = ['']
93 if os.name == 'os2':
94 (base, ext) = os.path.splitext(executable)
95 # executable files on OS/2 can have an arbitrary extension, but
96 # .exe is automatically appended if no dot is present in the name
97 if not ext:
98 executable = executable + ".exe"
99 elif sys.platform == 'win32':
100 pathext = os.environ['PATHEXT'].lower().split(os.pathsep)
101 (base, ext) = os.path.splitext(executable)
102 if ext.lower() not in pathext:
103 extlist = pathext
104 for ext in extlist:
105 execname = executable + ext
106 if os.path.isfile(execname):
107 return execname
108 else:
109 for p in paths:
110 f = os.path.join(p, execname)
111 if os.path.isfile(f):
112 return f
113 else:
114 return None
115
116def is_executable(fpath):
117 return os.path.exists(fpath) and os.access(fpath, os.X_OK)
118
119def add_options(parser):
120 parser.add_option("-v", "--verbose", action="store_true",
121 default=False,
122 help=("Output informational messages"
123 " [default: %default]"))
124 parser.add_option("--src", action="append",
125 help=("Top-level source directory [default: %default]"))
David Greenec136bc62011-02-25 20:51:27 +0000126 parser.add_option("--build", action="append",
David Greene55820a62011-02-21 19:23:22 +0000127 help=("Build types to run [default: %default]"))
David Greene55820a62011-02-21 19:23:22 +0000128 parser.add_option("--cc", default=find_executable("cc"),
129 help=("The C compiler to use [default: %default]"))
130 parser.add_option("--cxx", default=find_executable("c++"),
131 help=("The C++ compiler to use [default: %default]"))
132 parser.add_option("--threads", default=4, type="int",
133 help=("The number of worker threads to use "
134 "[default: %default]"))
135 parser.add_option("--jobs", "-j", default=8, type="int",
136 help=("The number of simultaneous build jobs "
137 "[default: %default]"))
138 parser.add_option("--prefix",
139 help=("Root install directory [default: %default]"))
140 parser.add_option("--builddir",
141 help=("Root build directory [default: %default]"))
David Greenec136bc62011-02-25 20:51:27 +0000142 parser.add_option("--extra-llvm-config-flags", default="",
143 help=("Extra flags to pass to llvm configure [default: %default]"))
David Greenec136bc62011-02-25 20:51:27 +0000144 parser.add_option("--force-configure", default=False, action="store_true",
145 help=("Force reconfigure of all components"))
David Greenec26e5fb2012-01-27 23:01:35 +0000146 parser.add_option("--no-dragonegg", default=False, action="store_true",
147 help=("Do not build dragonegg"))
David Greene0907a612011-10-14 19:12:34 +0000148 parser.add_option("--no-install", default=False, action="store_true",
149 help=("Do not do installs"))
David Greenea15b16f2013-01-28 22:05:50 +0000150 parser.add_option("--keep-going", default=False, action="store_true",
151 help=("Keep going after failures"))
David Greene9ccdb172014-06-19 19:31:05 +0000152 parser.add_option("--enable-werror", default=False, action="store_true",
153 help=("Build with -Werror"))
David Greene55820a62011-02-21 19:23:22 +0000154 return
155
156def check_options(parser, options, valid_builds):
157 # See if we're building valid flavors.
158 for build in options.build:
159 if (build not in valid_builds):
160 parser.error("'" + build + "' is not a valid build flavor "
161 + str(valid_builds))
162
163 # See if we can find source directories.
164 for src in options.src:
David Greeneafb9ba72011-07-06 16:54:14 +0000165 for component in components:
166 component = component.rstrip("2")
David Greene55820a62011-02-21 19:23:22 +0000167 compsrc = src + "/" + component
168 if (not os.path.isdir(compsrc)):
169 parser.error("'" + compsrc + "' does not exist")
David Greene55820a62011-02-21 19:23:22 +0000170
171 # See if we can find the compilers
172 options.cc = find_executable(options.cc)
173 options.cxx = find_executable(options.cxx)
174
175 return
176
177# Find a unique short name for the given set of paths. This searches
178# back through path components until it finds unique component names
179# among all given paths.
180def get_path_abbrevs(paths):
181 # Find the number of common starting characters in the last component
182 # of the paths.
183 unique_paths = list(paths)
184
185 class NotFoundException(Exception): pass
186
187 # Find a unique component of each path.
188 unique_bases = unique_paths[:]
189 found = 0
190 while len(unique_paths) > 0:
191 bases = [os.path.basename(src) for src in unique_paths]
192 components = { c for c in bases }
193 # Account for single entry in paths.
194 if len(components) > 1 or len(components) == len(bases):
195 # We found something unique.
196 for c in components:
197 if bases.count(c) == 1:
198 index = bases.index(c)
199 unique_bases[index] = c
200 # Remove the corresponding path from the set under
201 # consideration.
202 unique_paths[index] = None
203 unique_paths = [ p for p in unique_paths if p is not None ]
204 unique_paths = [os.path.dirname(src) for src in unique_paths]
205
206 if len(unique_paths) > 0:
207 raise NotFoundException()
208
209 abbrevs = dict(zip(paths, [base for base in unique_bases]))
210
211 return abbrevs
212
213# Given a set of unique names, find a short character sequence that
214# uniquely identifies them.
215def get_short_abbrevs(unique_bases):
216 # Find a unique start character for each path base.
217 my_unique_bases = unique_bases[:]
218 unique_char_starts = unique_bases[:]
219 while len(my_unique_bases) > 0:
220 for start, char_tuple in enumerate(zip(*[base
221 for base in my_unique_bases])):
222 chars = { c for c in char_tuple }
223 # Account for single path.
224 if len(chars) > 1 or len(chars) == len(char_tuple):
225 # We found something unique.
226 for c in chars:
227 if char_tuple.count(c) == 1:
228 index = char_tuple.index(c)
229 unique_char_starts[index] = start
230 # Remove the corresponding path from the set under
231 # consideration.
232 my_unique_bases[index] = None
233 my_unique_bases = [ b for b in my_unique_bases
234 if b is not None ]
235 break
236
237 if len(my_unique_bases) > 0:
238 raise NotFoundException()
239
240 abbrevs = [abbrev[start_index:start_index+3]
241 for abbrev, start_index
242 in zip([base for base in unique_bases],
243 [index for index in unique_char_starts])]
244
245 abbrevs = dict(zip(unique_bases, abbrevs))
246
247 return abbrevs
248
249class Builder(threading.Thread):
250 class ExecutableNotFound(Exception): pass
251 class FileNotExecutable(Exception): pass
252
David Greenec136bc62011-02-25 20:51:27 +0000253 def __init__(self, work_queue, jobs,
David Greenec26e5fb2012-01-27 23:01:35 +0000254 build_abbrev, source_abbrev,
David Greenec136bc62011-02-25 20:51:27 +0000255 options):
David Greene55820a62011-02-21 19:23:22 +0000256 super().__init__()
257 self.work_queue = work_queue
258 self.jobs = jobs
David Greenec136bc62011-02-25 20:51:27 +0000259 self.cc = options.cc
260 self.cxx = options.cxx
David Greene55820a62011-02-21 19:23:22 +0000261 self.build_abbrev = build_abbrev
262 self.source_abbrev = source_abbrev
David Greenec136bc62011-02-25 20:51:27 +0000263 self.build_prefix = options.builddir
264 self.install_prefix = options.prefix
265 self.options = options
David Greene55820a62011-02-21 19:23:22 +0000266 self.component_abbrev = dict(
267 llvm="llvm",
David Greenec26e5fb2012-01-27 23:01:35 +0000268 dragonegg="degg")
David Greene55820a62011-02-21 19:23:22 +0000269 def run(self):
270 while True:
271 try:
David Greenec26e5fb2012-01-27 23:01:35 +0000272 source, build = self.work_queue.get()
273 self.dobuild(source, build)
David Greene55820a62011-02-21 19:23:22 +0000274 except:
275 traceback.print_exc()
276 finally:
277 self.work_queue.task_done()
278
279 def execute(self, command, execdir, env, component):
280 prefix = self.component_abbrev[component.replace("-", "_")]
281 pwd = os.getcwd()
282 if not os.path.exists(execdir):
283 os.makedirs(execdir)
284
David Greene5ec82362011-02-22 23:30:45 +0000285 execenv = os.environ.copy()
286
David Greene55820a62011-02-21 19:23:22 +0000287 for key, value in env.items():
David Greene5ec82362011-02-22 23:30:45 +0000288 execenv[key] = value
David Greenea15b16f2013-01-28 22:05:50 +0000289
David Greene55820a62011-02-21 19:23:22 +0000290 self.logger.debug("[" + prefix + "] " + "env " + str(env) + " "
291 + " ".join(command));
292
293 try:
294 proc = subprocess.Popen(command,
295 cwd=execdir,
David Greene5ec82362011-02-22 23:30:45 +0000296 env=execenv,
David Greene55820a62011-02-21 19:23:22 +0000297 stdout=subprocess.PIPE,
298 stderr=subprocess.STDOUT)
299
300 line = proc.stdout.readline()
301 while line:
302 self.logger.info("[" + prefix + "] "
303 + str(line, "utf-8").rstrip())
304 line = proc.stdout.readline()
305
David Greenea15b16f2013-01-28 22:05:50 +0000306 (stdoutdata, stderrdata) = proc.communicate()
307 retcode = proc.wait()
308
309 return retcode
310
David Greene55820a62011-02-21 19:23:22 +0000311 except:
312 traceback.print_exc()
313
David Greene55820a62011-02-21 19:23:22 +0000314 # Get a list of C++ include directories to pass to clang.
315 def get_includes(self):
316 # Assume we're building with g++ for now.
317 command = [self.cxx]
318 command += ["-v", "-x", "c++", "/dev/null", "-fsyntax-only"]
319 includes = []
320 self.logger.debug(command)
321 try:
322 proc = subprocess.Popen(command,
323 stdout=subprocess.PIPE,
324 stderr=subprocess.STDOUT)
325
326 gather = False
327 line = proc.stdout.readline()
328 while line:
329 self.logger.debug(line)
330 if re.search("End of search list", str(line)) is not None:
331 self.logger.debug("Stop Gather")
332 gather = False
333 if gather:
334 includes.append(str(line, "utf-8").strip())
335 if re.search("#include <...> search starts", str(line)) is not None:
336 self.logger.debug("Start Gather")
337 gather = True
338 line = proc.stdout.readline()
David Greenea15b16f2013-01-28 22:05:50 +0000339
David Greene55820a62011-02-21 19:23:22 +0000340 except:
341 traceback.print_exc()
342 self.logger.debug(includes)
343 return includes
344
David Greenec26e5fb2012-01-27 23:01:35 +0000345 def dobuild(self, source, build):
David Greene55820a62011-02-21 19:23:22 +0000346 build_suffix = ""
347
348 ssabbrev = get_short_abbrevs([ab for ab in self.source_abbrev.values()])
349
David Greenec26e5fb2012-01-27 23:01:35 +0000350 prefix = "[" + ssabbrev[self.source_abbrev[source]] + "-" + self.build_abbrev[build] + "]"
351 self.install_prefix += "/" + self.source_abbrev[source] + "/" + build
352 build_suffix += "/" + self.source_abbrev[source] + "/" + build
David Greene55820a62011-02-21 19:23:22 +0000353
354 self.logger = logging.getLogger(prefix)
355
356 self.logger.debug(self.install_prefix)
357
358 # Assume we're building with gcc for now.
359 cxxincludes = self.get_includes()
Rafael Espindolaec217f62012-02-03 00:59:30 +0000360 cxxroot = os.path.dirname(cxxincludes[0]) # Remove the version
361 cxxroot = os.path.dirname(cxxroot) # Remove the c++
362 cxxroot = os.path.dirname(cxxroot) # Remove the include
David Greene55820a62011-02-21 19:23:22 +0000363
364 configure_flags = dict(
365 llvm=dict(debug=["--prefix=" + self.install_prefix,
David Greeneafb9ba72011-07-06 16:54:14 +0000366 "--enable-assertions",
367 "--disable-optimized",
Rafael Espindolaec217f62012-02-03 00:59:30 +0000368 "--with-gcc-toolchain=" + cxxroot],
David Greene55820a62011-02-21 19:23:22 +0000369 release=["--prefix=" + self.install_prefix,
370 "--enable-optimized",
Rafael Espindolaec217f62012-02-03 00:59:30 +0000371 "--with-gcc-toolchain=" + cxxroot],
David Greene55820a62011-02-21 19:23:22 +0000372 paranoid=["--prefix=" + self.install_prefix,
David Greeneafb9ba72011-07-06 16:54:14 +0000373 "--enable-assertions",
David Greene55820a62011-02-21 19:23:22 +0000374 "--enable-expensive-checks",
David Greeneafb9ba72011-07-06 16:54:14 +0000375 "--disable-optimized",
Rafael Espindolaec217f62012-02-03 00:59:30 +0000376 "--with-gcc-toolchain=" + cxxroot]),
David Greene55820a62011-02-21 19:23:22 +0000377 dragonegg=dict(debug=[],
378 release=[],
379 paranoid=[]))
380
David Greene9ccdb172014-06-19 19:31:05 +0000381 if (self.options.enable_werror):
382 configure_flags["llvm"]["debug"].append("--enable-werror")
383 configure_flags["llvm"]["release"].append("--enable-werror")
384 configure_flags["llvm"]["paranoid"].append("--enable-werror")
385
David Greene55820a62011-02-21 19:23:22 +0000386 configure_env = dict(
387 llvm=dict(debug=dict(CC=self.cc,
388 CXX=self.cxx),
389 release=dict(CC=self.cc,
390 CXX=self.cxx),
391 paranoid=dict(CC=self.cc,
392 CXX=self.cxx)),
David Greene55820a62011-02-21 19:23:22 +0000393 dragonegg=dict(debug=dict(CC=self.cc,
394 CXX=self.cxx),
395 release=dict(CC=self.cc,
396 CXX=self.cxx),
397 paranoid=dict(CC=self.cc,
398 CXX=self.cxx)))
399
400 make_flags = dict(
401 llvm=dict(debug=["-j" + str(self.jobs)],
402 release=["-j" + str(self.jobs)],
403 paranoid=["-j" + str(self.jobs)]),
David Greene55820a62011-02-21 19:23:22 +0000404 dragonegg=dict(debug=["-j" + str(self.jobs)],
405 release=["-j" + str(self.jobs)],
406 paranoid=["-j" + str(self.jobs)]))
407
408 make_env = dict(
409 llvm=dict(debug=dict(),
410 release=dict(),
411 paranoid=dict()),
David Greenec26e5fb2012-01-27 23:01:35 +0000412 dragonegg=dict(debug=dict(GCC=self.cc,
David Greene55820a62011-02-21 19:23:22 +0000413 LLVM_CONFIG=self.install_prefix + "/bin/llvm-config"),
David Greenec26e5fb2012-01-27 23:01:35 +0000414 release=dict(GCC=self.cc,
David Greene55820a62011-02-21 19:23:22 +0000415 LLVM_CONFIG=self.install_prefix + "/bin/llvm-config"),
David Greenec26e5fb2012-01-27 23:01:35 +0000416 paranoid=dict(GCC=self.cc,
David Greene55820a62011-02-21 19:23:22 +0000417 LLVM_CONFIG=self.install_prefix + "/bin/llvm-config")))
418
419 make_install_flags = dict(
420 llvm=dict(debug=["install"],
421 release=["install"],
422 paranoid=["install"]),
David Greene55820a62011-02-21 19:23:22 +0000423 dragonegg=dict(debug=["install"],
424 release=["install"],
425 paranoid=["install"]))
426
427 make_install_env = dict(
428 llvm=dict(debug=dict(),
429 release=dict(),
430 paranoid=dict()),
David Greene55820a62011-02-21 19:23:22 +0000431 dragonegg=dict(debug=dict(),
432 release=dict(),
433 paranoid=dict()))
434
435 make_check_flags = dict(
436 llvm=dict(debug=["check"],
437 release=["check"],
438 paranoid=["check"]),
David Greene55820a62011-02-21 19:23:22 +0000439 dragonegg=dict(debug=["check"],
440 release=["check"],
441 paranoid=["check"]))
442
443 make_check_env = dict(
444 llvm=dict(debug=dict(),
445 release=dict(),
446 paranoid=dict()),
David Greene55820a62011-02-21 19:23:22 +0000447 dragonegg=dict(debug=dict(),
448 release=dict(),
449 paranoid=dict()))
450
David Greeneafb9ba72011-07-06 16:54:14 +0000451 for component in components:
David Greene55820a62011-02-21 19:23:22 +0000452 comp = component[:]
David Greenea15b16f2013-01-28 22:05:50 +0000453
David Greenec26e5fb2012-01-27 23:01:35 +0000454 if (self.options.no_dragonegg):
455 if (comp == 'dragonegg'):
David Greened42442d2011-10-14 19:12:33 +0000456 self.logger.info("Skipping " + component + " in "
457 + builddir)
458 continue
David Greene55820a62011-02-21 19:23:22 +0000459
460 srcdir = source + "/" + comp.rstrip("2")
461 builddir = self.build_prefix + "/" + comp + "/" + build_suffix
462 installdir = self.install_prefix
463
David Greenec136bc62011-02-25 20:51:27 +0000464 comp_key = comp.replace("-", "_")
465
466 config_args = configure_flags[comp_key][build][:]
467 config_args.extend(getattr(self.options,
David Greeneafb9ba72011-07-06 16:54:14 +0000468 "extra_" + comp_key.rstrip("2")
David Greenec26e5fb2012-01-27 23:01:35 +0000469 + "_config_flags",
470 "").split())
David Greenec136bc62011-02-25 20:51:27 +0000471
David Greene55820a62011-02-21 19:23:22 +0000472 self.logger.info("Configuring " + component + " in " + builddir)
David Greenea15b16f2013-01-28 22:05:50 +0000473 configrc = self.configure(component, srcdir, builddir,
474 config_args,
475 configure_env[comp_key][build])
David Greene55820a62011-02-21 19:23:22 +0000476
David Greenea15b16f2013-01-28 22:05:50 +0000477 if (configrc == None) :
478 self.logger.info("[None] Failed to configure " + component + " in " + installdir)
David Greene55820a62011-02-21 19:23:22 +0000479
David Greenea15b16f2013-01-28 22:05:50 +0000480 if (configrc == 0 or self.options.keep_going) :
481 self.logger.info("Building " + component + " in " + builddir)
482 self.logger.info("Build: make " + str(make_flags[comp_key][build]))
483 buildrc = self.make(component, srcdir, builddir,
484 make_flags[comp_key][build],
485 make_env[comp_key][build])
David Greene55820a62011-02-21 19:23:22 +0000486
David Greenea15b16f2013-01-28 22:05:50 +0000487 if (buildrc == None) :
488 self.logger.info("[None] Failed to build " + component + " in " + installdir)
David Greene55820a62011-02-21 19:23:22 +0000489
David Greenea15b16f2013-01-28 22:05:50 +0000490 if (buildrc == 0 or self.options.keep_going) :
491 self.logger.info("Testing " + component + " in " + builddir)
492 self.logger.info("Test: make "
493 + str(make_check_flags[comp_key][build]))
494 testrc = self.make(component, srcdir, builddir,
495 make_check_flags[comp_key][build],
496 make_check_env[comp_key][build])
497
498 if (testrc == None) :
499 self.logger.info("[None] Failed to test " + component + " in " + installdir)
500
501 if ((testrc == 0 or self.options.keep_going)
502 and not self.options.no_install):
503 self.logger.info("Installing " + component + " in " + installdir)
504 self.make(component, srcdir, builddir,
505 make_install_flags[comp_key][build],
506 make_install_env[comp_key][build])
507 else :
508 self.logger.info("Failed testing " + component + " in " + installdir)
509
510 else :
511 self.logger.info("Failed to build " + component + " in " + installdir)
512
513 else :
514 self.logger.info("Failed to configure " + component + " in " + installdir)
David Greene55820a62011-02-21 19:23:22 +0000515
516 def configure(self, component, srcdir, builddir, flags, env):
David Greenea15b16f2013-01-28 22:05:50 +0000517 prefix = self.component_abbrev[component.replace("-", "_")]
518
David Greene9e8963a2011-03-04 23:02:52 +0000519 self.logger.debug("Configure " + str(flags) + " " + str(srcdir) + " -> "
520 + str(builddir))
David Greenec136bc62011-02-25 20:51:27 +0000521
David Greene55820a62011-02-21 19:23:22 +0000522 configure_files = dict(
523 llvm=[(srcdir + "/configure", builddir + "/Makefile")],
David Greenea15b16f2013-01-28 22:05:50 +0000524 dragonegg=[(None,None)])
David Greene55820a62011-02-21 19:23:22 +0000525
David Greenec136bc62011-02-25 20:51:27 +0000526
David Greene55820a62011-02-21 19:23:22 +0000527 doconfig = False
528 for conf, mf in configure_files[component.replace("-", "_")]:
David Greenea15b16f2013-01-28 22:05:50 +0000529 if conf is None:
530 # No configure necessary
531 return 0
532
David Greenec136bc62011-02-25 20:51:27 +0000533 if not os.path.exists(conf):
David Greenea15b16f2013-01-28 22:05:50 +0000534 self.logger.info("[" + prefix + "] Configure failed, no configure script " + conf)
535 return -1
536
537 if not os.path.exists(mf):
538 self.logger.info("[" + prefix + "] Configure failed, no makefile " + mf)
539 return -1
540
David Greene55820a62011-02-21 19:23:22 +0000541 if os.path.exists(conf) and os.path.exists(mf):
542 confstat = os.stat(conf)
543 makestat = os.stat(mf)
544 if confstat.st_mtime > makestat.st_mtime:
545 doconfig = True
546 break
547 else:
548 doconfig = True
549 break
550
David Greenec136bc62011-02-25 20:51:27 +0000551 if not doconfig and not self.options.force_configure:
David Greenea15b16f2013-01-28 22:05:50 +0000552 return 0
David Greene55820a62011-02-21 19:23:22 +0000553
554 program = srcdir + "/configure"
555 if not is_executable(program):
David Greenea15b16f2013-01-28 22:05:50 +0000556 self.logger.info("[" + prefix + "] Configure failed, cannot execute " + program)
557 return -1
David Greene55820a62011-02-21 19:23:22 +0000558
559 args = [program]
560 args += ["--verbose"]
561 args += flags
David Greenea15b16f2013-01-28 22:05:50 +0000562 return self.execute(args, builddir, env, component)
David Greene55820a62011-02-21 19:23:22 +0000563
564 def make(self, component, srcdir, builddir, flags, env):
565 program = find_executable("make")
566 if program is None:
567 raise ExecutableNotFound
568
569 if not is_executable(program):
570 raise FileNotExecutable
571
572 args = [program]
573 args += flags
David Greenea15b16f2013-01-28 22:05:50 +0000574 return self.execute(args, builddir, env, component)
David Greene55820a62011-02-21 19:23:22 +0000575
576# Global constants
577build_abbrev = dict(debug="dbg", release="opt", paranoid="par")
David Greenec26e5fb2012-01-27 23:01:35 +0000578components = ["llvm", "dragonegg"]
David Greene55820a62011-02-21 19:23:22 +0000579
580# Parse options
581parser = optparse.OptionParser(version="%prog 1.0")
582add_options(parser)
583(options, args) = parser.parse_args()
584check_options(parser, options, build_abbrev.keys());
585
586if options.verbose:
587 logging.basicConfig(level=logging.DEBUG,
588 format='%(name)-13s: %(message)s')
589else:
590 logging.basicConfig(level=logging.INFO,
591 format='%(name)-13s: %(message)s')
592
593source_abbrev = get_path_abbrevs(set(options.src))
David Greeneafb9ba72011-07-06 16:54:14 +0000594
David Greene55820a62011-02-21 19:23:22 +0000595work_queue = queue.Queue()
596
David Greene9e8963a2011-03-04 23:02:52 +0000597jobs = options.jobs // options.threads
598if jobs == 0:
599 jobs = 1
600
601numthreads = options.threads
David Greene1dafb032011-10-14 19:12:37 +0000602
603logging.getLogger().info("Building with " + str(options.jobs) + " jobs and "
604 + str(numthreads) + " threads using " + str(jobs)
605 + " make jobs")
David Greene9e8963a2011-03-04 23:02:52 +0000606
David Greenec26e5fb2012-01-27 23:01:35 +0000607logging.getLogger().info("CC = " + str(options.cc))
608logging.getLogger().info("CXX = " + str(options.cxx))
609
David Greene9e8963a2011-03-04 23:02:52 +0000610for t in range(numthreads):
David Greenec136bc62011-02-25 20:51:27 +0000611 builder = Builder(work_queue, jobs,
David Greenec26e5fb2012-01-27 23:01:35 +0000612 build_abbrev, source_abbrev,
David Greenec136bc62011-02-25 20:51:27 +0000613 options)
David Greene55820a62011-02-21 19:23:22 +0000614 builder.daemon = True
615 builder.start()
616
617for build in set(options.build):
618 for source in set(options.src):
David Greenec26e5fb2012-01-27 23:01:35 +0000619 work_queue.put((source, build))
David Greene55820a62011-02-21 19:23:22 +0000620
621work_queue.join()