Instantiate a CMakeBuild from a path. This is used to recover from an existing physical directory (created with or without CMakeBuild). Note that this method is not idempotent as the original definition will be lost. Only build_type is recovered.
(path)
| 181 | |
| 182 | @staticmethod |
| 183 | def from_path(path): |
| 184 | """ Instantiate a CMakeBuild from a path. |
| 185 | |
| 186 | This is used to recover from an existing physical directory (created |
| 187 | with or without CMakeBuild). |
| 188 | |
| 189 | Note that this method is not idempotent as the original definition will |
| 190 | be lost. Only build_type is recovered. |
| 191 | """ |
| 192 | if not CMakeBuild.is_build_dir(path): |
| 193 | raise ValueError(f"Not a valid CMakeBuild path: {path}") |
| 194 | |
| 195 | build_type = None |
| 196 | # Infer build_type by looking at CMakeCache.txt and looking for a magic |
| 197 | # definition |
| 198 | cmake_cache_path = os.path.join(path, "CMakeCache.txt") |
| 199 | with open(cmake_cache_path, "r") as cmake_cache: |
| 200 | candidates = CMAKE_BUILD_TYPE_RE.findall(cmake_cache.read()) |
| 201 | build_type = candidates[0].lower() if candidates else "release" |
| 202 | |
| 203 | return CMakeBuild(path, build_type) |
| 204 | |
| 205 | def __repr__(self): |
| 206 | return (f"CMakeBuild[build = {self.build_dir}," |
no test coverage detected