diff options
author | Aren Babikian <aren.babikian@mail.mcgill.ca> | 2021-02-03 03:16:35 +0100 |
---|---|---|
committer | Aren Babikian <aren.babikian@mail.mcgill.ca> | 2021-02-03 03:16:35 +0100 |
commit | 0cd830021dd76c9e1711ba581dce37577e7835c4 (patch) | |
tree | b4cfe433538374b73f1fd8cdf72eb18675630a79 /Solvers/dreal4/bazel-bin/dreal/test/smt2 | |
parent | add dreal build (diff) | |
download | VIATRA-Generator-0cd830021dd76c9e1711ba581dce37577e7835c4.tar.gz VIATRA-Generator-0cd830021dd76c9e1711ba581dce37577e7835c4.tar.zst VIATRA-Generator-0cd830021dd76c9e1711ba581dce37577e7835c4.zip |
fix previous commit
Diffstat (limited to 'Solvers/dreal4/bazel-bin/dreal/test/smt2')
143 files changed, 5304 insertions, 0 deletions
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02 new file mode 100755 index 00000000..8a17dbd7 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02 | |||
@@ -0,0 +1,387 @@ | |||
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:02', | ||
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:02', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/MANIFEST new file mode 100755 index 00000000..df01094e --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/02 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/02 | ||
5 | dreal/dreal/test/smt2/02.smt2 /home/models/dreal4/dreal/test/smt2/02.smt2 | ||
6 | dreal/dreal/test/smt2/02.smt2.expected /home/models/dreal4/dreal/test/smt2/02.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/02 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/02 new file mode 120000 index 00000000..a88394bc --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/02 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/02 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/02.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/02.smt2 new file mode 120000 index 00000000..55b0399e --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/02.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/02.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/02.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/02.smt2.expected new file mode 120000 index 00000000..5c16c2df --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/02.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/02.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles_manifest new file mode 100755 index 00000000..df01094e --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/02.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/02 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/02 | ||
5 | dreal/dreal/test/smt2/02.smt2 /home/models/dreal4/dreal/test/smt2/02.smt2 | ||
6 | dreal/dreal/test/smt2/02.smt2.expected /home/models/dreal4/dreal/test/smt2/02.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03 new file mode 100755 index 00000000..9e47c959 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03 | |||
@@ -0,0 +1,387 @@ | |||
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:03', | ||
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:03', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/MANIFEST new file mode 100755 index 00000000..68149200 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/03 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/03 | ||
5 | dreal/dreal/test/smt2/03.smt2 /home/models/dreal4/dreal/test/smt2/03.smt2 | ||
6 | dreal/dreal/test/smt2/03.smt2.expected /home/models/dreal4/dreal/test/smt2/03.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/03 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/03 new file mode 120000 index 00000000..b8e138a3 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/03 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/03 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/03.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/03.smt2 new file mode 120000 index 00000000..a948d8cc --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/03.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/03.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/03.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/03.smt2.expected new file mode 120000 index 00000000..76bcb7f1 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/03.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/03.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles_manifest new file mode 100755 index 00000000..68149200 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/03.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/03 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/03 | ||
5 | dreal/dreal/test/smt2/03.smt2 /home/models/dreal4/dreal/test/smt2/03.smt2 | ||
6 | dreal/dreal/test/smt2/03.smt2.expected /home/models/dreal4/dreal/test/smt2/03.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06 new file mode 100755 index 00000000..275a96b5 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06 | |||
@@ -0,0 +1,387 @@ | |||
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:06', | ||
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:06', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/MANIFEST new file mode 100755 index 00000000..b1b85567 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/06 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/06 | ||
5 | dreal/dreal/test/smt2/06.smt2 /home/models/dreal4/dreal/test/smt2/06.smt2 | ||
6 | dreal/dreal/test/smt2/06.smt2.expected /home/models/dreal4/dreal/test/smt2/06.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/06 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/06 new file mode 120000 index 00000000..5b500e07 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/06 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/06 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/06.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/06.smt2 new file mode 120000 index 00000000..339620ea --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/06.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/06.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/06.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/06.smt2.expected new file mode 120000 index 00000000..21624938 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/06.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/06.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles_manifest new file mode 100755 index 00000000..b1b85567 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/06.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/06 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/06 | ||
5 | dreal/dreal/test/smt2/06.smt2 /home/models/dreal4/dreal/test/smt2/06.smt2 | ||
6 | dreal/dreal/test/smt2/06.smt2.expected /home/models/dreal4/dreal/test/smt2/06.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07 new file mode 100755 index 00000000..02cc3691 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07 | |||
@@ -0,0 +1,387 @@ | |||
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:07', | ||
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:07', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/MANIFEST new file mode 100755 index 00000000..05f60c60 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/07 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/07 | ||
5 | dreal/dreal/test/smt2/07.smt2 /home/models/dreal4/dreal/test/smt2/07.smt2 | ||
6 | dreal/dreal/test/smt2/07.smt2.expected /home/models/dreal4/dreal/test/smt2/07.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/07 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/07 new file mode 120000 index 00000000..170a5630 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/07 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/07 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/07.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/07.smt2 new file mode 120000 index 00000000..2d09fd8a --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/07.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/07.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/07.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/07.smt2.expected new file mode 120000 index 00000000..c534c5a7 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/07.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/07.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles_manifest new file mode 100755 index 00000000..05f60c60 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/07.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/07 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/07 | ||
5 | dreal/dreal/test/smt2/07.smt2 /home/models/dreal4/dreal/test/smt2/07.smt2 | ||
6 | dreal/dreal/test/smt2/07.smt2.expected /home/models/dreal4/dreal/test/smt2/07.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18 new file mode 100755 index 00000000..4b7d0b96 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18 | |||
@@ -0,0 +1,387 @@ | |||
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:18', | ||
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:18', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/MANIFEST new file mode 100755 index 00000000..f435fbaf --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/18 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/18 | ||
5 | dreal/dreal/test/smt2/18.smt2 /home/models/dreal4/dreal/test/smt2/18.smt2 | ||
6 | dreal/dreal/test/smt2/18.smt2.expected /home/models/dreal4/dreal/test/smt2/18.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/18 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/18 new file mode 120000 index 00000000..36fa8994 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/18 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/18 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/18.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/18.smt2 new file mode 120000 index 00000000..71ee37ad --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/18.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/18.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/18.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/18.smt2.expected new file mode 120000 index 00000000..72fa7439 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/18.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/18.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles_manifest new file mode 100755 index 00000000..f435fbaf --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/18.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/18 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/18 | ||
5 | dreal/dreal/test/smt2/18.smt2 /home/models/dreal4/dreal/test/smt2/18.smt2 | ||
6 | dreal/dreal/test/smt2/18.smt2.expected /home/models/dreal4/dreal/test/smt2/18.smt2.expected | ||
7 | dreal/dreal/test/smt2/__init__.py | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194 new file mode 100755 index 00000000..4c27324e --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194 | |||
@@ -0,0 +1,387 @@ | |||
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:github_issue_194', | ||
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:github_issue_194', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/MANIFEST new file mode 100755 index 00000000..40a8321d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/github_issue_194 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/github_issue_194 | ||
6 | dreal/dreal/test/smt2/github_issue_194.smt2 /home/models/dreal4/dreal/test/smt2/github_issue_194.smt2 | ||
7 | dreal/dreal/test/smt2/github_issue_194.smt2.expected /home/models/dreal4/dreal/test/smt2/github_issue_194.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/github_issue_194 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/github_issue_194 new file mode 120000 index 00000000..5a9af330 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/github_issue_194 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/github_issue_194 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/github_issue_194.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/github_issue_194.smt2 new file mode 120000 index 00000000..7ee4e542 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/github_issue_194.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/github_issue_194.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/github_issue_194.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/github_issue_194.smt2.expected new file mode 120000 index 00000000..09d948b6 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/github_issue_194.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/github_issue_194.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles_manifest new file mode 100755 index 00000000..40a8321d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/github_issue_194.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/github_issue_194 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/github_issue_194 | ||
6 | dreal/dreal/test/smt2/github_issue_194.smt2 /home/models/dreal4/dreal/test/smt2/github_issue_194.smt2 | ||
7 | dreal/dreal/test/smt2/github_issue_194.smt2.expected /home/models/dreal4/dreal/test/smt2/github_issue_194.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02 new file mode 100755 index 00000000..07f9121b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02 | |||
@@ -0,0 +1,387 @@ | |||
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:hex_02', | ||
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:hex_02', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/MANIFEST new file mode 100755 index 00000000..b97a6881 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hex_02 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hex_02 | ||
6 | dreal/dreal/test/smt2/hex_02.smt2 /home/models/dreal4/dreal/test/smt2/hex_02.smt2 | ||
7 | dreal/dreal/test/smt2/hex_02.smt2.expected /home/models/dreal4/dreal/test/smt2/hex_02.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/hex_02 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/hex_02 new file mode 120000 index 00000000..fab6e2a0 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/hex_02 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hex_02 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/hex_02.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/hex_02.smt2 new file mode 120000 index 00000000..7f081ba6 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/hex_02.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hex_02.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/hex_02.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/hex_02.smt2.expected new file mode 120000 index 00000000..4593fc6d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/hex_02.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hex_02.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles_manifest new file mode 100755 index 00000000..b97a6881 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hex_02.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hex_02 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hex_02 | ||
6 | dreal/dreal/test/smt2/hex_02.smt2 /home/models/dreal4/dreal/test/smt2/hex_02.smt2 | ||
7 | dreal/dreal/test/smt2/hex_02.smt2.expected /home/models/dreal4/dreal/test/smt2/hex_02.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1 new file mode 100755 index 00000000..f4b5cdf3 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1 | |||
@@ -0,0 +1,387 @@ | |||
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_1', | ||
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_1', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/MANIFEST new file mode 100755 index 00000000..721da666 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_1 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_1 | ||
6 | dreal/dreal/test/smt2/hong/hong_1.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_1.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_1.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_1.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/hong/hong_1 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/hong/hong_1 new file mode 120000 index 00000000..9b7e8fa9 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/hong/hong_1 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_1 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/hong/hong_1.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/hong/hong_1.smt2 new file mode 120000 index 00000000..4fe4a025 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/hong/hong_1.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_1.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/hong/hong_1.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/hong/hong_1.smt2.expected new file mode 120000 index 00000000..00311ead --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/hong/hong_1.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_1.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles_manifest new file mode 100755 index 00000000..721da666 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_1.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_1 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_1 | ||
6 | dreal/dreal/test/smt2/hong/hong_1.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_1.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_1.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_1.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10 new file mode 100755 index 00000000..460a5358 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10 | |||
@@ -0,0 +1,387 @@ | |||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/MANIFEST new file mode 100755 index 00000000..3fa993fb --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_10 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_10 | ||
6 | dreal/dreal/test/smt2/hong/hong_10.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_10.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_10.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_10.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/hong/hong_10 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/hong/hong_10 new file mode 120000 index 00000000..5eebdb78 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/hong/hong_10 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_10 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/hong/hong_10.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/hong/hong_10.smt2 new file mode 120000 index 00000000..838dfc9d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/hong/hong_10.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_10.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/hong/hong_10.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/hong/hong_10.smt2.expected new file mode 120000 index 00000000..112e3a0b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/hong/hong_10.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_10.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles_manifest new file mode 100755 index 00000000..3fa993fb --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_10.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_10 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_10 | ||
6 | dreal/dreal/test/smt2/hong/hong_10.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_10.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_10.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_10.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11 new file mode 100755 index 00000000..e017367a --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11 | |||
@@ -0,0 +1,387 @@ | |||
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_11', | ||
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_11', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/MANIFEST new file mode 100755 index 00000000..9c959527 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_11 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_11 | ||
6 | dreal/dreal/test/smt2/hong/hong_11.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_11.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_11.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_11.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/hong/hong_11 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/hong/hong_11 new file mode 120000 index 00000000..5a4fc34d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/hong/hong_11 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_11 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/hong/hong_11.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/hong/hong_11.smt2 new file mode 120000 index 00000000..af629f5d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/hong/hong_11.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_11.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/hong/hong_11.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/hong/hong_11.smt2.expected new file mode 120000 index 00000000..a3b86584 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/hong/hong_11.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_11.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles_manifest new file mode 100755 index 00000000..9c959527 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_11.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_11 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_11 | ||
6 | dreal/dreal/test/smt2/hong/hong_11.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_11.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_11.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_11.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12 new file mode 100755 index 00000000..722c2fba --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12 | |||
@@ -0,0 +1,387 @@ | |||
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_12', | ||
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_12', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/MANIFEST new file mode 100755 index 00000000..d46d56ec --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_12 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_12 | ||
6 | dreal/dreal/test/smt2/hong/hong_12.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_12.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_12.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_12.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/hong/hong_12 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/hong/hong_12 new file mode 120000 index 00000000..d5c886d7 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/hong/hong_12 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_12 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/hong/hong_12.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/hong/hong_12.smt2 new file mode 120000 index 00000000..209dce00 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/hong/hong_12.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_12.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/hong/hong_12.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/hong/hong_12.smt2.expected new file mode 120000 index 00000000..772e3753 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/hong/hong_12.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_12.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles_manifest new file mode 100755 index 00000000..d46d56ec --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_12.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_12 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_12 | ||
6 | dreal/dreal/test/smt2/hong/hong_12.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_12.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_12.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_12.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13 new file mode 100755 index 00000000..467493de --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13 | |||
@@ -0,0 +1,387 @@ | |||
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_13', | ||
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_13', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/MANIFEST new file mode 100755 index 00000000..615866c9 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_13 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_13 | ||
6 | dreal/dreal/test/smt2/hong/hong_13.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_13.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_13.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_13.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/hong/hong_13 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/hong/hong_13 new file mode 120000 index 00000000..bac272ee --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/hong/hong_13 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_13 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/hong/hong_13.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/hong/hong_13.smt2 new file mode 120000 index 00000000..66cf64f4 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/hong/hong_13.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_13.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/hong/hong_13.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/hong/hong_13.smt2.expected new file mode 120000 index 00000000..4070448c --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/hong/hong_13.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_13.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles_manifest new file mode 100755 index 00000000..615866c9 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_13.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_13 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_13 | ||
6 | dreal/dreal/test/smt2/hong/hong_13.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_13.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_13.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_13.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14 new file mode 100755 index 00000000..68a20d76 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14 | |||
@@ -0,0 +1,387 @@ | |||
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_14', | ||
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_14', | ||
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() | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/MANIFEST b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/MANIFEST new file mode 100755 index 00000000..9e8e23a0 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/MANIFEST | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_14 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_14 | ||
6 | dreal/dreal/test/smt2/hong/hong_14.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_14.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_14.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_14.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/dreal b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/dreal new file mode 120000 index 00000000..ed73d63d --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/dreal | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/__init__.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/__init__.py new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/__init__.py | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/hong/hong_14 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/hong/hong_14 new file mode 120000 index 00000000..96816c94 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/hong/hong_14 | |||
@@ -0,0 +1 @@ | |||
/home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_14 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/hong/hong_14.smt2 b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/hong/hong_14.smt2 new file mode 120000 index 00000000..07898209 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/hong/hong_14.smt2 | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_14.smt2 \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/hong/hong_14.smt2.expected b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/hong/hong_14.smt2.expected new file mode 120000 index 00000000..939d5fae --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/hong/hong_14.smt2.expected | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/hong/hong_14.smt2.expected \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/test.py b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/test.py new file mode 120000 index 00000000..c352474f --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles/dreal/dreal/test/smt2/test.py | |||
@@ -0,0 +1 @@ | |||
/home/models/dreal4/dreal/test/smt2/test.py \ No newline at end of file | |||
diff --git a/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles_manifest b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles_manifest new file mode 100755 index 00000000..9e8e23a0 --- /dev/null +++ b/Solvers/dreal4/bazel-bin/dreal/test/smt2/hong/hong_14.runfiles_manifest | |||
@@ -0,0 +1,8 @@ | |||
1 | dreal/dreal/__init__.py | ||
2 | dreal/dreal/dreal /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/dreal | ||
3 | dreal/dreal/test/__init__.py | ||
4 | dreal/dreal/test/smt2/__init__.py | ||
5 | dreal/dreal/test/smt2/hong/hong_14 /home/models/.cache/bazel/_bazel_models/d2bcb0d79fb4abe5ea9078c2027c2fc8/execroot/dreal/bazel-out/k8-opt/bin/dreal/test/smt2/hong/hong_14 | ||
6 | dreal/dreal/test/smt2/hong/hong_14.smt2 /home/models/dreal4/dreal/test/smt2/hong/hong_14.smt2 | ||
7 | dreal/dreal/test/smt2/hong/hong_14.smt2.expected /home/models/dreal4/dreal/test/smt2/hong/hong_14.smt2.expected | ||
8 | dreal/dreal/test/smt2/test.py /home/models/dreal4/dreal/test/smt2/test.py | ||