llvm.org GIT mirror llvm / e959bd0
Run pyformat on lit code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315084 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
3 changed file(s) with 173 addition(s) and 129 deletion(s). Raw diff Collapse all Expand all
3737 llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
3838
3939 # Propagate some variables from the host environment.
40 llvm_config.with_system_environment(['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
40 llvm_config.with_system_environment(
41 ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
4142
4243
4344 # Set up OCAMLPATH to include newly built OCaml libraries.
4950 llvm_config.with_environment('OCAMLPATH', llvm_ocaml_lib, append_path=True)
5051
5152 llvm_config.with_system_environment('CAML_LD_LIBRARY_PATH')
52 llvm_config.with_environment('CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
53 llvm_config.with_environment(
54 'CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
5355
5456 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
5557 llvm_config.with_environment('OCAMLRUNPARAM', 'b')
5658
5759 # Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
5860 # available. This is darwin specific since it's currently only needed on darwin.
61
62
5963 def get_asan_rtlib():
60 if not "Address" in config.llvm_use_sanitizer or \
61 not "Darwin" in config.host_os or \
62 not "x86" in config.host_triple:
63 return ""
64 if not 'Address' in config.llvm_use_sanitizer or \
65 not 'Darwin' in config.host_os or \
66 not 'x86' in config.host_triple:
67 return ''
6468 try:
6569 import glob
6670 except:
67 print("glob module not found, skipping get_asan_rtlib() lookup")
68 return ""
71 print('glob module not found, skipping get_asan_rtlib() lookup')
72 return ''
6973 # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative
7074 # path from the host cc.
71 host_lib_dir = os.path.join(os.path.dirname(config.host_cc), "../lib")
75 host_lib_dir = os.path.join(os.path.dirname(config.host_cc), '../lib')
7276 asan_dylib_dir_pattern = host_lib_dir + \
73 "/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib"
77 '/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib'
7478 found_dylibs = glob.glob(asan_dylib_dir_pattern)
7579 if len(found_dylibs) != 1:
76 return ""
80 return ''
7781 return found_dylibs[0]
82
7883
7984 lli = 'lli'
8085 # The target triple used by default by lli is the process target triple (some
8388 # Windows. FIXME: the process target triple should be used here, but this is
8489 # difficult to obtain on Windows.
8590 if re.search(r'cygwin|mingw32|windows-gnu|windows-msvc|win32', config.host_triple):
86 lli += ' -mtriple='+config.host_triple+'-elf'
87 config.substitutions.append( ('%lli', lli ) )
91 lli += ' -mtriple=' + config.host_triple + '-elf'
92 config.substitutions.append(('%lli', lli))
8893
8994 # Similarly, have a macro to use llc with DWARF even when the host is win32.
9095 llc_dwarf = 'llc'
9196 if re.search(r'win32', config.target_triple):
92 llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32')
93 config.substitutions.append( ('%llc_dwarf', llc_dwarf) )
97 llc_dwarf += ' -mtriple=' + \
98 config.target_triple.replace('-win32', '-mingw32')
99 config.substitutions.append(('%llc_dwarf', llc_dwarf))
94100
95101 # Add site-specific substitutions.
96 config.substitutions.append( ('%gold', config.gold_executable) )
97 config.substitutions.append( ('%go', config.go_executable) )
98 config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
99 config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
100 config.substitutions.append( ('%exeext', config.llvm_exe_ext) )
101 config.substitutions.append( ('%python', config.python_executable) )
102 config.substitutions.append( ('%host_cc', config.host_cc) )
102 config.substitutions.append(('%gold', config.gold_executable))
103 config.substitutions.append(('%go', config.go_executable))
104 config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir))
105 config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
106 config.substitutions.append(('%exeext', config.llvm_exe_ext))
107 config.substitutions.append(('%python', config.python_executable))
108 config.substitutions.append(('%host_cc', config.host_cc))
103109
104110 # Provide the path to asan runtime lib if available. On darwin, this lib needs
105111 # to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
107113 ld64_cmd = config.ld64_executable
108114 asan_rtlib = get_asan_rtlib()
109115 if asan_rtlib:
110 ld64_cmd = "DYLD_INSERT_LIBRARIES={} {}".format(asan_rtlib, ld64_cmd)
111 config.substitutions.append( ('%ld64', ld64_cmd) )
116 ld64_cmd = 'DYLD_INSERT_LIBRARIES={} {}'.format(asan_rtlib, ld64_cmd)
117 config.substitutions.append(('%ld64', ld64_cmd))
112118
113119 # OCaml substitutions.
114120 # Support tests for both native and bytecode builds.
115 config.substitutions.append( ('%ocamlc',
116 "%s ocamlc -cclib -L%s %s" %
117 (config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags)) )
121 config.substitutions.append(('%ocamlc',
122 '%s ocamlc -cclib -L%s %s' %
123 (config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags)))
118124 if config.have_ocamlopt:
119 config.substitutions.append( ('%ocamlopt',
120 "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
121 (config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)) )
125 config.substitutions.append(('%ocamlopt',
126 '%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s' %
127 (config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)))
122128 else:
123 config.substitutions.append( ('%ocamlopt', "true" ) )
129 config.substitutions.append(('%ocamlopt', 'true'))
124130
125131 # For each occurrence of an llvm tool name as its own word, replace it
126132 # with the full path to the build directory holding that tool. This
168174 llvm_config.add_tool_substitutions(optional_tools, config.llvm_tools_dir,
169175 warn_missing=False)
170176
171 ### Targets
177 # Targets
172178
173179 config.targets = frozenset(config.targets_to_build.split())
174180
175181 for arch in config.targets_to_build.split():
176182 config.available_features.add(arch.lower() + '-registered-target')
177183
178 ### Features
184 # Features
179185
180186 # Others/can-execute.txt
181187 if sys.platform not in ['win32']:
194200
195201 # Static libraries are not built if BUILD_SHARED_LIBS is ON.
196202 if not config.build_shared_libs:
197 config.available_features.add("static-libs")
203 config.available_features.add('static-libs')
198204
199205 # Direct object generation
200206 if not 'hexagon' in config.target_triple:
201 config.available_features.add("object-emission")
207 config.available_features.add('object-emission')
202208
203209 # LLVM can be configured with an empty default triple
204210 # Some tests are "generic" and require a valid default triple
205211 if config.target_triple:
206 config.available_features.add("default_triple")
212 config.available_features.add('default_triple')
207213
208214 import subprocess
215
209216
210217 def have_ld_plugin_support():
211218 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
212219 return False
213220
214 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'})
221 ld_cmd = subprocess.Popen(
222 [config.gold_executable, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
215223 ld_out = ld_cmd.stdout.read().decode()
216224 ld_cmd.wait()
217225
232240 if 'elf32ppc' in emulations:
233241 config.available_features.add('ld_emu_elf32ppc')
234242
235 ld_version = subprocess.Popen([config.gold_executable, '--version'], stdout = subprocess.PIPE, env={'LANG': 'C'})
243 ld_version = subprocess.Popen(
244 [config.gold_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
236245 if not 'GNU gold' in ld_version.stdout.read().decode():
237246 return False
238247 ld_version.wait()
239248
240249 return True
250
241251
242252 if have_ld_plugin_support():
243253 config.available_features.add('ld_plugin')
244254
255
245256 def have_ld64_plugin_support():
246257 if not config.llvm_tool_lto_build or config.ld64_executable == '':
247258 return False
248259
249 ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)
260 ld_cmd = subprocess.Popen(
261 [config.ld64_executable, '-v'], stderr=subprocess.PIPE)
250262 ld_out = ld_cmd.stderr.read().decode()
251263 ld_cmd.wait()
252264
255267
256268 return True
257269
270
258271 if have_ld64_plugin_support():
259272 config.available_features.add('ld64_plugin')
260273
261274 # Ask llvm-config about asserts and global-isel.
262275 llvm_config.feature_config(
263 [('--assertion-mode', {'ON' : 'asserts'}),
264 ('--has-global-isel', {'ON' : 'global-isel'})])
276 [('--assertion-mode', {'ON': 'asserts'}),
277 ('--has-global-isel', {'ON': 'global-isel'})])
265278
266279 if 'darwin' == sys.platform:
267280 try:
268281 sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
269 stdout = subprocess.PIPE)
282 stdout=subprocess.PIPE)
270283 except OSError:
271 print("Could not exec sysctl")
284 print('Could not exec sysctl')
272285 result = sysctl_cmd.stdout.read().decode('ascii')
273 if -1 != result.find("hw.optional.fma: 1"):
286 if -1 != result.find('hw.optional.fma: 1'):
274287 config.available_features.add('fma3')
275288 sysctl_cmd.wait()
276289
281294 if config.have_libxar:
282295 config.available_features.add('xar')
283296
284 if config.llvm_libxml2_enabled == "1":
297 if config.llvm_libxml2_enabled == '1':
285298 config.available_features.add('libxml2')
55
66 import lit.util
77
8
89 def binary_feature(on, feature, off_prefix):
910 return feature if on else off_prefix + feature
11
1012
1113 class LLVMConfig(object):
1214
2426
2527 # Seek sane tools in directories and set to $PATH.
2628 path = self.lit_config.getToolsPath(config.lit_tools_dir,
27 config.environment['PATH'],
28 ['cmp.exe', 'grep.exe', 'sed.exe'])
29 config.environment['PATH'],
30 ['cmp.exe', 'grep.exe', 'sed.exe'])
2931 if path is not None:
3032 self.with_environment('PATH', path, append_path=True)
3133 self.use_lit_shell = True
3234
3335 # Choose between lit's internal shell pipeline runner and a real shell. If
3436 # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
35 lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
37 lit_shell_env = os.environ.get('LIT_USE_INTERNAL_SHELL')
3638 if lit_shell_env:
3739 self.use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
3840
3941 if not self.use_lit_shell:
4042 features.add('shell')
41
4243
4344 # Running on Darwin OS
4445 if platform.system() in ['Darwin']:
5657 host_triple = getattr(config, 'host_triple', None)
5758 target_triple = getattr(config, 'target_triple', None)
5859 if host_triple and host_triple == target_triple:
59 features.add("native")
60 features.add('native')
6061
6162 # Sanitizers.
6263 sanitizers = getattr(config, 'llvm_use_sanitizer', '')
6364 sanitizers = frozenset(x.lower() for x in sanitizers.split(';'))
6465 features.add(binary_feature('address' in sanitizers, 'asan', 'not_'))
6566 features.add(binary_feature('memory' in sanitizers, 'msan', 'not_'))
66 features.add(binary_feature('undefined' in sanitizers, 'ubsan', 'not_'))
67 features.add(binary_feature(
68 'undefined' in sanitizers, 'ubsan', 'not_'))
6769
6870 have_zlib = getattr(config, 'have_zlib', None)
6971 features.add(binary_feature(have_zlib, 'zlib', 'no'))
7072
7173 # Check if we should run long running tests.
72 long_tests = lit_config.params.get("run_long_tests", None)
74 long_tests = lit_config.params.get('run_long_tests', None)
7375 if lit.util.pythonize_bool(long_tests):
74 features.add("long_tests")
76 features.add('long_tests')
7577
7678 if target_triple:
7779 if re.match(r'^x86_64.*-apple', target_triple):
7880 if 'address' in sanitizers:
79 self.with_environment('ASAN_OPTIONS', 'detect_leaks=1', append_path=True)
81 self.with_environment(
82 'ASAN_OPTIONS', 'detect_leaks=1', append_path=True)
8083 if re.match(r'^x86_64.*-linux', target_triple):
81 features.add("x86_64-linux")
84 features.add('x86_64-linux')
8285 if re.match(r'.*-win32$', target_triple):
8386 features.add('target-windows')
8487
8992 gmalloc_path_str = lit_config.params.get('gmalloc_path',
9093 '/usr/lib/libgmalloc.dylib')
9194 if gmalloc_path_str is not None:
92 self.with_environment('DYLD_INSERT_LIBRARIES', gmalloc_path_str)
95 self.with_environment(
96 'DYLD_INSERT_LIBRARIES', gmalloc_path_str)
9397
9498 breaking_checks = getattr(config, 'enable_abi_breaking_checks', None)
9599 if lit.util.pythonize_bool(breaking_checks):
96100 features.add('abi-breaking-checks')
97101
98 def with_environment(self, variable, value, append_path = False):
102 def with_environment(self, variable, value, append_path=False):
99103 if append_path:
100104 # For paths, we should be able to take a list of them and process all
101105 # of them.
128132 value = os.pathsep.join(paths)
129133 self.config.environment[variable] = value
130134
131
132 def with_system_environment(self, variables, append_path = False):
135 def with_system_environment(self, variables, append_path=False):
133136 if lit.util.is_string(variables):
134137 variables = [variables]
135138 for v in variables:
152155 stderr = lit.util.to_string(stderr)
153156 return (stdout, stderr)
154157 except OSError:
155 self.lit_config.fatal("Could not run process %s" % command)
158 self.lit_config.fatal('Could not run process %s' % command)
156159
157160 def feature_config(self, features):
158161 # Ask llvm-config about the specified feature.
174177 if re.search(re_pattern, feature_line):
175178 self.config.available_features.add(feature)
176179
177
178180 # Note that when substituting %clang_cc1 also fill in the include directory of
179181 # the builtin headers. Those are part of even a freestanding environment, but
180182 # Clang relies on the driver to locate them.
181183 def get_clang_builtin_include_dir(self, clang):
182184 # FIXME: Rather than just getting the version, we should have clang print
183185 # out its resource dir here in an easy to scrape form.
184 clang_dir, _ = self.get_process_output([clang, '-print-file-name=include'])
186 clang_dir, _ = self.get_process_output(
187 [clang, '-print-file-name=include'])
185188
186189 if not clang_dir:
187 self.lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang)
190 self.lit_config.fatal(
191 "Couldn't find the include dir for Clang ('%s')" % clang)
188192
189193 clang_dir = clang_dir.strip()
190194 if sys.platform in ['win32'] and not self.use_lit_shell:
196200 def make_itanium_abi_triple(self, triple):
197201 m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
198202 if not m:
199 self.lit_config.fatal("Could not turn '%s' into Itanium ABI triple" % triple)
203 self.lit_config.fatal(
204 "Could not turn '%s' into Itanium ABI triple" % triple)
200205 if m.group(3).lower() != 'win32':
201 # All non-win32 triples use the Itanium ABI.
202 return triple
206 # All non-win32 triples use the Itanium ABI.
207 return triple
203208 return m.group(1) + '-' + m.group(2) + '-mingw32'
204209
205210 def make_msabi_triple(self, triple):
206211 m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
207212 if not m:
208 self.lit_config.fatal("Could not turn '%s' into MS ABI triple" % triple)
213 self.lit_config.fatal(
214 "Could not turn '%s' into MS ABI triple" % triple)
209215 isa = m.group(1).lower()
210216 vendor = m.group(2).lower()
211217 os = m.group(3).lower()
212218 if os == 'win32':
213 # If the OS is win32, we're done.
214 return triple
219 # If the OS is win32, we're done.
220 return triple
215221 if isa.startswith('x86') or isa == 'amd64' or re.match(r'i\d86', isa):
216 # For x86 ISAs, adjust the OS.
217 return isa + '-' + vendor + '-win32'
222 # For x86 ISAs, adjust the OS.
223 return isa + '-' + vendor + '-win32'
218224 # -win32 is not supported for non-x86 targets; use a default.
219225 return 'i686-pc-win32'
220226
221 def add_tool_substitutions(self, tools, search_dirs, warn_missing = True):
227 def add_tool_substitutions(self, tools, search_dirs, warn_missing=True):
222228 if lit.util.is_string(search_dirs):
223229 search_dirs = [search_dirs]
224230
244250 if not tool_path:
245251 if warn_missing:
246252 # Warn, but still provide a substitution.
247 self.lit_config.note('Did not find ' + tool_name + ' in %s' % search_dirs)
253 self.lit_config.note(
254 'Did not find ' + tool_name + ' in %s' % search_dirs)
248255 tool_path = self.config.llvm_tools_dir + '/' + tool_name
249256
250257 if tool_name == 'llc' and os.environ.get('LLVM_ENABLE_MACHINE_VERIFIER') == '1':
252259 if tool_name == 'llvm-go':
253260 exe = getattr(self.config, 'go_executable', None)
254261 if exe:
255 tool_path += " go=" + exe
262 tool_path += ' go=' + exe
256263
257264 self.config.substitutions.append((tool, tool_pipe + tool_path))
88 import sys
99 import threading
1010
11
1112 def norm_path(path):
1213 path = os.path.realpath(path)
1314 path = os.path.normpath(path)
1415 path = os.path.normcase(path)
1516 return path
17
1618
1719 def is_string(value):
1820 try:
2022 return isinstance(value, basestring)
2123 except NameError:
2224 return isinstance(value, str)
25
2326
2427 def pythonize_bool(value):
2528 if value is None:
3538 return False
3639 raise ValueError('"{}" is not a valid boolean'.format(value))
3740
41
3842 def make_word_regex(word):
3943 return r'\b' + word + r'\b'
4044
45
4146 def to_bytes(s):
4247 """Return the parameter as type 'bytes', possibly encoding it.
4348
44 In Python2, the 'bytes' type is the same as 'str'. In Python3, they are
45 distinct.
49 In Python2, the 'bytes' type is the same as 'str'. In Python3, they
50 are distinct.
51
4652 """
4753 if isinstance(s, bytes):
4854 # In Python2, this branch is taken for both 'str' and 'bytes'.
5359 # Encode to UTF-8 to get 'bytes' data.
5460 return s.encode('utf-8')
5561
62
5663 def to_string(b):
5764 """Return the parameter as type 'str', possibly encoding it.
5865
5966 In Python2, the 'str' type is the same as 'bytes'. In Python3, the
6067 'str' type is (essentially) Python2's 'unicode' type, and 'bytes' is
6168 distinct.
69
6270 """
6371 if isinstance(b, str):
6472 # In Python2, this branch is taken for types 'str' and 'bytes'.
9098 except AttributeError:
9199 raise TypeError('not sure how to convert %s to %s' % (type(b), str))
92100
101
93102 def detectCPUs():
94 """
95 Detects the number of CPUs on a system. Cribbed from pp.
103 """Detects the number of CPUs on a system.
104
105 Cribbed from pp.
106
96107 """
97108 # Linux, Unix and MacOS:
98 if hasattr(os, "sysconf"):
99 if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
109 if hasattr(os, 'sysconf'):
110 if 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
100111 # Linux & Unix:
101 ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
112 ncpus = os.sysconf('SC_NPROCESSORS_ONLN')
102113 if isinstance(ncpus, int) and ncpus > 0:
103114 return ncpus
104 else: # OSX:
115 else: # OSX:
105116 return int(subprocess.check_output(['sysctl', '-n', 'hw.ncpu'],
106117 stderr=subprocess.STDOUT))
107118 # Windows:
108 if "NUMBER_OF_PROCESSORS" in os.environ:
109 ncpus = int(os.environ["NUMBER_OF_PROCESSORS"])
119 if 'NUMBER_OF_PROCESSORS' in os.environ:
120 ncpus = int(os.environ['NUMBER_OF_PROCESSORS'])
110121 if ncpus > 0:
111122 # With more than 32 processes, process creation often fails with
112123 # "Too many open files". FIXME: Check if there's a better fix.
113124 return min(ncpus, 32)
114 return 1 # Default
125 return 1 # Default
126
115127
116128 def mkdir_p(path):
117129 """mkdir_p(path) - Make the "path" directory, if it does not exist; this
131143 if e.errno != errno.EEXIST:
132144 raise
133145
146
134147 def listdir_files(dirname, suffixes=None, exclude_filenames=None):
135148 """Yields files in a directory.
136149
157170
158171 Yields:
159172 Filenames as returned by os.listdir (generally, str).
173
160174 """
161175 if exclude_filenames is None:
162176 exclude_filenames = set()
166180 if (os.path.isdir(os.path.join(dirname, filename)) or
167181 filename.startswith('.') or
168182 filename in exclude_filenames or
169 not any(filename.endswith(sfx) for sfx in suffixes)):
183 not any(filename.endswith(sfx) for sfx in suffixes)):
170184 continue
171185 yield filename
172186
173 def which(command, paths = None):
187
188 def which(command, paths=None):
174189 """which(command, [paths]) - Look up the given command in the paths string
175190 (or the PATH environment variable, if unspecified)."""
176191
177192 if paths is None:
178 paths = os.environ.get('PATH','')
193 paths = os.environ.get('PATH', '')
179194
180195 # Check for absolute match first.
181196 if os.path.isfile(command):
201216
202217 return None
203218
219
204220 def checkToolsPath(dir, tools):
205221 for tool in tools:
206222 if not os.path.exists(os.path.join(dir, tool)):
207223 return False
208224 return True
209225
226
210227 def whichTools(tools, paths):
211228 for path in paths.split(os.pathsep):
212229 if checkToolsPath(path, tools):
213230 return path
214231 return None
215232
216 def printHistogram(items, title = 'Items'):
217 items.sort(key = lambda item: item[1])
218
219 maxValue = max([v for _,v in items])
233
234 def printHistogram(items, title='Items'):
235 items.sort(key=lambda item: item[1])
236
237 maxValue = max([v for _, v in items])
220238
221239 # Select first "nice" bar height that produces more than 10 bars.
222240 power = int(math.ceil(math.log(maxValue, 10)))
229247 power -= 1
230248
231249 histo = [set() for i in range(N)]
232 for name,v in items:
233 bin = min(int(N * v/maxValue), N-1)
250 for name, v in items:
251 bin = min(int(N * v / maxValue), N - 1)
234252 histo[bin].add(name)
235253
236254 barW = 40
237255 hr = '-' * (barW + 34)
238256 print('\nSlowest %s:' % title)
239257 print(hr)
240 for name,value in items[-20:]:
258 for name, value in items[-20:]:
241259 print('%.2fs: %s' % (value, name))
242260 print('\n%s Times:' % title)
243261 print(hr)
244262 pDigits = int(math.ceil(math.log(maxValue, 10)))
245 pfDigits = max(0, 3-pDigits)
263 pfDigits = max(0, 3 - pDigits)
246264 if pfDigits:
247265 pDigits += pfDigits + 1
248266 cDigits = int(math.ceil(math.log(len(items), 10)))
249 print("[%s] :: [%s] :: [%s]" % ('Range'.center((pDigits+1)*2 + 3),
267 print('[%s] :: [%s] :: [%s]' % ('Range'.center((pDigits + 1) * 2 + 3),
250268 'Percentage'.center(barW),
251 'Count'.center(cDigits*2 + 1)))
269 'Count'.center(cDigits * 2 + 1)))
252270 print(hr)
253 for i,row in enumerate(histo):
271 for i, row in enumerate(histo):
254272 pct = float(len(row)) / len(items)
255273 w = int(barW * pct)
256 print("[%*.*fs,%*.*fs) :: [%s%s] :: [%*d/%*d]" % (
257 pDigits, pfDigits, i*barH, pDigits, pfDigits, (i+1)*barH,
258 '*'*w, ' '*(barW-w), cDigits, len(row), cDigits, len(items)))
274 print('[%*.*fs,%*.*fs) :: [%s%s] :: [%*d/%*d]' % (
275 pDigits, pfDigits, i * barH, pDigits, pfDigits, (i + 1) * barH,
276 '*' * w, ' ' * (barW - w), cDigits, len(row), cDigits, len(items)))
277
259278
260279 class ExecuteCommandTimeoutException(Exception):
261280 def __init__(self, msg, out, err, exitCode):
268287 self.err = err
269288 self.exitCode = exitCode
270289
290
271291 # Close extra file handles on UNIX (on Windows this cannot be done while
272292 # also redirecting input).
273293 kUseCloseFDs = not (platform.system() == 'Windows')
294
295
274296 def executeCommand(command, cwd=None, env=None, input=None, timeout=0):
275 """
276 Execute command ``command`` (list of arguments or string)
277 with
278 * working directory ``cwd`` (str), use None to use the current
279 working directory
280 * environment ``env`` (dict), use None for none
281 * Input to the command ``input`` (str), use string to pass
282 no input.
283 * Max execution time ``timeout`` (int) seconds. Use 0 for no timeout.
284
285 Returns a tuple (out, err, exitCode) where
286 * ``out`` (str) is the standard output of running the command
287 * ``err`` (str) is the standard error of running the command
288 * ``exitCode`` (int) is the exitCode of running the command
289
290 If the timeout is hit an ``ExecuteCommandTimeoutException``
291 is raised.
297 """Execute command ``command`` (list of arguments or string) with.
298
299 * working directory ``cwd`` (str), use None to use the current
300 working directory
301 * environment ``env`` (dict), use None for none
302 * Input to the command ``input`` (str), use string to pass
303 no input.
304 * Max execution time ``timeout`` (int) seconds. Use 0 for no timeout.
305
306 Returns a tuple (out, err, exitCode) where
307 * ``out`` (str) is the standard output of running the command
308 * ``err`` (str) is the standard error of running the command
309 * ``exitCode`` (int) is the exitCode of running the command
310
311 If the timeout is hit an ``ExecuteCommandTimeoutException``
312 is raised.
313
292314 """
293315 if input is not None:
294316 input = to_bytes(input)
314336 timerObject = threading.Timer(timeout, killProcess)
315337 timerObject.start()
316338
317 out,err = p.communicate(input=input)
339 out, err = p.communicate(input=input)
318340 exitCode = p.wait()
319341 finally:
320342 if timerObject != None:
330352 out=out,
331353 err=err,
332354 exitCode=exitCode
333 )
355 )
334356
335357 # Detect Ctrl-C in subprocess.
336358 if exitCode == -signal.SIGINT:
337359 raise KeyboardInterrupt
338360
339361 return out, err, exitCode
362
340363
341364 def usePlatformSdkOnDarwin(config, lit_config):
342365 # On Darwin, support relocatable SDKs by providing Clang with a
355378 lit_config.note('using SDKROOT: %r' % sdk_path)
356379 config.environment['SDKROOT'] = sdk_path
357380
381
358382 def findPlatformSdkVersionOnMacOS(config, lit_config):
359383 if 'darwin' in config.target_triple:
360384 try:
369393 return out
370394 return None
371395
396
372397 def killProcessAndChildren(pid):
373 """
374 This function kills a process with ``pid`` and all its
375 running children (recursively). It is currently implemented
376 using the psutil module which provides a simple platform
377 neutral implementation.
378
379 TODO: Reimplement this without using psutil so we can
380 remove our dependency on it.
398 """This function kills a process with ``pid`` and all its running children
399 (recursively). It is currently implemented using the psutil module which
400 provides a simple platform neutral implementation.
401
402 TODO: Reimplement this without using psutil so we can remove
403 our dependency on it.
404
381405 """
382406 import psutil
383407 try: