David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | ##===- utils/llvmbuild - Build the LLVM project ----------------*-python-*-===## |
| 3 | # |
| 4 | # The LLVM Compiler Infrastructure |
| 5 | # |
| 6 | # This file is distributed under the University of Illinois Open Source |
| 7 | # License. See LICENSE.TXT for details. |
| 8 | # |
| 9 | ##===----------------------------------------------------------------------===## |
| 10 | # |
| 11 | # This script builds many different flavors of the LLVM ecosystem. It |
| 12 | # will build LLVM, Clang, llvm-gcc, and dragonegg as well as run tests |
| 13 | # on them. This script is convenient to use to check builds and tests |
| 14 | # before committing changes to the upstream repository |
| 15 | # |
| 16 | # A typical source setup uses three trees and looks like this: |
| 17 | # |
| 18 | # official |
| 19 | # dragonegg |
| 20 | # trunk |
| 21 | # gcc |
| 22 | # trunk |
| 23 | # llvm |
| 24 | # trunk |
| 25 | # tools |
| 26 | # clang |
| 27 | # tags |
| 28 | # RELEASE_28 |
| 29 | # tools |
| 30 | # clang |
| 31 | # llvm-gcc |
| 32 | # trunk |
| 33 | # tags |
| 34 | # RELEASE_28 |
| 35 | # staging |
| 36 | # dragonegg |
| 37 | # trunk |
| 38 | # gcc |
| 39 | # trunk |
| 40 | # llvm |
| 41 | # trunk |
| 42 | # tools |
| 43 | # clang |
| 44 | # tags |
| 45 | # RELEASE_28 |
| 46 | # tools |
| 47 | # clang |
| 48 | # llvm-gcc |
| 49 | # trunk |
| 50 | # tags |
| 51 | # RELEASE_28 |
| 52 | # commit |
| 53 | # dragonegg |
| 54 | # trunk |
| 55 | # gcc |
| 56 | # trunk |
| 57 | # llvm |
| 58 | # trunk |
| 59 | # tools |
| 60 | # clang |
| 61 | # tags |
| 62 | # RELEASE_28 |
| 63 | # tools |
| 64 | # clang |
| 65 | # llvm-gcc |
| 66 | # trunk |
| 67 | # tags |
| 68 | # RELEASE_28 |
| 69 | # |
| 70 | # "gcc" above is the upstream FSF gcc and "gcc/trunk" refers to the |
| 71 | # 4.5 branch as discussed in the dragonegg build guide. |
| 72 | # |
| 73 | # In a typical workflow, the "official" tree always contains unchanged |
| 74 | # sources from the main LLVM project repositories. The "staging" tree |
| 75 | # is where local work is done. A set of changes resides there waiting |
| 76 | # to be moved upstream. The "commit" tree is where changes from |
| 77 | # "staging" make their way upstream. Individual incremental changes |
| 78 | # from "staging" are applied to "commit" and committed upstream after |
| 79 | # a successful build and test run. A successful build is one in which |
| 80 | # testing results in no more failures than seen in the testing of the |
| 81 | # "official" tree. |
| 82 | # |
| 83 | # A build may be invoked as such: |
| 84 | # |
| 85 | # llvmbuild --src=~/llvm/commit --src=~/llvm/staging |
| 86 | # --src=~/llvm/official --branch=trunk --branch=tags/RELEASE_28 |
| 87 | # --build=debug --build=release --build=paranoid |
| 88 | # --prefix=/home/greened/install --builddir=/home/greened/build |
| 89 | # |
| 90 | # This will build the LLVM ecosystem, including LLVM, Clang, llvm-gcc, |
| 91 | # gcc 4.5 and dragonegg, putting build results in ~/build and |
| 92 | # installing tools in ~/install. llvmbuild creates separate build and |
| 93 | # install directories for each source/branch/build flavor. In the |
| 94 | # above example, llvmbuild will build debug, release and paranoid |
| 95 | # (debug+checks) flavors of the trunk and RELEASE_28 branches from |
| 96 | # each source tree (official, staging and commit) for a total of |
| 97 | # eighteen builds. All builds will be run in parallel. |
| 98 | # |
| 99 | # The user may control parallelism via the --jobs and --threads |
| 100 | # switches. --jobs tells llvmbuild the maximum total number of builds |
| 101 | # to activate in parallel. The user may think of it as equivalent to |
| 102 | # the GNU make -j switch. --threads tells llvmbuild how many worker |
| 103 | # threads to use to accomplish those builds. If --threads is less |
| 104 | # than --jobs, --threads workers will be launched and each one will |
| 105 | # pick a source/branch/flavor combination to build. Then llvmbuild |
| 106 | # will invoke GNU make with -j (--jobs / --threads) to use up the |
| 107 | # remaining job capacity. Once a worker is finished with a build, it |
| 108 | # will pick another combination off the list and start building it. |
| 109 | # |
| 110 | ##===----------------------------------------------------------------------===## |
| 111 | |
| 112 | import optparse |
| 113 | import os |
| 114 | import sys |
| 115 | import threading |
| 116 | import queue |
| 117 | import logging |
| 118 | import traceback |
| 119 | import subprocess |
| 120 | import re |
| 121 | |
| 122 | # TODO: Use shutil.which when it is available (3.2 or later) |
| 123 | def find_executable(executable, path=None): |
| 124 | """Try to find 'executable' in the directories listed in 'path' (a |
| 125 | string listing directories separated by 'os.pathsep'; defaults to |
| 126 | os.environ['PATH']). Returns the complete filename or None if not |
| 127 | found |
| 128 | """ |
| 129 | if path is None: |
| 130 | path = os.environ['PATH'] |
| 131 | paths = path.split(os.pathsep) |
| 132 | extlist = [''] |
| 133 | if os.name == 'os2': |
| 134 | (base, ext) = os.path.splitext(executable) |
| 135 | # executable files on OS/2 can have an arbitrary extension, but |
| 136 | # .exe is automatically appended if no dot is present in the name |
| 137 | if not ext: |
| 138 | executable = executable + ".exe" |
| 139 | elif sys.platform == 'win32': |
| 140 | pathext = os.environ['PATHEXT'].lower().split(os.pathsep) |
| 141 | (base, ext) = os.path.splitext(executable) |
| 142 | if ext.lower() not in pathext: |
| 143 | extlist = pathext |
| 144 | for ext in extlist: |
| 145 | execname = executable + ext |
| 146 | if os.path.isfile(execname): |
| 147 | return execname |
| 148 | else: |
| 149 | for p in paths: |
| 150 | f = os.path.join(p, execname) |
| 151 | if os.path.isfile(f): |
| 152 | return f |
| 153 | else: |
| 154 | return None |
| 155 | |
| 156 | def is_executable(fpath): |
| 157 | return os.path.exists(fpath) and os.access(fpath, os.X_OK) |
| 158 | |
| 159 | def add_options(parser): |
| 160 | parser.add_option("-v", "--verbose", action="store_true", |
| 161 | default=False, |
| 162 | help=("Output informational messages" |
| 163 | " [default: %default]")) |
| 164 | parser.add_option("--src", action="append", |
| 165 | help=("Top-level source directory [default: %default]")) |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 166 | parser.add_option("--build", action="append", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 167 | help=("Build types to run [default: %default]")) |
| 168 | parser.add_option("--branch", action="append", |
| 169 | help=("Source branch to build [default: %default]")) |
| 170 | parser.add_option("--cc", default=find_executable("cc"), |
| 171 | help=("The C compiler to use [default: %default]")) |
| 172 | parser.add_option("--cxx", default=find_executable("c++"), |
| 173 | help=("The C++ compiler to use [default: %default]")) |
| 174 | parser.add_option("--threads", default=4, type="int", |
| 175 | help=("The number of worker threads to use " |
| 176 | "[default: %default]")) |
| 177 | parser.add_option("--jobs", "-j", default=8, type="int", |
| 178 | help=("The number of simultaneous build jobs " |
| 179 | "[default: %default]")) |
| 180 | parser.add_option("--prefix", |
| 181 | help=("Root install directory [default: %default]")) |
| 182 | parser.add_option("--builddir", |
| 183 | help=("Root build directory [default: %default]")) |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 184 | parser.add_option("--extra-llvm-config-flags", default="", |
| 185 | help=("Extra flags to pass to llvm configure [default: %default]")) |
| 186 | parser.add_option("--extra-llvm-gcc-config-flags", default="", |
| 187 | help=("Extra flags to pass to llvm-gcc configure [default: %default]")) |
| 188 | parser.add_option("--extra-gcc-config-flags", default="", |
| 189 | help=("Extra flags to pass to gcc configure [default: %default]")) |
| 190 | parser.add_option("--force-configure", default=False, action="store_true", |
| 191 | help=("Force reconfigure of all components")) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 192 | return |
| 193 | |
| 194 | def check_options(parser, options, valid_builds): |
| 195 | # See if we're building valid flavors. |
| 196 | for build in options.build: |
| 197 | if (build not in valid_builds): |
| 198 | parser.error("'" + build + "' is not a valid build flavor " |
| 199 | + str(valid_builds)) |
| 200 | |
| 201 | # See if we can find source directories. |
| 202 | for src in options.src: |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 203 | for component in components: |
| 204 | component = component.rstrip("2") |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 205 | compsrc = src + "/" + component |
| 206 | if (not os.path.isdir(compsrc)): |
| 207 | parser.error("'" + compsrc + "' does not exist") |
| 208 | if (options.branch is not None): |
| 209 | for branch in options.branch: |
| 210 | if (not os.path.isdir(os.path.join(compsrc, branch))): |
| 211 | parser.error("'" + os.path.join(compsrc, branch) |
| 212 | + "' does not exist") |
| 213 | |
| 214 | # See if we can find the compilers |
| 215 | options.cc = find_executable(options.cc) |
| 216 | options.cxx = find_executable(options.cxx) |
| 217 | |
| 218 | return |
| 219 | |
| 220 | # Find a unique short name for the given set of paths. This searches |
| 221 | # back through path components until it finds unique component names |
| 222 | # among all given paths. |
| 223 | def get_path_abbrevs(paths): |
| 224 | # Find the number of common starting characters in the last component |
| 225 | # of the paths. |
| 226 | unique_paths = list(paths) |
| 227 | |
| 228 | class NotFoundException(Exception): pass |
| 229 | |
| 230 | # Find a unique component of each path. |
| 231 | unique_bases = unique_paths[:] |
| 232 | found = 0 |
| 233 | while len(unique_paths) > 0: |
| 234 | bases = [os.path.basename(src) for src in unique_paths] |
| 235 | components = { c for c in bases } |
| 236 | # Account for single entry in paths. |
| 237 | if len(components) > 1 or len(components) == len(bases): |
| 238 | # We found something unique. |
| 239 | for c in components: |
| 240 | if bases.count(c) == 1: |
| 241 | index = bases.index(c) |
| 242 | unique_bases[index] = c |
| 243 | # Remove the corresponding path from the set under |
| 244 | # consideration. |
| 245 | unique_paths[index] = None |
| 246 | unique_paths = [ p for p in unique_paths if p is not None ] |
| 247 | unique_paths = [os.path.dirname(src) for src in unique_paths] |
| 248 | |
| 249 | if len(unique_paths) > 0: |
| 250 | raise NotFoundException() |
| 251 | |
| 252 | abbrevs = dict(zip(paths, [base for base in unique_bases])) |
| 253 | |
| 254 | return abbrevs |
| 255 | |
| 256 | # Given a set of unique names, find a short character sequence that |
| 257 | # uniquely identifies them. |
| 258 | def get_short_abbrevs(unique_bases): |
| 259 | # Find a unique start character for each path base. |
| 260 | my_unique_bases = unique_bases[:] |
| 261 | unique_char_starts = unique_bases[:] |
| 262 | while len(my_unique_bases) > 0: |
| 263 | for start, char_tuple in enumerate(zip(*[base |
| 264 | for base in my_unique_bases])): |
| 265 | chars = { c for c in char_tuple } |
| 266 | # Account for single path. |
| 267 | if len(chars) > 1 or len(chars) == len(char_tuple): |
| 268 | # We found something unique. |
| 269 | for c in chars: |
| 270 | if char_tuple.count(c) == 1: |
| 271 | index = char_tuple.index(c) |
| 272 | unique_char_starts[index] = start |
| 273 | # Remove the corresponding path from the set under |
| 274 | # consideration. |
| 275 | my_unique_bases[index] = None |
| 276 | my_unique_bases = [ b for b in my_unique_bases |
| 277 | if b is not None ] |
| 278 | break |
| 279 | |
| 280 | if len(my_unique_bases) > 0: |
| 281 | raise NotFoundException() |
| 282 | |
| 283 | abbrevs = [abbrev[start_index:start_index+3] |
| 284 | for abbrev, start_index |
| 285 | in zip([base for base in unique_bases], |
| 286 | [index for index in unique_char_starts])] |
| 287 | |
| 288 | abbrevs = dict(zip(unique_bases, abbrevs)) |
| 289 | |
| 290 | return abbrevs |
| 291 | |
| 292 | class Builder(threading.Thread): |
| 293 | class ExecutableNotFound(Exception): pass |
| 294 | class FileNotExecutable(Exception): pass |
| 295 | |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 296 | def __init__(self, work_queue, jobs, |
| 297 | build_abbrev, source_abbrev, branch_abbrev, |
| 298 | options): |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 299 | super().__init__() |
| 300 | self.work_queue = work_queue |
| 301 | self.jobs = jobs |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 302 | self.cc = options.cc |
| 303 | self.cxx = options.cxx |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 304 | self.build_abbrev = build_abbrev |
| 305 | self.source_abbrev = source_abbrev |
| 306 | self.branch_abbrev = branch_abbrev |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 307 | self.build_prefix = options.builddir |
| 308 | self.install_prefix = options.prefix |
| 309 | self.options = options |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 310 | self.component_abbrev = dict( |
| 311 | llvm="llvm", |
| 312 | llvm_gcc="lgcc", |
| 313 | llvm2="llv2", |
| 314 | gcc="ugcc", |
| 315 | dagonegg="degg") |
| 316 | def run(self): |
| 317 | while True: |
| 318 | try: |
| 319 | source, branch, build = self.work_queue.get() |
| 320 | self.dobuild(source, branch, build) |
| 321 | except: |
| 322 | traceback.print_exc() |
| 323 | finally: |
| 324 | self.work_queue.task_done() |
| 325 | |
| 326 | def execute(self, command, execdir, env, component): |
| 327 | prefix = self.component_abbrev[component.replace("-", "_")] |
| 328 | pwd = os.getcwd() |
| 329 | if not os.path.exists(execdir): |
| 330 | os.makedirs(execdir) |
| 331 | |
David Greene | 8b890c2 | 2011-02-22 23:30:45 +0000 | [diff] [blame] | 332 | execenv = os.environ.copy() |
| 333 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 334 | for key, value in env.items(): |
David Greene | 8b890c2 | 2011-02-22 23:30:45 +0000 | [diff] [blame] | 335 | execenv[key] = value |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 336 | |
| 337 | self.logger.debug("[" + prefix + "] " + "env " + str(env) + " " |
| 338 | + " ".join(command)); |
| 339 | |
| 340 | try: |
| 341 | proc = subprocess.Popen(command, |
| 342 | cwd=execdir, |
David Greene | 8b890c2 | 2011-02-22 23:30:45 +0000 | [diff] [blame] | 343 | env=execenv, |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 344 | stdout=subprocess.PIPE, |
| 345 | stderr=subprocess.STDOUT) |
| 346 | |
| 347 | line = proc.stdout.readline() |
| 348 | while line: |
| 349 | self.logger.info("[" + prefix + "] " |
| 350 | + str(line, "utf-8").rstrip()) |
| 351 | line = proc.stdout.readline() |
| 352 | |
| 353 | except: |
| 354 | traceback.print_exc() |
| 355 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 356 | # Get a list of C++ include directories to pass to clang. |
| 357 | def get_includes(self): |
| 358 | # Assume we're building with g++ for now. |
| 359 | command = [self.cxx] |
| 360 | command += ["-v", "-x", "c++", "/dev/null", "-fsyntax-only"] |
| 361 | includes = [] |
| 362 | self.logger.debug(command) |
| 363 | try: |
| 364 | proc = subprocess.Popen(command, |
| 365 | stdout=subprocess.PIPE, |
| 366 | stderr=subprocess.STDOUT) |
| 367 | |
| 368 | gather = False |
| 369 | line = proc.stdout.readline() |
| 370 | while line: |
| 371 | self.logger.debug(line) |
| 372 | if re.search("End of search list", str(line)) is not None: |
| 373 | self.logger.debug("Stop Gather") |
| 374 | gather = False |
| 375 | if gather: |
| 376 | includes.append(str(line, "utf-8").strip()) |
| 377 | if re.search("#include <...> search starts", str(line)) is not None: |
| 378 | self.logger.debug("Start Gather") |
| 379 | gather = True |
| 380 | line = proc.stdout.readline() |
| 381 | except: |
| 382 | traceback.print_exc() |
| 383 | self.logger.debug(includes) |
| 384 | return includes |
| 385 | |
| 386 | def dobuild(self, source, branch, build): |
| 387 | build_suffix = "" |
| 388 | |
| 389 | ssabbrev = get_short_abbrevs([ab for ab in self.source_abbrev.values()]) |
| 390 | |
| 391 | if branch is not None: |
| 392 | sbabbrev = get_short_abbrevs([ab for ab in self.branch_abbrev.values()]) |
| 393 | |
| 394 | prefix = "[" + ssabbrev[self.source_abbrev[source]] + "-" + sbabbrev[self.branch_abbrev[branch]] + "-" + self.build_abbrev[build] + "]" |
| 395 | self.install_prefix += "/" + self.source_abbrev[source] + "/" + branch + "/" + build |
| 396 | build_suffix += self.source_abbrev[source] + "/" + branch + "/" + build |
| 397 | else: |
| 398 | prefix = "[" + ssabbrev[self.source_abbrev[source]] + "-" + self.build_abbrev[build] + "]" |
| 399 | self.install_prefix += "/" + self.source_abbrev[source] + "/" + build |
| 400 | build_suffix += "/" + self.source_abbrev[source] + "/" + build |
| 401 | |
| 402 | self.logger = logging.getLogger(prefix) |
| 403 | |
| 404 | self.logger.debug(self.install_prefix) |
| 405 | |
| 406 | # Assume we're building with gcc for now. |
| 407 | cxxincludes = self.get_includes() |
| 408 | cxxroot = cxxincludes[0] |
| 409 | cxxarch = os.path.basename(cxxincludes[1]) |
| 410 | |
| 411 | configure_flags = dict( |
| 412 | llvm=dict(debug=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 413 | "--with-extra-options=-Werror", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 414 | "--enable-assertions", |
| 415 | "--disable-optimized", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 416 | "--with-cxx-include-root=" + cxxroot, |
| 417 | "--with-cxx-include-arch=" + cxxarch], |
| 418 | release=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 419 | "--with-extra-options=-Werror", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 420 | "--enable-optimized", |
| 421 | "--with-cxx-include-root=" + cxxroot, |
| 422 | "--with-cxx-include-arch=" + cxxarch], |
| 423 | paranoid=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 424 | "--with-extra-options=-Werror", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 425 | "--enable-assertions", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 426 | "--enable-expensive-checks", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 427 | "--disable-optimized", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 428 | "--with-cxx-include-root=" + cxxroot, |
| 429 | "--with-cxx-include-arch=" + cxxarch]), |
| 430 | llvm_gcc=dict(debug=["--prefix=" + self.install_prefix, |
| 431 | "--enable-checking", |
| 432 | "--program-prefix=llvm-", |
| 433 | "--enable-llvm=" + self.build_prefix + "/llvm/" + build_suffix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 434 | # Fortran install seems to be broken. |
| 435 | # "--enable-languages=c,c++,fortran"], |
| 436 | "--enable-languages=c,c++"], |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 437 | release=["--prefix=" + self.install_prefix, |
| 438 | "--program-prefix=llvm-", |
| 439 | "--enable-llvm=" + self.build_prefix + "/llvm/" + build_suffix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 440 | # Fortran install seems to be broken. |
| 441 | # "--enable-languages=c,c++,fortran"], |
| 442 | "--enable-languages=c,c++"], |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 443 | paranoid=["--prefix=" + self.install_prefix, |
| 444 | "--enable-checking", |
| 445 | "--program-prefix=llvm-", |
| 446 | "--enable-llvm=" + self.build_prefix + "/llvm/" + build_suffix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 447 | # Fortran install seems to be broken. |
| 448 | # "--enable-languages=c,c++,fortran"]), |
| 449 | "--enable-languages=c,c++"]), |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 450 | llvm2=dict(debug=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 451 | "--with-extra-options=-Werror", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 452 | "--enable-assertions", |
| 453 | "--disable-optimized", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 454 | "--with-llvmgccdir=" + self.install_prefix + "/bin", |
| 455 | "--with-cxx-include-root=" + cxxroot, |
| 456 | "--with-cxx-include-arch=" + cxxarch], |
| 457 | release=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 458 | "--with-extra-options=-Werror", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 459 | "--enable-optimized", |
| 460 | "--with-llvmgccdir=" + self.install_prefix + "/bin", |
| 461 | "--with-cxx-include-root=" + cxxroot, |
| 462 | "--with-cxx-include-arch=" + cxxarch], |
| 463 | paranoid=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 464 | "--with-extra-options=-Werror", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 465 | "--enable-assertions", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 466 | "--enable-expensive-checks", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 467 | "--disable-optimized", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 468 | "--with-llvmgccdir=" + self.install_prefix + "/bin", |
| 469 | "--with-cxx-include-root=" + cxxroot, |
| 470 | "--with-cxx-include-arch=" + cxxarch]), |
| 471 | gcc=dict(debug=["--prefix=" + self.install_prefix, |
| 472 | "--enable-checking"], |
| 473 | release=["--prefix=" + self.install_prefix], |
| 474 | paranoid=["--prefix=" + self.install_prefix, |
| 475 | "--enable-checking"]), |
| 476 | dragonegg=dict(debug=[], |
| 477 | release=[], |
| 478 | paranoid=[])) |
| 479 | |
| 480 | configure_env = dict( |
| 481 | llvm=dict(debug=dict(CC=self.cc, |
| 482 | CXX=self.cxx), |
| 483 | release=dict(CC=self.cc, |
| 484 | CXX=self.cxx), |
| 485 | paranoid=dict(CC=self.cc, |
| 486 | CXX=self.cxx)), |
| 487 | llvm_gcc=dict(debug=dict(CC=self.cc, |
| 488 | CXX=self.cxx), |
| 489 | release=dict(CC=self.cc, |
| 490 | CXX=self.cxx), |
| 491 | paranoid=dict(CC=self.cc, |
| 492 | CXX=self.cxx)), |
| 493 | llvm2=dict(debug=dict(CC=self.cc, |
| 494 | CXX=self.cxx), |
| 495 | release=dict(CC=self.cc, |
| 496 | CXX=self.cxx), |
| 497 | paranoid=dict(CC=self.cc, |
| 498 | CXX=self.cxx)), |
| 499 | gcc=dict(debug=dict(CC=self.cc, |
| 500 | CXX=self.cxx), |
| 501 | release=dict(CC=self.cc, |
| 502 | CXX=self.cxx), |
| 503 | paranoid=dict(CC=self.cc, |
| 504 | CXX=self.cxx)), |
| 505 | dragonegg=dict(debug=dict(CC=self.cc, |
| 506 | CXX=self.cxx), |
| 507 | release=dict(CC=self.cc, |
| 508 | CXX=self.cxx), |
| 509 | paranoid=dict(CC=self.cc, |
| 510 | CXX=self.cxx))) |
| 511 | |
| 512 | make_flags = dict( |
| 513 | llvm=dict(debug=["-j" + str(self.jobs)], |
| 514 | release=["-j" + str(self.jobs)], |
| 515 | paranoid=["-j" + str(self.jobs)]), |
| 516 | llvm_gcc=dict(debug=["-j" + str(self.jobs), |
| 517 | "bootstrap"], |
| 518 | release=["-j" + str(self.jobs), |
| 519 | "bootstrap"], |
| 520 | paranoid=["-j" + str(self.jobs), |
| 521 | "bootstrap"]), |
| 522 | llvm2=dict(debug=["-j" + str(self.jobs)], |
| 523 | release=["-j" + str(self.jobs)], |
| 524 | paranoid=["-j" + str(self.jobs)]), |
| 525 | gcc=dict(debug=["-j" + str(self.jobs), |
| 526 | "bootstrap"], |
| 527 | release=["-j" + str(self.jobs), |
| 528 | "bootstrap"], |
| 529 | paranoid=["-j" + str(self.jobs), |
| 530 | "bootstrap"]), |
| 531 | dragonegg=dict(debug=["-j" + str(self.jobs)], |
| 532 | release=["-j" + str(self.jobs)], |
| 533 | paranoid=["-j" + str(self.jobs)])) |
| 534 | |
| 535 | make_env = dict( |
| 536 | llvm=dict(debug=dict(), |
| 537 | release=dict(), |
| 538 | paranoid=dict()), |
| 539 | llvm_gcc=dict(debug=dict(), |
| 540 | release=dict(), |
| 541 | paranoid=dict()), |
| 542 | llvm2=dict(debug=dict(), |
| 543 | release=dict(), |
| 544 | paranoid=dict()), |
| 545 | gcc=dict(debug=dict(), |
| 546 | release=dict(), |
| 547 | paranoid=dict()), |
| 548 | dragonegg=dict(debug=dict(GCC=self.install_prefix + "/bin/gcc", |
| 549 | LLVM_CONFIG=self.install_prefix + "/bin/llvm-config"), |
| 550 | release=dict(GCC=self.install_prefix + "/bin/gcc", |
| 551 | LLVM_CONFIG=self.install_prefix + "/bin/llvm-config"), |
| 552 | paranoid=dict(GCC=self.install_prefix + "/bin/gcc", |
| 553 | LLVM_CONFIG=self.install_prefix + "/bin/llvm-config"))) |
| 554 | |
| 555 | make_install_flags = dict( |
| 556 | llvm=dict(debug=["install"], |
| 557 | release=["install"], |
| 558 | paranoid=["install"]), |
| 559 | llvm_gcc=dict(debug=["install"], |
| 560 | release=["install"], |
| 561 | paranoid=["install"]), |
| 562 | llvm2=dict(debug=["install"], |
| 563 | release=["install"], |
| 564 | paranoid=["install"]), |
| 565 | gcc=dict(debug=["install"], |
| 566 | release=["install"], |
| 567 | paranoid=["install"]), |
| 568 | dragonegg=dict(debug=["install"], |
| 569 | release=["install"], |
| 570 | paranoid=["install"])) |
| 571 | |
| 572 | make_install_env = dict( |
| 573 | llvm=dict(debug=dict(), |
| 574 | release=dict(), |
| 575 | paranoid=dict()), |
| 576 | llvm_gcc=dict(debug=dict(), |
| 577 | release=dict(), |
| 578 | paranoid=dict()), |
| 579 | llvm2=dict(debug=dict(), |
| 580 | release=dict(), |
| 581 | paranoid=dict()), |
| 582 | gcc=dict(debug=dict(), |
| 583 | release=dict(), |
| 584 | paranoid=dict()), |
| 585 | dragonegg=dict(debug=dict(), |
| 586 | release=dict(), |
| 587 | paranoid=dict())) |
| 588 | |
| 589 | make_check_flags = dict( |
| 590 | llvm=dict(debug=["check"], |
| 591 | release=["check"], |
| 592 | paranoid=["check"]), |
| 593 | llvm_gcc=dict(debug=["check"], |
| 594 | release=["check"], |
| 595 | paranoid=["check"]), |
| 596 | llvm2=dict(debug=["check"], |
| 597 | release=["check"], |
| 598 | paranoid=["check"]), |
| 599 | gcc=dict(debug=["check"], |
| 600 | release=["check"], |
| 601 | paranoid=["check"]), |
| 602 | dragonegg=dict(debug=["check"], |
| 603 | release=["check"], |
| 604 | paranoid=["check"])) |
| 605 | |
| 606 | make_check_env = dict( |
| 607 | llvm=dict(debug=dict(), |
| 608 | release=dict(), |
| 609 | paranoid=dict()), |
| 610 | llvm_gcc=dict(debug=dict(), |
| 611 | release=dict(), |
| 612 | paranoid=dict()), |
| 613 | llvm2=dict(debug=dict(), |
| 614 | release=dict(), |
| 615 | paranoid=dict()), |
| 616 | gcc=dict(debug=dict(), |
| 617 | release=dict(), |
| 618 | paranoid=dict()), |
| 619 | dragonegg=dict(debug=dict(), |
| 620 | release=dict(), |
| 621 | paranoid=dict())) |
| 622 | |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 623 | for component in components: |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 624 | comp = component[:] |
| 625 | |
| 626 | srcdir = source + "/" + comp.rstrip("2") |
| 627 | builddir = self.build_prefix + "/" + comp + "/" + build_suffix |
| 628 | installdir = self.install_prefix |
| 629 | |
| 630 | if (branch is not None): |
| 631 | srcdir += "/" + branch |
| 632 | |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 633 | comp_key = comp.replace("-", "_") |
| 634 | |
| 635 | config_args = configure_flags[comp_key][build][:] |
| 636 | config_args.extend(getattr(self.options, |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 637 | "extra_" + comp_key.rstrip("2") |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 638 | + "_config_flags").split()) |
| 639 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 640 | self.logger.info("Configuring " + component + " in " + builddir) |
| 641 | self.configure(component, srcdir, builddir, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 642 | config_args, |
| 643 | configure_env[comp_key][build]) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 644 | |
| 645 | self.logger.info("Building " + component + " in " + builddir) |
| 646 | self.make(component, srcdir, builddir, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 647 | make_flags[comp_key][build], |
| 648 | make_env[comp_key][build]) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 649 | |
| 650 | self.logger.info("Installing " + component + " in " + installdir) |
| 651 | self.make(component, srcdir, builddir, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 652 | make_install_flags[comp_key][build], |
| 653 | make_install_env[comp_key][build]) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 654 | |
| 655 | self.logger.info("Testing " + component + " in " + builddir) |
| 656 | self.make(component, srcdir, builddir, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 657 | make_check_flags[comp_key][build], |
| 658 | make_check_env[comp_key][build]) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 659 | |
| 660 | |
| 661 | def configure(self, component, srcdir, builddir, flags, env): |
David Greene | b1939d5 | 2011-03-04 23:02:52 +0000 | [diff] [blame] | 662 | self.logger.debug("Configure " + str(flags) + " " + str(srcdir) + " -> " |
| 663 | + str(builddir)) |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 664 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 665 | configure_files = dict( |
| 666 | llvm=[(srcdir + "/configure", builddir + "/Makefile")], |
| 667 | llvm_gcc=[(srcdir + "/configure", builddir + "/Makefile"), |
| 668 | (srcdir + "/gcc/configure", builddir + "/gcc/Makefile")], |
| 669 | llvm2=[(srcdir + "/configure", builddir + "/Makefile")], |
| 670 | gcc=[(srcdir + "/configure", builddir + "/Makefile"), |
| 671 | (srcdir + "/gcc/configure", builddir + "/gcc/Makefile")], |
| 672 | dragonegg=[()]) |
| 673 | |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 674 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 675 | doconfig = False |
| 676 | for conf, mf in configure_files[component.replace("-", "_")]: |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 677 | if not os.path.exists(conf): |
| 678 | return |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 679 | if os.path.exists(conf) and os.path.exists(mf): |
| 680 | confstat = os.stat(conf) |
| 681 | makestat = os.stat(mf) |
| 682 | if confstat.st_mtime > makestat.st_mtime: |
| 683 | doconfig = True |
| 684 | break |
| 685 | else: |
| 686 | doconfig = True |
| 687 | break |
| 688 | |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 689 | if not doconfig and not self.options.force_configure: |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 690 | return |
| 691 | |
| 692 | program = srcdir + "/configure" |
| 693 | if not is_executable(program): |
| 694 | return |
| 695 | |
| 696 | args = [program] |
| 697 | args += ["--verbose"] |
| 698 | args += flags |
| 699 | self.execute(args, builddir, env, component) |
| 700 | |
| 701 | def make(self, component, srcdir, builddir, flags, env): |
| 702 | program = find_executable("make") |
| 703 | if program is None: |
| 704 | raise ExecutableNotFound |
| 705 | |
| 706 | if not is_executable(program): |
| 707 | raise FileNotExecutable |
| 708 | |
| 709 | args = [program] |
| 710 | args += flags |
| 711 | self.execute(args, builddir, env, component) |
| 712 | |
| 713 | # Global constants |
| 714 | build_abbrev = dict(debug="dbg", release="opt", paranoid="par") |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 715 | #components = ["llvm", "llvm-gcc", "llvm2", "gcc", "dragonegg"] |
| 716 | components = ["llvm", "llvm2", "gcc", "dragonegg"] |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 717 | |
| 718 | # Parse options |
| 719 | parser = optparse.OptionParser(version="%prog 1.0") |
| 720 | add_options(parser) |
| 721 | (options, args) = parser.parse_args() |
| 722 | check_options(parser, options, build_abbrev.keys()); |
| 723 | |
| 724 | if options.verbose: |
| 725 | logging.basicConfig(level=logging.DEBUG, |
| 726 | format='%(name)-13s: %(message)s') |
| 727 | else: |
| 728 | logging.basicConfig(level=logging.INFO, |
| 729 | format='%(name)-13s: %(message)s') |
| 730 | |
| 731 | source_abbrev = get_path_abbrevs(set(options.src)) |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame^] | 732 | |
| 733 | branch_abbrev = None |
| 734 | if options.branch is not None: |
| 735 | branch_abbrev = get_path_abbrevs(set(options.branch)) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 736 | |
| 737 | work_queue = queue.Queue() |
| 738 | |
David Greene | b1939d5 | 2011-03-04 23:02:52 +0000 | [diff] [blame] | 739 | jobs = options.jobs // options.threads |
| 740 | if jobs == 0: |
| 741 | jobs = 1 |
| 742 | |
| 743 | numthreads = options.threads |
| 744 | if jobs < numthreads: |
| 745 | numthreads = jobs |
| 746 | jobs = 1 |
| 747 | |
| 748 | for t in range(numthreads): |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 749 | builder = Builder(work_queue, jobs, |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 750 | build_abbrev, source_abbrev, branch_abbrev, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 751 | options) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 752 | builder.daemon = True |
| 753 | builder.start() |
| 754 | |
| 755 | for build in set(options.build): |
| 756 | for source in set(options.src): |
| 757 | if options.branch is not None: |
| 758 | for branch in set(options.branch): |
| 759 | work_queue.put((source, branch, build)) |
| 760 | else: |
| 761 | work_queue.put((source, None, build)) |
| 762 | |
| 763 | work_queue.join() |