Explorar o código

Merge branch 'bugfix/set_target_with_stale_config' into 'master'

tools: fix set-target if IDF_TARGET env is set and stale sdkconfig exists

Closes IDF-7154

See merge request espressif/esp-idf!22950
Roland Dobai %!s(int64=2) %!d(string=hai) anos
pai
achega
775f8e7a49

+ 9 - 2
tools/idf_py_actions/tools.py

@@ -459,7 +459,7 @@ def ensure_build_directory(args: 'PropertyDict', prog_name: str, always_run_cmak
     cache_cmdl = _parse_cmdl_cmakecache(args.define_cache_entry)
 
     # Validate IDF_TARGET
-    _check_idf_target(args, prog_name, cache, cache_cmdl)
+    _check_idf_target(args, prog_name, cache, cache_cmdl, env)
 
     if always_run_cmake or _new_cmakecache_entries(cache, cache_cmdl):
         if args.generator is None:
@@ -582,7 +582,8 @@ def is_target_supported(project_path: str, supported_targets: List) -> bool:
     return get_target(project_path) in supported_targets
 
 
-def _check_idf_target(args: 'PropertyDict', prog_name: str, cache: Dict, cache_cmdl: Dict) -> None:
+def _check_idf_target(args: 'PropertyDict', prog_name: str, cache: Dict,
+                      cache_cmdl: Dict, env: Dict=None) -> None:
     """
     Cross-check the three settings (sdkconfig, CMakeCache, environment) and if there is
     mismatch, fail with instructions on how to fix this.
@@ -593,6 +594,12 @@ def _check_idf_target(args: 'PropertyDict', prog_name: str, cache: Dict, cache_c
     idf_target_from_cache = cache.get('IDF_TARGET')
     idf_target_from_cache_cmdl = cache_cmdl.get('IDF_TARGET')
 
+    # Called from set-target action. The original sdkconfig will be renamed
+    # in cmake, so ignore any CONFIG_IDF_TARGET which may be defined in
+    # stale sdkconfig.
+    if env and env.get('_IDF_PY_SET_TARGET_ACTION') == '1':
+        idf_target_from_sdkconfig = None
+
     if idf_target_from_env:
         # Let's check that IDF_TARGET values are consistent
         if idf_target_from_sdkconfig and idf_target_from_sdkconfig != idf_target_from_env:

+ 7 - 1
tools/test_build_system/test_non_default_target.py

@@ -140,7 +140,7 @@ def test_target_using_settarget_parameter_alternative_name(idf_py: IdfPyFunc) ->
 
 
 @pytest.mark.usefixtures('test_app_copy')
-def test_target_using_settarget_parameter(idf_py: IdfPyFunc) -> None:
+def test_target_using_settarget_parameter(idf_py: IdfPyFunc, default_idf_env: EnvDict) -> None:
     logging.info('Can set target using idf.py set-target')
     idf_py('set-target', ESP32S2_TARGET)
     check_file_contains('sdkconfig', 'CONFIG_IDF_TARGET="{}"'.format(ESP32S2_TARGET))
@@ -152,6 +152,12 @@ def test_target_using_settarget_parameter(idf_py: IdfPyFunc) -> None:
     check_file_contains('sdkconfig', 'CONFIG_IDF_TARGET="{}"'.format(ESP32S2_TARGET))
     check_file_contains('build/CMakeCache.txt', 'IDF_TARGET:STRING={}'.format(ESP32S2_TARGET))
 
+    logging.info('Can set target if IDF_TARGET env is set and old sdkconfig exists')
+    default_idf_env.update({'IDF_TARGET': ESP32_TARGET})
+    idf_py('set-target', ESP32_TARGET)
+    default_idf_env.pop('IDF_TARGET')
+    check_file_contains('sdkconfig', 'CONFIG_IDF_TARGET="{}"'.format(ESP32_TARGET))
+
 
 def test_target_using_sdkconfig(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
     logging.info('Can set the default target using sdkconfig.defaults')