annotate llvm/utils/llvm-compilers-check @ 198:cef006dc7fd5

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