MCPcopy Create free account
hub / github.com/pytorch/executorch / CMakeCache

Class CMakeCache

tools/cmake/cmake_cache.py:20–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19@dataclass
20class CMakeCache:
21 # The path to the CMakeCache.txt file.
22 cache_path: str
23
24 def __post_init__(self):
25 self.cache = CMakeCache.read_cmake_cache(cache_path=self.cache_path)
26
27 def get(self, var: str) -> Optional[CacheValue]:
28 return self.cache.get(var)
29
30 def is_enabled(self, var: str, fallback: bool = False) -> bool:
31 definition = self.get(var)
32 if definition is None:
33 return fallback
34 return CMakeCache._is_truthy(definition.value)
35
36 @staticmethod
37 def _is_truthy(value: Optional[str]) -> bool:
38 if (value is None) or (value.lower().strip() in _FALSE_VALUES):
39 return False
40 return True
41
42 @staticmethod
43 def read_cmake_cache(cache_path: str) -> Dict[str, CacheValue]:
44 result = {}
45 with open(cache_path, "r") as cache_file:
46 for line in cache_file:
47 line = line.strip()
48 if "=" in line:
49 key, value = line.split("=", 1)
50 value_type = ""
51 if ":" in key:
52 key, value_type = key.split(":")
53 result[key.strip()] = CacheValue(
54 value_type=value_type,
55 value=value.strip(),
56 )
57 return result

Callers 3

runMethod · 0.90
assert_cmake_cacheMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected