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 | d17f813 | 2011-10-14 19:12:33 +0000 | [diff] [blame^] | 192 | parser.add_option("--no-gcc", default=False, action="store_true", |
| 193 | help=("Do not build dragonegg and gcc")) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 194 | return |
| 195 | |
| 196 | def check_options(parser, options, valid_builds): |
| 197 | # See if we're building valid flavors. |
| 198 | for build in options.build: |
| 199 | if (build not in valid_builds): |
| 200 | parser.error("'" + build + "' is not a valid build flavor " |
| 201 | + str(valid_builds)) |
| 202 | |
| 203 | # See if we can find source directories. |
| 204 | for src in options.src: |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 205 | for component in components: |
| 206 | component = component.rstrip("2") |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 207 | compsrc = src + "/" + component |
| 208 | if (not os.path.isdir(compsrc)): |
| 209 | parser.error("'" + compsrc + "' does not exist") |
| 210 | if (options.branch is not None): |
| 211 | for branch in options.branch: |
| 212 | if (not os.path.isdir(os.path.join(compsrc, branch))): |
| 213 | parser.error("'" + os.path.join(compsrc, branch) |
| 214 | + "' does not exist") |
| 215 | |
| 216 | # See if we can find the compilers |
| 217 | options.cc = find_executable(options.cc) |
| 218 | options.cxx = find_executable(options.cxx) |
| 219 | |
| 220 | return |
| 221 | |
| 222 | # Find a unique short name for the given set of paths. This searches |
| 223 | # back through path components until it finds unique component names |
| 224 | # among all given paths. |
| 225 | def get_path_abbrevs(paths): |
| 226 | # Find the number of common starting characters in the last component |
| 227 | # of the paths. |
| 228 | unique_paths = list(paths) |
| 229 | |
| 230 | class NotFoundException(Exception): pass |
| 231 | |
| 232 | # Find a unique component of each path. |
| 233 | unique_bases = unique_paths[:] |
| 234 | found = 0 |
| 235 | while len(unique_paths) > 0: |
| 236 | bases = [os.path.basename(src) for src in unique_paths] |
| 237 | components = { c for c in bases } |
| 238 | # Account for single entry in paths. |
| 239 | if len(components) > 1 or len(components) == len(bases): |
| 240 | # We found something unique. |
| 241 | for c in components: |
| 242 | if bases.count(c) == 1: |
| 243 | index = bases.index(c) |
| 244 | unique_bases[index] = c |
| 245 | # Remove the corresponding path from the set under |
| 246 | # consideration. |
| 247 | unique_paths[index] = None |
| 248 | unique_paths = [ p for p in unique_paths if p is not None ] |
| 249 | unique_paths = [os.path.dirname(src) for src in unique_paths] |
| 250 | |
| 251 | if len(unique_paths) > 0: |
| 252 | raise NotFoundException() |
| 253 | |
| 254 | abbrevs = dict(zip(paths, [base for base in unique_bases])) |
| 255 | |
| 256 | return abbrevs |
| 257 | |
| 258 | # Given a set of unique names, find a short character sequence that |
| 259 | # uniquely identifies them. |
| 260 | def get_short_abbrevs(unique_bases): |
| 261 | # Find a unique start character for each path base. |
| 262 | my_unique_bases = unique_bases[:] |
| 263 | unique_char_starts = unique_bases[:] |
| 264 | while len(my_unique_bases) > 0: |
| 265 | for start, char_tuple in enumerate(zip(*[base |
| 266 | for base in my_unique_bases])): |
| 267 | chars = { c for c in char_tuple } |
| 268 | # Account for single path. |
| 269 | if len(chars) > 1 or len(chars) == len(char_tuple): |
| 270 | # We found something unique. |
| 271 | for c in chars: |
| 272 | if char_tuple.count(c) == 1: |
| 273 | index = char_tuple.index(c) |
| 274 | unique_char_starts[index] = start |
| 275 | # Remove the corresponding path from the set under |
| 276 | # consideration. |
| 277 | my_unique_bases[index] = None |
| 278 | my_unique_bases = [ b for b in my_unique_bases |
| 279 | if b is not None ] |
| 280 | break |
| 281 | |
| 282 | if len(my_unique_bases) > 0: |
| 283 | raise NotFoundException() |
| 284 | |
| 285 | abbrevs = [abbrev[start_index:start_index+3] |
| 286 | for abbrev, start_index |
| 287 | in zip([base for base in unique_bases], |
| 288 | [index for index in unique_char_starts])] |
| 289 | |
| 290 | abbrevs = dict(zip(unique_bases, abbrevs)) |
| 291 | |
| 292 | return abbrevs |
| 293 | |
| 294 | class Builder(threading.Thread): |
| 295 | class ExecutableNotFound(Exception): pass |
| 296 | class FileNotExecutable(Exception): pass |
| 297 | |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 298 | def __init__(self, work_queue, jobs, |
| 299 | build_abbrev, source_abbrev, branch_abbrev, |
| 300 | options): |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 301 | super().__init__() |
| 302 | self.work_queue = work_queue |
| 303 | self.jobs = jobs |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 304 | self.cc = options.cc |
| 305 | self.cxx = options.cxx |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 306 | self.build_abbrev = build_abbrev |
| 307 | self.source_abbrev = source_abbrev |
| 308 | self.branch_abbrev = branch_abbrev |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 309 | self.build_prefix = options.builddir |
| 310 | self.install_prefix = options.prefix |
| 311 | self.options = options |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 312 | self.component_abbrev = dict( |
| 313 | llvm="llvm", |
| 314 | llvm_gcc="lgcc", |
| 315 | llvm2="llv2", |
| 316 | gcc="ugcc", |
| 317 | dagonegg="degg") |
| 318 | def run(self): |
| 319 | while True: |
| 320 | try: |
| 321 | source, branch, build = self.work_queue.get() |
| 322 | self.dobuild(source, branch, build) |
| 323 | except: |
| 324 | traceback.print_exc() |
| 325 | finally: |
| 326 | self.work_queue.task_done() |
| 327 | |
| 328 | def execute(self, command, execdir, env, component): |
| 329 | prefix = self.component_abbrev[component.replace("-", "_")] |
| 330 | pwd = os.getcwd() |
| 331 | if not os.path.exists(execdir): |
| 332 | os.makedirs(execdir) |
| 333 | |
David Greene | 8b890c2 | 2011-02-22 23:30:45 +0000 | [diff] [blame] | 334 | execenv = os.environ.copy() |
| 335 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 336 | for key, value in env.items(): |
David Greene | 8b890c2 | 2011-02-22 23:30:45 +0000 | [diff] [blame] | 337 | execenv[key] = value |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 338 | |
| 339 | self.logger.debug("[" + prefix + "] " + "env " + str(env) + " " |
| 340 | + " ".join(command)); |
| 341 | |
| 342 | try: |
| 343 | proc = subprocess.Popen(command, |
| 344 | cwd=execdir, |
David Greene | 8b890c2 | 2011-02-22 23:30:45 +0000 | [diff] [blame] | 345 | env=execenv, |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 346 | stdout=subprocess.PIPE, |
| 347 | stderr=subprocess.STDOUT) |
| 348 | |
| 349 | line = proc.stdout.readline() |
| 350 | while line: |
| 351 | self.logger.info("[" + prefix + "] " |
| 352 | + str(line, "utf-8").rstrip()) |
| 353 | line = proc.stdout.readline() |
| 354 | |
| 355 | except: |
| 356 | traceback.print_exc() |
| 357 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 358 | # Get a list of C++ include directories to pass to clang. |
| 359 | def get_includes(self): |
| 360 | # Assume we're building with g++ for now. |
| 361 | command = [self.cxx] |
| 362 | command += ["-v", "-x", "c++", "/dev/null", "-fsyntax-only"] |
| 363 | includes = [] |
| 364 | self.logger.debug(command) |
| 365 | try: |
| 366 | proc = subprocess.Popen(command, |
| 367 | stdout=subprocess.PIPE, |
| 368 | stderr=subprocess.STDOUT) |
| 369 | |
| 370 | gather = False |
| 371 | line = proc.stdout.readline() |
| 372 | while line: |
| 373 | self.logger.debug(line) |
| 374 | if re.search("End of search list", str(line)) is not None: |
| 375 | self.logger.debug("Stop Gather") |
| 376 | gather = False |
| 377 | if gather: |
| 378 | includes.append(str(line, "utf-8").strip()) |
| 379 | if re.search("#include <...> search starts", str(line)) is not None: |
| 380 | self.logger.debug("Start Gather") |
| 381 | gather = True |
| 382 | line = proc.stdout.readline() |
| 383 | except: |
| 384 | traceback.print_exc() |
| 385 | self.logger.debug(includes) |
| 386 | return includes |
| 387 | |
| 388 | def dobuild(self, source, branch, build): |
| 389 | build_suffix = "" |
| 390 | |
| 391 | ssabbrev = get_short_abbrevs([ab for ab in self.source_abbrev.values()]) |
| 392 | |
| 393 | if branch is not None: |
| 394 | sbabbrev = get_short_abbrevs([ab for ab in self.branch_abbrev.values()]) |
| 395 | |
| 396 | prefix = "[" + ssabbrev[self.source_abbrev[source]] + "-" + sbabbrev[self.branch_abbrev[branch]] + "-" + self.build_abbrev[build] + "]" |
| 397 | self.install_prefix += "/" + self.source_abbrev[source] + "/" + branch + "/" + build |
| 398 | build_suffix += self.source_abbrev[source] + "/" + branch + "/" + build |
| 399 | else: |
| 400 | prefix = "[" + ssabbrev[self.source_abbrev[source]] + "-" + self.build_abbrev[build] + "]" |
| 401 | self.install_prefix += "/" + self.source_abbrev[source] + "/" + build |
| 402 | build_suffix += "/" + self.source_abbrev[source] + "/" + build |
| 403 | |
| 404 | self.logger = logging.getLogger(prefix) |
| 405 | |
| 406 | self.logger.debug(self.install_prefix) |
| 407 | |
| 408 | # Assume we're building with gcc for now. |
| 409 | cxxincludes = self.get_includes() |
| 410 | cxxroot = cxxincludes[0] |
| 411 | cxxarch = os.path.basename(cxxincludes[1]) |
| 412 | |
| 413 | configure_flags = dict( |
| 414 | llvm=dict(debug=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 415 | "--with-extra-options=-Werror", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 416 | "--enable-assertions", |
| 417 | "--disable-optimized", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 418 | "--with-cxx-include-root=" + cxxroot, |
| 419 | "--with-cxx-include-arch=" + cxxarch], |
| 420 | release=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 421 | "--with-extra-options=-Werror", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 422 | "--enable-optimized", |
| 423 | "--with-cxx-include-root=" + cxxroot, |
| 424 | "--with-cxx-include-arch=" + cxxarch], |
| 425 | paranoid=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 426 | "--with-extra-options=-Werror", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 427 | "--enable-assertions", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 428 | "--enable-expensive-checks", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 429 | "--disable-optimized", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 430 | "--with-cxx-include-root=" + cxxroot, |
| 431 | "--with-cxx-include-arch=" + cxxarch]), |
| 432 | llvm_gcc=dict(debug=["--prefix=" + self.install_prefix, |
| 433 | "--enable-checking", |
| 434 | "--program-prefix=llvm-", |
| 435 | "--enable-llvm=" + self.build_prefix + "/llvm/" + build_suffix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 436 | # Fortran install seems to be broken. |
| 437 | # "--enable-languages=c,c++,fortran"], |
| 438 | "--enable-languages=c,c++"], |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 439 | release=["--prefix=" + self.install_prefix, |
| 440 | "--program-prefix=llvm-", |
| 441 | "--enable-llvm=" + self.build_prefix + "/llvm/" + build_suffix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 442 | # Fortran install seems to be broken. |
| 443 | # "--enable-languages=c,c++,fortran"], |
| 444 | "--enable-languages=c,c++"], |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 445 | paranoid=["--prefix=" + self.install_prefix, |
| 446 | "--enable-checking", |
| 447 | "--program-prefix=llvm-", |
| 448 | "--enable-llvm=" + self.build_prefix + "/llvm/" + build_suffix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 449 | # Fortran install seems to be broken. |
| 450 | # "--enable-languages=c,c++,fortran"]), |
| 451 | "--enable-languages=c,c++"]), |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 452 | llvm2=dict(debug=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 453 | "--with-extra-options=-Werror", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 454 | "--enable-assertions", |
| 455 | "--disable-optimized", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 456 | "--with-llvmgccdir=" + self.install_prefix + "/bin", |
| 457 | "--with-cxx-include-root=" + cxxroot, |
| 458 | "--with-cxx-include-arch=" + cxxarch], |
| 459 | release=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 460 | "--with-extra-options=-Werror", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 461 | "--enable-optimized", |
| 462 | "--with-llvmgccdir=" + self.install_prefix + "/bin", |
| 463 | "--with-cxx-include-root=" + cxxroot, |
| 464 | "--with-cxx-include-arch=" + cxxarch], |
| 465 | paranoid=["--prefix=" + self.install_prefix, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 466 | "--with-extra-options=-Werror", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 467 | "--enable-assertions", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 468 | "--enable-expensive-checks", |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 469 | "--disable-optimized", |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 470 | "--with-llvmgccdir=" + self.install_prefix + "/bin", |
| 471 | "--with-cxx-include-root=" + cxxroot, |
| 472 | "--with-cxx-include-arch=" + cxxarch]), |
| 473 | gcc=dict(debug=["--prefix=" + self.install_prefix, |
| 474 | "--enable-checking"], |
| 475 | release=["--prefix=" + self.install_prefix], |
| 476 | paranoid=["--prefix=" + self.install_prefix, |
| 477 | "--enable-checking"]), |
| 478 | dragonegg=dict(debug=[], |
| 479 | release=[], |
| 480 | paranoid=[])) |
| 481 | |
| 482 | configure_env = dict( |
| 483 | llvm=dict(debug=dict(CC=self.cc, |
| 484 | CXX=self.cxx), |
| 485 | release=dict(CC=self.cc, |
| 486 | CXX=self.cxx), |
| 487 | paranoid=dict(CC=self.cc, |
| 488 | CXX=self.cxx)), |
| 489 | llvm_gcc=dict(debug=dict(CC=self.cc, |
| 490 | CXX=self.cxx), |
| 491 | release=dict(CC=self.cc, |
| 492 | CXX=self.cxx), |
| 493 | paranoid=dict(CC=self.cc, |
| 494 | CXX=self.cxx)), |
| 495 | llvm2=dict(debug=dict(CC=self.cc, |
| 496 | CXX=self.cxx), |
| 497 | release=dict(CC=self.cc, |
| 498 | CXX=self.cxx), |
| 499 | paranoid=dict(CC=self.cc, |
| 500 | CXX=self.cxx)), |
| 501 | gcc=dict(debug=dict(CC=self.cc, |
| 502 | CXX=self.cxx), |
| 503 | release=dict(CC=self.cc, |
| 504 | CXX=self.cxx), |
| 505 | paranoid=dict(CC=self.cc, |
| 506 | CXX=self.cxx)), |
| 507 | dragonegg=dict(debug=dict(CC=self.cc, |
| 508 | CXX=self.cxx), |
| 509 | release=dict(CC=self.cc, |
| 510 | CXX=self.cxx), |
| 511 | paranoid=dict(CC=self.cc, |
| 512 | CXX=self.cxx))) |
| 513 | |
| 514 | make_flags = dict( |
| 515 | llvm=dict(debug=["-j" + str(self.jobs)], |
| 516 | release=["-j" + str(self.jobs)], |
| 517 | paranoid=["-j" + str(self.jobs)]), |
| 518 | llvm_gcc=dict(debug=["-j" + str(self.jobs), |
| 519 | "bootstrap"], |
| 520 | release=["-j" + str(self.jobs), |
| 521 | "bootstrap"], |
| 522 | paranoid=["-j" + str(self.jobs), |
| 523 | "bootstrap"]), |
| 524 | llvm2=dict(debug=["-j" + str(self.jobs)], |
| 525 | release=["-j" + str(self.jobs)], |
| 526 | paranoid=["-j" + str(self.jobs)]), |
| 527 | gcc=dict(debug=["-j" + str(self.jobs), |
| 528 | "bootstrap"], |
| 529 | release=["-j" + str(self.jobs), |
| 530 | "bootstrap"], |
| 531 | paranoid=["-j" + str(self.jobs), |
| 532 | "bootstrap"]), |
| 533 | dragonegg=dict(debug=["-j" + str(self.jobs)], |
| 534 | release=["-j" + str(self.jobs)], |
| 535 | paranoid=["-j" + str(self.jobs)])) |
| 536 | |
| 537 | make_env = dict( |
| 538 | llvm=dict(debug=dict(), |
| 539 | release=dict(), |
| 540 | paranoid=dict()), |
| 541 | llvm_gcc=dict(debug=dict(), |
| 542 | release=dict(), |
| 543 | paranoid=dict()), |
| 544 | llvm2=dict(debug=dict(), |
| 545 | release=dict(), |
| 546 | paranoid=dict()), |
| 547 | gcc=dict(debug=dict(), |
| 548 | release=dict(), |
| 549 | paranoid=dict()), |
| 550 | dragonegg=dict(debug=dict(GCC=self.install_prefix + "/bin/gcc", |
| 551 | LLVM_CONFIG=self.install_prefix + "/bin/llvm-config"), |
| 552 | release=dict(GCC=self.install_prefix + "/bin/gcc", |
| 553 | LLVM_CONFIG=self.install_prefix + "/bin/llvm-config"), |
| 554 | paranoid=dict(GCC=self.install_prefix + "/bin/gcc", |
| 555 | LLVM_CONFIG=self.install_prefix + "/bin/llvm-config"))) |
| 556 | |
| 557 | make_install_flags = dict( |
| 558 | llvm=dict(debug=["install"], |
| 559 | release=["install"], |
| 560 | paranoid=["install"]), |
| 561 | llvm_gcc=dict(debug=["install"], |
| 562 | release=["install"], |
| 563 | paranoid=["install"]), |
| 564 | llvm2=dict(debug=["install"], |
| 565 | release=["install"], |
| 566 | paranoid=["install"]), |
| 567 | gcc=dict(debug=["install"], |
| 568 | release=["install"], |
| 569 | paranoid=["install"]), |
| 570 | dragonegg=dict(debug=["install"], |
| 571 | release=["install"], |
| 572 | paranoid=["install"])) |
| 573 | |
| 574 | make_install_env = dict( |
| 575 | llvm=dict(debug=dict(), |
| 576 | release=dict(), |
| 577 | paranoid=dict()), |
| 578 | llvm_gcc=dict(debug=dict(), |
| 579 | release=dict(), |
| 580 | paranoid=dict()), |
| 581 | llvm2=dict(debug=dict(), |
| 582 | release=dict(), |
| 583 | paranoid=dict()), |
| 584 | gcc=dict(debug=dict(), |
| 585 | release=dict(), |
| 586 | paranoid=dict()), |
| 587 | dragonegg=dict(debug=dict(), |
| 588 | release=dict(), |
| 589 | paranoid=dict())) |
| 590 | |
| 591 | make_check_flags = dict( |
| 592 | llvm=dict(debug=["check"], |
| 593 | release=["check"], |
| 594 | paranoid=["check"]), |
| 595 | llvm_gcc=dict(debug=["check"], |
| 596 | release=["check"], |
| 597 | paranoid=["check"]), |
| 598 | llvm2=dict(debug=["check"], |
| 599 | release=["check"], |
| 600 | paranoid=["check"]), |
| 601 | gcc=dict(debug=["check"], |
| 602 | release=["check"], |
| 603 | paranoid=["check"]), |
| 604 | dragonegg=dict(debug=["check"], |
| 605 | release=["check"], |
| 606 | paranoid=["check"])) |
| 607 | |
| 608 | make_check_env = dict( |
| 609 | llvm=dict(debug=dict(), |
| 610 | release=dict(), |
| 611 | paranoid=dict()), |
| 612 | llvm_gcc=dict(debug=dict(), |
| 613 | release=dict(), |
| 614 | paranoid=dict()), |
| 615 | llvm2=dict(debug=dict(), |
| 616 | release=dict(), |
| 617 | paranoid=dict()), |
| 618 | gcc=dict(debug=dict(), |
| 619 | release=dict(), |
| 620 | paranoid=dict()), |
| 621 | dragonegg=dict(debug=dict(), |
| 622 | release=dict(), |
| 623 | paranoid=dict())) |
| 624 | |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 625 | for component in components: |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 626 | comp = component[:] |
David Greene | d17f813 | 2011-10-14 19:12:33 +0000 | [diff] [blame^] | 627 | |
| 628 | if (self.options.no_gcc): |
| 629 | if (comp == 'gcc' or comp == 'dragonegg' or comp == 'llvm2'): |
| 630 | self.logger.info("Skipping " + component + " in " |
| 631 | + builddir) |
| 632 | continue |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 633 | |
| 634 | srcdir = source + "/" + comp.rstrip("2") |
| 635 | builddir = self.build_prefix + "/" + comp + "/" + build_suffix |
| 636 | installdir = self.install_prefix |
| 637 | |
| 638 | if (branch is not None): |
| 639 | srcdir += "/" + branch |
| 640 | |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 641 | comp_key = comp.replace("-", "_") |
| 642 | |
| 643 | config_args = configure_flags[comp_key][build][:] |
| 644 | config_args.extend(getattr(self.options, |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 645 | "extra_" + comp_key.rstrip("2") |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 646 | + "_config_flags").split()) |
| 647 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 648 | self.logger.info("Configuring " + component + " in " + builddir) |
| 649 | self.configure(component, srcdir, builddir, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 650 | config_args, |
| 651 | configure_env[comp_key][build]) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 652 | |
| 653 | self.logger.info("Building " + component + " in " + builddir) |
| 654 | self.make(component, srcdir, builddir, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 655 | make_flags[comp_key][build], |
| 656 | make_env[comp_key][build]) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 657 | |
| 658 | self.logger.info("Installing " + component + " in " + installdir) |
| 659 | self.make(component, srcdir, builddir, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 660 | make_install_flags[comp_key][build], |
| 661 | make_install_env[comp_key][build]) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 662 | |
| 663 | self.logger.info("Testing " + component + " in " + builddir) |
| 664 | self.make(component, srcdir, builddir, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 665 | make_check_flags[comp_key][build], |
| 666 | make_check_env[comp_key][build]) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 667 | |
| 668 | |
| 669 | def configure(self, component, srcdir, builddir, flags, env): |
David Greene | b1939d5 | 2011-03-04 23:02:52 +0000 | [diff] [blame] | 670 | self.logger.debug("Configure " + str(flags) + " " + str(srcdir) + " -> " |
| 671 | + str(builddir)) |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 672 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 673 | configure_files = dict( |
| 674 | llvm=[(srcdir + "/configure", builddir + "/Makefile")], |
| 675 | llvm_gcc=[(srcdir + "/configure", builddir + "/Makefile"), |
| 676 | (srcdir + "/gcc/configure", builddir + "/gcc/Makefile")], |
| 677 | llvm2=[(srcdir + "/configure", builddir + "/Makefile")], |
| 678 | gcc=[(srcdir + "/configure", builddir + "/Makefile"), |
| 679 | (srcdir + "/gcc/configure", builddir + "/gcc/Makefile")], |
| 680 | dragonegg=[()]) |
| 681 | |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 682 | |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 683 | doconfig = False |
| 684 | for conf, mf in configure_files[component.replace("-", "_")]: |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 685 | if not os.path.exists(conf): |
| 686 | return |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 687 | if os.path.exists(conf) and os.path.exists(mf): |
| 688 | confstat = os.stat(conf) |
| 689 | makestat = os.stat(mf) |
| 690 | if confstat.st_mtime > makestat.st_mtime: |
| 691 | doconfig = True |
| 692 | break |
| 693 | else: |
| 694 | doconfig = True |
| 695 | break |
| 696 | |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 697 | if not doconfig and not self.options.force_configure: |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 698 | return |
| 699 | |
| 700 | program = srcdir + "/configure" |
| 701 | if not is_executable(program): |
| 702 | return |
| 703 | |
| 704 | args = [program] |
| 705 | args += ["--verbose"] |
| 706 | args += flags |
| 707 | self.execute(args, builddir, env, component) |
| 708 | |
| 709 | def make(self, component, srcdir, builddir, flags, env): |
| 710 | program = find_executable("make") |
| 711 | if program is None: |
| 712 | raise ExecutableNotFound |
| 713 | |
| 714 | if not is_executable(program): |
| 715 | raise FileNotExecutable |
| 716 | |
| 717 | args = [program] |
| 718 | args += flags |
| 719 | self.execute(args, builddir, env, component) |
| 720 | |
| 721 | # Global constants |
| 722 | build_abbrev = dict(debug="dbg", release="opt", paranoid="par") |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 723 | #components = ["llvm", "llvm-gcc", "llvm2", "gcc", "dragonegg"] |
| 724 | components = ["llvm", "llvm2", "gcc", "dragonegg"] |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 725 | |
| 726 | # Parse options |
| 727 | parser = optparse.OptionParser(version="%prog 1.0") |
| 728 | add_options(parser) |
| 729 | (options, args) = parser.parse_args() |
| 730 | check_options(parser, options, build_abbrev.keys()); |
| 731 | |
| 732 | if options.verbose: |
| 733 | logging.basicConfig(level=logging.DEBUG, |
| 734 | format='%(name)-13s: %(message)s') |
| 735 | else: |
| 736 | logging.basicConfig(level=logging.INFO, |
| 737 | format='%(name)-13s: %(message)s') |
| 738 | |
| 739 | source_abbrev = get_path_abbrevs(set(options.src)) |
David Greene | e234cd9 | 2011-07-06 16:54:14 +0000 | [diff] [blame] | 740 | |
| 741 | branch_abbrev = None |
| 742 | if options.branch is not None: |
| 743 | branch_abbrev = get_path_abbrevs(set(options.branch)) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 744 | |
| 745 | work_queue = queue.Queue() |
| 746 | |
David Greene | b1939d5 | 2011-03-04 23:02:52 +0000 | [diff] [blame] | 747 | jobs = options.jobs // options.threads |
| 748 | if jobs == 0: |
| 749 | jobs = 1 |
| 750 | |
| 751 | numthreads = options.threads |
| 752 | if jobs < numthreads: |
| 753 | numthreads = jobs |
| 754 | jobs = 1 |
| 755 | |
| 756 | for t in range(numthreads): |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 757 | builder = Builder(work_queue, jobs, |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 758 | build_abbrev, source_abbrev, branch_abbrev, |
David Greene | 14a129a | 2011-02-25 20:51:27 +0000 | [diff] [blame] | 759 | options) |
David Greene | 8b8b4af | 2011-02-21 19:23:22 +0000 | [diff] [blame] | 760 | builder.daemon = True |
| 761 | builder.start() |
| 762 | |
| 763 | for build in set(options.build): |
| 764 | for source in set(options.src): |
| 765 | if options.branch is not None: |
| 766 | for branch in set(options.branch): |
| 767 | work_queue.put((source, branch, build)) |
| 768 | else: |
| 769 | work_queue.put((source, None, build)) |
| 770 | |
| 771 | work_queue.join() |