CIRCT 23.0.0git
Loading...
Searching...
No Matches
conftest.py
Go to the documentation of this file.
1# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2# See https://llvm.org/LICENSE.txt for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5from pathlib import Path
6
7collect_ignore_glob = [
8 "integration/hw/*.py",
9]
10
11
12def _looks_like_runtime_root(root: Path) -> bool:
14
15
16def _has_runtime_root_markers(root: Path) -> bool:
17 markers = [
18 root / "cmake" / "esiaccelConfig.cmake",
19 root / "cpp" / "cmake" / "esiaccelConfig.cmake",
20 root / "cpp" / "include" / "esi" / "Accelerator.h",
21 root / "include" / "esi" / "Accelerator.h",
22 root / "tests" / "cpp",
23 root / "bin",
24 ]
25 return any(marker.exists() for marker in markers)
26
27
28def _has_runtime_library_markers(root: Path) -> bool:
29 markers = [
30 root / "lib" / "libESICppRuntime.so",
31 root / "lib" / "libESICppRuntime.dylib",
32 root / "ESICppRuntime.dll",
33 ]
34 return any(marker.exists() for marker in markers)
35
36
37def get_runtime_root() -> Path:
38 """Determine the root directory of the ESI runtime installation. Since we need
39 to support testing in a bunch of different configurations and environments,
40 just semi-brute-force the search."""
41 import esiaccel
42
43 # Keep the unresolved build-tree path first. The integrated CIRCT build uses
44 # symlinks back into the source tree for Python sources, and resolve() would
45 # otherwise discard the build location where the runtime libraries live.
46 # Wheel installs (e.g. ``site-packages/esiaccel/``) put cmake configs,
47 # headers and DLLs directly in the package directory, so probe that first.
48 package_file = Path(esiaccel.__file__)
49 candidates = [
50 package_file.parent,
51 package_file.parent.parent,
52 package_file.parent.parent.parent,
53 package_file.resolve().parent,
54 package_file.resolve().parent.parent,
55 package_file.resolve().parent.parent.parent,
56 ]
57
58 seen = set()
59 unique_candidates = []
60 for candidate in candidates:
61 if candidate not in seen:
62 unique_candidates.append(candidate)
63 seen.add(candidate)
64
65 # Prefer roots with headers, CMake package files, binaries, or the runtime
66 # test tree over lib-only package directories. In integrated CIRCT builds,
67 # the Python package may contain library symlinks while the source headers
68 # are only discoverable by walking up from the broader runtime build root.
69 for candidate in unique_candidates:
70 if _has_runtime_root_markers(candidate):
71 return candidate
72
73 for candidate in unique_candidates:
74 if _looks_like_runtime_root(candidate):
75 return candidate
76
77 raise FileNotFoundError("Could not determine ESI runtime root directory")
bool _has_runtime_root_markers(Path root)
Definition conftest.py:16
bool _has_runtime_library_markers(Path root)
Definition conftest.py:28
Path get_runtime_root()
Definition conftest.py:37
bool _looks_like_runtime_root(Path root)
Definition conftest.py:12