mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 12:35:28 +00:00
tools: add _parse_cmdl_cmakecache() helper
This parses cmakes cache vars defined on command line with -D options into dictionary. It allows to simplify the check for new cache entries and also can be re-used for other checks. Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
@@ -384,19 +384,27 @@ def _parse_cmakecache(path: str) -> Dict:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _new_cmakecache_entries(cache_path: str, new_cache_entries: List) -> bool:
|
def _parse_cmdl_cmakecache(entries: List) -> Dict[str, str]:
|
||||||
if not os.path.exists(cache_path):
|
"""
|
||||||
return True
|
Parse list of CMake cache entries passed in via the -D option.
|
||||||
|
|
||||||
if new_cache_entries:
|
Returns a dict of name:value.
|
||||||
current_cache = _parse_cmakecache(cache_path)
|
"""
|
||||||
|
result: Dict = {}
|
||||||
for entry in new_cache_entries:
|
for entry in entries:
|
||||||
key, value = entry.split('=', 1)
|
key, value = entry.split('=', 1)
|
||||||
current_value = current_cache.get(key, None)
|
value = _strip_quotes(value)
|
||||||
if current_value is None or _strip_quotes(value) != current_value:
|
result[key] = value
|
||||||
return True
|
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def _new_cmakecache_entries(cache: Dict, cache_cmdl: Dict) -> bool:
|
||||||
|
for entry in cache_cmdl:
|
||||||
|
if entry not in cache:
|
||||||
|
return True
|
||||||
|
if cache_cmdl[entry] != cache[entry]:
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -444,12 +452,14 @@ def ensure_build_directory(args: 'PropertyDict', prog_name: str, always_run_cmak
|
|||||||
cache_path = os.path.join(build_dir, 'CMakeCache.txt')
|
cache_path = os.path.join(build_dir, 'CMakeCache.txt')
|
||||||
cache = _parse_cmakecache(cache_path) if os.path.exists(cache_path) else {}
|
cache = _parse_cmakecache(cache_path) if os.path.exists(cache_path) else {}
|
||||||
|
|
||||||
|
args.define_cache_entry.append('CCACHE_ENABLE=%d' % args.ccache)
|
||||||
|
|
||||||
|
cache_cmdl = _parse_cmdl_cmakecache(args.define_cache_entry)
|
||||||
|
|
||||||
# Validate or set IDF_TARGET
|
# Validate or set IDF_TARGET
|
||||||
_guess_or_check_idf_target(args, prog_name, cache)
|
_guess_or_check_idf_target(args, prog_name, cache)
|
||||||
|
|
||||||
args.define_cache_entry.append('CCACHE_ENABLE=%d' % args.ccache)
|
if always_run_cmake or _new_cmakecache_entries(cache, cache_cmdl):
|
||||||
|
|
||||||
if always_run_cmake or _new_cmakecache_entries(cache_path, args.define_cache_entry):
|
|
||||||
if args.generator is None:
|
if args.generator is None:
|
||||||
args.generator = _detect_cmake_generator(prog_name)
|
args.generator = _detect_cmake_generator(prog_name)
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user