diff options
Diffstat (limited to 'Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10')
-rwxr-xr-x | Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10 | 387 |
1 files changed, 0 insertions, 387 deletions
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10 deleted file mode 100755 index 460a5358..00000000 --- a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10 +++ /dev/null | |||
@@ -1,387 +0,0 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | # This script must retain compatibility with a wide variety of Python versions | ||
4 | # since it is run for every py_binary target. Currently we guarantee support | ||
5 | # going back to Python 2.7, and try to support even Python 2.6 on a best-effort | ||
6 | # basis. We might abandon 2.6 support once users have the ability to control the | ||
7 | # above shebang string via the Python toolchain (#8685). | ||
8 | |||
9 | from __future__ import absolute_import | ||
10 | from __future__ import division | ||
11 | from __future__ import print_function | ||
12 | |||
13 | import sys | ||
14 | |||
15 | # The Python interpreter unconditionally prepends the directory containing this | ||
16 | # script (following symlinks) to the import path. This is the cause of #9239, | ||
17 | # and is a special case of #7091. We therefore explicitly delete that entry. | ||
18 | # TODO(#7091): Remove this hack when no longer necessary. | ||
19 | del sys.path[0] | ||
20 | |||
21 | import os | ||
22 | import re | ||
23 | import shutil | ||
24 | import subprocess | ||
25 | import sysconfig | ||
26 | import tempfile | ||
27 | import zipfile | ||
28 | |||
29 | # Return True if running on Windows | ||
30 | def IsWindows(): | ||
31 | return os.name == 'nt' | ||
32 | |||
33 | def GetWindowsPathWithUNCPrefix(path): | ||
34 | """Adds UNC prefix after getting a normalized absolute Windows path. | ||
35 | |||
36 | No-op for non-Windows platforms or if running under python2. | ||
37 | """ | ||
38 | path = path.strip() | ||
39 | |||
40 | # No need to add prefix for non-Windows platforms. | ||
41 | # And \\?\ doesn't work in python 2 or on mingw | ||
42 | if not IsWindows() or sys.version_info[0] < 3 or sysconfig.get_platform() == 'mingw': | ||
43 | return path | ||
44 | |||
45 | # Lets start the unicode fun | ||
46 | unicode_prefix = '\\\\?\\' | ||
47 | if path.startswith(unicode_prefix): | ||
48 | return path | ||
49 | |||
50 | # os.path.abspath returns a normalized absolute path | ||
51 | return unicode_prefix + os.path.abspath(path) | ||
52 | |||
53 | def HasWindowsExecutableExtension(path): | ||
54 | return path.endswith('.exe') or path.endswith('.com') or path.endswith('.bat') | ||
55 | |||
56 | PYTHON_BINARY = '/usr/bin/python3' | ||
57 | if IsWindows() and not HasWindowsExecutableExtension(PYTHON_BINARY): | ||
58 | PYTHON_BINARY = PYTHON_BINARY + '.exe' | ||
59 | |||
60 | def SearchPath(name): | ||
61 | """Finds a file in a given search path.""" | ||
62 | search_path = os.getenv('PATH', os.defpath).split(os.pathsep) | ||
63 | for directory in search_path: | ||
64 | if directory: | ||
65 | path = os.path.join(directory, name) | ||
66 | if os.path.isfile(path) and os.access(path, os.X_OK): | ||
67 | return path | ||
68 | return None | ||
69 | |||
70 | def IsRunningFromZip(): | ||
71 | return False | ||
72 | |||
73 | def FindPythonBinary(module_space): | ||
74 | """Finds the real Python binary if it's not a normal absolute path.""" | ||
75 | if PYTHON_BINARY.startswith('//'): | ||
76 | # Case 1: Path is a label. Not supported yet. | ||
77 | raise AssertionError( | ||
78 | 'Bazel does not support execution of Python interpreters via labels yet') | ||
79 | elif os.path.isabs(PYTHON_BINARY): | ||
80 | # Case 2: Absolute path. | ||
81 | return PYTHON_BINARY | ||
82 | # Use normpath() to convert slashes to os.sep on Windows. | ||
83 | elif os.sep in os.path.normpath(PYTHON_BINARY): | ||
84 | # Case 3: Path is relative to the repo root. | ||
85 | return os.path.join(module_space, PYTHON_BINARY) | ||
86 | else: | ||
87 | # Case 4: Path has to be looked up in the search path. | ||
88 | return SearchPath(PYTHON_BINARY) | ||
89 | |||
90 | def CreatePythonPathEntries(python_imports, module_space): | ||
91 | parts = python_imports.split(':') | ||
92 | return [module_space] + ['%s/%s' % (module_space, path) for path in parts] | ||
93 | |||
94 | def FindModuleSpace(): | ||
95 | """Finds the runfiles tree.""" | ||
96 | stub_filename = sys.argv[0] | ||
97 | if not os.path.isabs(stub_filename): | ||
98 | stub_filename = os.path.join(os.getcwd(), stub_filename) | ||
99 | |||
100 | while True: | ||
101 | module_space = stub_filename + ('.exe' if IsWindows() else '') + '.runfiles' | ||
102 | if os.path.isdir(module_space): | ||
103 | return module_space | ||
104 | |||
105 | runfiles_pattern = r'(.*\.runfiles)' + (r'\\' if IsWindows() else '/') + '.*' | ||
106 | matchobj = re.match(runfiles_pattern, stub_filename) | ||
107 | if matchobj: | ||
108 | return matchobj.group(1) | ||
109 | |||
110 | if not os.path.islink(stub_filename): | ||
111 | break | ||
112 | target = os.readlink(stub_filename) | ||
113 | if os.path.isabs(target): | ||
114 | stub_filename = target | ||
115 | else: | ||
116 | stub_filename = os.path.join(os.path.dirname(stub_filename), target) | ||
117 | |||
118 | raise AssertionError('Cannot find .runfiles directory for %s' % sys.argv[0]) | ||
119 | |||
120 | def ExtractZip(zip_path, dest_dir): | ||
121 | """Extracts the contents of a zip file, preserving the unix file mode bits. | ||
122 | |||
123 | These include the permission bits, and in particular, the executable bit. | ||
124 | |||
125 | Ideally the zipfile module should set these bits, but it doesn't. See: | ||
126 | https://bugs.python.org/issue15795. | ||
127 | |||
128 | Args: | ||
129 | zip_path: The path to the zip file to extract | ||
130 | dest_dir: The path to the destination directory | ||
131 | """ | ||
132 | zip_path = GetWindowsPathWithUNCPrefix(zip_path) | ||
133 | dest_dir = GetWindowsPathWithUNCPrefix(dest_dir) | ||
134 | with zipfile.ZipFile(zip_path) as zf: | ||
135 | for info in zf.infolist(): | ||
136 | zf.extract(info, dest_dir) | ||
137 | # UNC-prefixed paths must be absolute/normalized. See | ||
138 | # https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#maximum-path-length-limitation | ||
139 | file_path = os.path.abspath(os.path.join(dest_dir, info.filename)) | ||
140 | # The Unix st_mode bits (see "man 7 inode") are stored in the upper 16 | ||
141 | # bits of external_attr. Of those, we set the lower 12 bits, which are the | ||
142 | # file mode bits (since the file type bits can't be set by chmod anyway). | ||
143 | attrs = info.external_attr >> 16 | ||
144 | if attrs != 0: # Rumor has it these can be 0 for zips created on Windows. | ||
145 | os.chmod(file_path, attrs & 0o7777) | ||
146 | |||
147 | # Create the runfiles tree by extracting the zip file | ||
148 | def CreateModuleSpace(): | ||
149 | temp_dir = tempfile.mkdtemp('', 'Bazel.runfiles_') | ||
150 | ExtractZip(os.path.dirname(__file__), temp_dir) | ||
151 | return os.path.join(temp_dir, 'runfiles') | ||
152 | |||
153 | # Returns repository roots to add to the import path. | ||
154 | def GetRepositoriesImports(module_space, import_all): | ||
155 | if import_all: | ||
156 | repo_dirs = [os.path.join(module_space, d) for d in os.listdir(module_space)] | ||
157 | return [d for d in repo_dirs if os.path.isdir(d)] | ||
158 | return [os.path.join(module_space, 'dreal')] | ||
159 | |||
160 | def RunfilesEnvvar(module_space): | ||
161 | """Finds the runfiles manifest or the runfiles directory.""" | ||
162 | # If this binary is the data-dependency of another one, the other sets | ||
163 | # RUNFILES_MANIFEST_FILE or RUNFILES_DIR for our sake. | ||
164 | runfiles = os.environ.get('RUNFILES_MANIFEST_FILE', None) | ||
165 | if runfiles: | ||
166 | return ('RUNFILES_MANIFEST_FILE', runfiles) | ||
167 | |||
168 | runfiles = os.environ.get('RUNFILES_DIR', None) | ||
169 | if runfiles: | ||
170 | return ('RUNFILES_DIR', runfiles) | ||
171 | |||
172 | # If running from a zip, there's no manifest file. | ||
173 | if IsRunningFromZip(): | ||
174 | return ('RUNFILES_DIR', module_space) | ||
175 | |||
176 | # Look for the runfiles "output" manifest, argv[0] + ".runfiles_manifest" | ||
177 | runfiles = module_space + '_manifest' | ||
178 | if os.path.exists(runfiles): | ||
179 | return ('RUNFILES_MANIFEST_FILE', runfiles) | ||
180 | |||
181 | # Look for the runfiles "input" manifest, argv[0] + ".runfiles/MANIFEST" | ||
182 | runfiles = os.path.join(module_space, 'MANIFEST') | ||
183 | if os.path.exists(runfiles): | ||
184 | return ('RUNFILES_DIR', runfiles) | ||
185 | |||
186 | # If running in a sandbox and no environment variables are set, then | ||
187 | # Look for the runfiles next to the binary. | ||
188 | if module_space.endswith('.runfiles') and os.path.isdir(module_space): | ||
189 | return ('RUNFILES_DIR', module_space) | ||
190 | |||
191 | return (None, None) | ||
192 | |||
193 | # TODO(#6443): Remove this once there's no longer a host configuration for | ||
194 | # Python targets to appear in. | ||
195 | def MaybeEmitHostVersionWarning(ret_code): | ||
196 | """Warns the user if a failure may be due to the host config's version. | ||
197 | |||
198 | This emits a message to stderr if | ||
199 | 1) ret_code is non-zero, | ||
200 | 2) the target was built in the host config and with toolchains enabled, and | ||
201 | 3) at analysis time we detected a mismatch between the host config's version | ||
202 | and this target's explicitly declared version, or else this target did | ||
203 | not explicitly declare its version. (The former diagnoses targets | ||
204 | affected by #6443, and the latter diagnoses targets that are broken by | ||
205 | fixing #4815.) | ||
206 | |||
207 | See also #7899, #8549, and PyCommon#shouldWarnAboutHostVersionUponFailure. | ||
208 | |||
209 | Since this warning is emitted here in the stub script and not in Bazel itself, | ||
210 | it will be present in all failing runs of affected targets, even when executed | ||
211 | directly and not via `bazel run`. However, note that this warning is never | ||
212 | added to non-host-configured targets, and that it can be disabled by ensuring | ||
213 | the correct Python version is passed to --host_force_python and declared in | ||
214 | tools' python_version attributes. | ||
215 | |||
216 | Args: | ||
217 | ret_code: The exit code of the payload user program | ||
218 | """ | ||
219 | if ret_code == 0: | ||
220 | return | ||
221 | if not False: | ||
222 | return | ||
223 | |||
224 | host_version = "3" | ||
225 | target_version = "3" | ||
226 | opposite_of_host_version = '2' if host_version == '3' else '3' | ||
227 | |||
228 | if False: | ||
229 | # Mismatch with explicitly declared version. | ||
230 | diagnostic = """\ | ||
231 | Note: The failure of target {target} (with exit code {ret_code}) may have been \ | ||
232 | caused by the fact that it is a Python {target_version} program that was built \ | ||
233 | in the host configuration, which uses Python {host_version}. You can change \ | ||
234 | the host configuration (for the entire build) to instead use Python \ | ||
235 | {target_version} by setting --host_force_python=PY{target_version}.\ | ||
236 | """.format( | ||
237 | target='//dreal/test/smt2:hong/hong_10', | ||
238 | ret_code=ret_code, | ||
239 | target_version=target_version, | ||
240 | host_version=host_version) | ||
241 | else: | ||
242 | diagnostic = """\ | ||
243 | Note: The failure of target {target} (with exit code {ret_code}) may have been \ | ||
244 | caused by the fact that it is running under Python {host_version} instead of \ | ||
245 | Python {opposite_of_host_version}. Examine the error to determine if that \ | ||
246 | appears to be the problem. Since this target is built in the host \ | ||
247 | configuration, the only way to change its version is to set \ | ||
248 | --host_force_python=PY{opposite_of_host_version}, which affects the entire \ | ||
249 | build.\ | ||
250 | """.format( | ||
251 | target='//dreal/test/smt2:hong/hong_10', | ||
252 | ret_code=ret_code, | ||
253 | host_version=host_version, | ||
254 | opposite_of_host_version=opposite_of_host_version) | ||
255 | |||
256 | # TODO(brandjon): Change the wording "You are likely seeing this message | ||
257 | # because" to something less strong after a few releases from 0.27. By that | ||
258 | # point, migration for toolchains won't be the main reason this error is seen | ||
259 | # by users. | ||
260 | message = """\ | ||
261 | ---------------- | ||
262 | {diagnostic} | ||
263 | |||
264 | If this error started occurring in Bazel 0.27 and later, it may be because the \ | ||
265 | Python toolchain now enforces that targets analyzed as PY2 and PY3 run under a \ | ||
266 | Python 2 and Python 3 interpreter, respectively. See \ | ||
267 | https://github.com/bazelbuild/bazel/issues/7899 for more information. | ||
268 | ----------------""".format(diagnostic=diagnostic) | ||
269 | print(message, file=sys.stderr) | ||
270 | |||
271 | def Deduplicate(items): | ||
272 | """Efficiently filter out duplicates, keeping the first element only.""" | ||
273 | seen = set() | ||
274 | for it in items: | ||
275 | if it not in seen: | ||
276 | seen.add(it) | ||
277 | yield it | ||
278 | |||
279 | def Main(): | ||
280 | args = sys.argv[1:] | ||
281 | |||
282 | new_env = {} | ||
283 | |||
284 | if IsRunningFromZip(): | ||
285 | module_space = CreateModuleSpace() | ||
286 | else: | ||
287 | module_space = FindModuleSpace() | ||
288 | |||
289 | python_imports = '' | ||
290 | python_path_entries = CreatePythonPathEntries(python_imports, module_space) | ||
291 | python_path_entries += GetRepositoriesImports(module_space, True) | ||
292 | # Remove duplicates to avoid overly long PYTHONPATH (#10977). Preserve order, | ||
293 | # keep first occurrence only. | ||
294 | python_path_entries = [ | ||
295 | GetWindowsPathWithUNCPrefix(d) | ||
296 | for d in Deduplicate(python_path_entries) | ||
297 | ] | ||
298 | |||
299 | old_python_path = os.environ.get('PYTHONPATH') | ||
300 | python_path = os.pathsep.join(python_path_entries) | ||
301 | if old_python_path: | ||
302 | python_path += os.pathsep + old_python_path | ||
303 | |||
304 | if IsWindows(): | ||
305 | python_path = python_path.replace('/', os.sep) | ||
306 | |||
307 | new_env['PYTHONPATH'] = python_path | ||
308 | runfiles_envkey, runfiles_envvalue = RunfilesEnvvar(module_space) | ||
309 | if runfiles_envkey: | ||
310 | new_env[runfiles_envkey] = runfiles_envvalue | ||
311 | |||
312 | # Now look for my main python source file. | ||
313 | # The magic string percent-main-percent is replaced with the filename of the | ||
314 | # main file of the Python binary in BazelPythonSemantics.java. | ||
315 | rel_path = 'dreal/dreal/test/smt2/test.py' | ||
316 | if IsWindows(): | ||
317 | rel_path = rel_path.replace('/', os.sep) | ||
318 | |||
319 | main_filename = os.path.join(module_space, rel_path) | ||
320 | main_filename = GetWindowsPathWithUNCPrefix(main_filename) | ||
321 | assert os.path.exists(main_filename), \ | ||
322 | 'Cannot exec() %r: file not found.' % main_filename | ||
323 | assert os.access(main_filename, os.R_OK), \ | ||
324 | 'Cannot exec() %r: file not readable.' % main_filename | ||
325 | |||
326 | program = python_program = FindPythonBinary(module_space) | ||
327 | if python_program is None: | ||
328 | raise AssertionError('Could not find python binary: ' + PYTHON_BINARY) | ||
329 | |||
330 | cov_tool = os.environ.get('PYTHON_COVERAGE') | ||
331 | if cov_tool: | ||
332 | # Inhibit infinite recursion: | ||
333 | del os.environ['PYTHON_COVERAGE'] | ||
334 | if not os.path.exists(cov_tool): | ||
335 | raise EnvironmentError('Python coverage tool %s not found.' % cov_tool) | ||
336 | args = [python_program, cov_tool, 'run', '-a', '--branch', main_filename] + args | ||
337 | # coverage library expects sys.path[0] to contain the library, and replaces | ||
338 | # it with the directory of the program it starts. Our actual sys.path[0] is | ||
339 | # the runfiles directory, which must not be replaced. | ||
340 | # CoverageScript.do_execute() undoes this sys.path[0] setting. | ||
341 | # | ||
342 | # Update sys.path such that python finds the coverage package. The coverage | ||
343 | # entry point is coverage.coverage_main, so we need to do twice the dirname. | ||
344 | new_env['PYTHONPATH'] = \ | ||
345 | new_env['PYTHONPATH'] + ':' + os.path.dirname(os.path.dirname(cov_tool)) | ||
346 | new_env['PYTHON_LCOV_FILE'] = os.environ.get('COVERAGE_DIR') + '/pylcov.dat' | ||
347 | else: | ||
348 | args = [python_program, main_filename] + args | ||
349 | |||
350 | os.environ.update(new_env) | ||
351 | |||
352 | try: | ||
353 | sys.stdout.flush() | ||
354 | if IsRunningFromZip(): | ||
355 | # If RUN_UNDER_RUNFILES equals 1, it means we need to | ||
356 | # change directory to the right runfiles directory. | ||
357 | # (So that the data files are accessible) | ||
358 | if os.environ.get('RUN_UNDER_RUNFILES') == '1': | ||
359 | os.chdir(os.path.join(module_space, 'dreal')) | ||
360 | ret_code = subprocess.call(args) | ||
361 | shutil.rmtree(os.path.dirname(module_space), True) | ||
362 | MaybeEmitHostVersionWarning(ret_code) | ||
363 | sys.exit(ret_code) | ||
364 | else: | ||
365 | # On Windows, os.execv doesn't handle arguments with spaces correctly, | ||
366 | # and it actually starts a subprocess just like subprocess.call. | ||
367 | # | ||
368 | # If we may need to emit a host config warning after execution, don't | ||
369 | # execv because we need control to return here. This only happens for | ||
370 | # targets built in the host config, so other targets still get to take | ||
371 | # advantage of the performance benefits of execv. | ||
372 | if IsWindows() or False: | ||
373 | ret_code = subprocess.call(args) | ||
374 | MaybeEmitHostVersionWarning(ret_code) | ||
375 | sys.exit(ret_code) | ||
376 | else: | ||
377 | os.execv(args[0], args) | ||
378 | except EnvironmentError: | ||
379 | # This works from Python 2.4 all the way to 3.x. | ||
380 | e = sys.exc_info()[1] | ||
381 | # This exception occurs when os.execv() fails for some reason. | ||
382 | if not getattr(e, 'filename', None): | ||
383 | e.filename = program # Add info to error message | ||
384 | raise | ||
385 | |||
386 | if __name__ == '__main__': | ||
387 | Main() | ||