Merge branch 'bugfix/missing_idfSelectedId' into 'release/v4.4'

Tools: bugfix wrong format of idf-env.json, KeyError: 'idfSelectedId'

See merge request espressif/esp-idf!20327
pull/9884/head^2
Roland Dobai 2022-09-27 15:22:36 +08:00
commit c8ce38e60c
1 zmienionych plików z 9 dodań i 12 usunięć

Wyświetl plik

@ -1077,7 +1077,10 @@ def get_idf_env(): # type: () -> Any
try:
idf_env_file_path = os.path.join(global_idf_tools_path, IDF_ENV_FILE) # type: ignore
with open(idf_env_file_path, 'r') as idf_env_file:
return json.load(idf_env_file)
idf_env_json = json.load(idf_env_file)
if 'sha' not in idf_env_json['idfInstalled']:
idf_env_json['idfInstalled']['sha'] = {'targets': []}
return idf_env_json
except (IOError, OSError):
if not os.path.exists(idf_env_file_path):
warn('File {} was not found. '.format(idf_env_file_path))
@ -1087,17 +1090,14 @@ def get_idf_env(): # type: () -> Any
os.rename(idf_env_file_path, os.path.join(os.path.dirname(idf_env_file_path), (filename + '_failed' + ending)))
info('Creating {}' .format(idf_env_file_path))
return {'idfSelectedId': 'sha', 'idfInstalled': {'sha': {'targets': {}}}}
return {'idfInstalled': {'sha': {'targets': []}}}
def export_targets_to_idf_env_json(targets): # type: (list[str]) -> None
idf_env_json = get_idf_env()
targets = list(set(targets + get_user_defined_targets()))
for env in idf_env_json['idfInstalled']:
if env == idf_env_json['idfSelectedId']:
idf_env_json['idfInstalled'][env]['targets'] = targets
break
idf_env_json['idfInstalled']['sha']['targets'] = targets
try:
if global_idf_tools_path: # mypy fix for Optional[str] in the next call
@ -1132,16 +1132,13 @@ def get_user_defined_targets(): # type: () -> list[str]
try:
with open(os.path.join(global_idf_tools_path, IDF_ENV_FILE), 'r') as idf_env_file: # type: ignore
idf_env_json = json.load(idf_env_file)
if 'sha' not in idf_env_json['idfInstalled']:
idf_env_json['idfInstalled']['sha'] = {'targets': []}
except OSError:
# warn('File {} was not found. Installing tools for all esp targets.'.format(os.path.join(global_idf_tools_path, IDF_ENV_FILE))) # type: ignore
return []
targets = []
for env in idf_env_json['idfInstalled']:
if env == idf_env_json['idfSelectedId']:
targets = idf_env_json['idfInstalled'][env]['targets']
break
return targets
return idf_env_json['idfInstalled']['sha']['targets'] # type: ignore
def get_all_targets_from_tools_json(): # type: () -> list[str]