diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-07-13 13:03:15 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-07-13 13:05:26 +0300 |
commit | 107bbee4c763c95ea5d07a3b2f08bfe3b6adb24c (patch) | |
tree | 2e9a703fa9e5200665b76a52ae5b88c3c084303b /build_files | |
parent | 5201748f5f5a0b1ac026a21dbcf64ce4ce0d0025 (diff) |
Use regex for cmake config parsing
Diffstat (limited to 'build_files')
-rw-r--r-- | build_files/cmake/project_source_info.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/build_files/cmake/project_source_info.py b/build_files/cmake/project_source_info.py index b28c8208d44..45d732c2422 100644 --- a/build_files/cmake/project_source_info.py +++ b/build_files/cmake/project_source_info.py @@ -59,14 +59,21 @@ def is_c_any(filename): CMAKE_DIR = "." -def cmake_cache_var(var): - cache_file = open(join(CMAKE_DIR, "CMakeCache.txt")) - lines = [l_strip for l in cache_file for l_strip in (l.strip(),) if l_strip if not l_strip.startswith("//") if not l_strip.startswith("#")] - cache_file.close() +def cmake_cache_var_iter(): + import re + re_cache = re.compile(r'([A-Za-z0-9_\-]+)?:?([A-Za-z0-9_\-]+)?=(.*)$') + with open(join(CMAKE_DIR, "CMakeCache.txt"), 'r', encoding='utf-8') as cache_file: + for l in cache_file: + match = re_cache.match(l.strip()) + if match is not None: + var, type_, val = match.groups() + yield (var, type_ or "", val) + - for l in lines: - if l.split(":")[0] == var: - return l.split("=", 1)[-1] +def cmake_cache_var(var): + for var_iter, type_iter, value_iter in cmake_cache_var_iter(): + if var == var_iter: + return value_iter return None |