Skip to content

Commit

Permalink
Merge branch 'bugfix/set_target_with_stale_config' into 'master'
Browse files Browse the repository at this point in the history
tools: fix set-target if IDF_TARGET env is set and stale sdkconfig exists

Closes IDF-7154

See merge request espressif/esp-idf!22950
  • Loading branch information
dobairoland committed Mar 31, 2023
2 parents 5d70620 + 9b731e5 commit 775f8e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions tools/idf_py_actions/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion tools/test_build_system/test_non_default_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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')
Expand Down

0 comments on commit 775f8e7

Please sign in to comment.