fix(tools): idf_tools.py install tool@version

This commit is contained in:
Marek Fiala
2025-05-16 11:19:52 +02:00
committed by BOT
parent 304b561f8a
commit 79ebe0b306

View File

@ -1089,17 +1089,37 @@ class IDFTool(object):
def get_preferred_installed_version(self) -> Optional[str]:
"""
Get the preferred installed version of the tool. If more versions installed, return the highest.
Get the preferred installed version of the tool.
If more versions installed, return recommended version if exists, otherwise return the highest supported version
"""
recommended_versions = [
try:
self.find_installed_versions()
except ToolBinaryError:
pass
if self.get_recommended_version() in self.versions_installed:
return self.get_recommended_version()
supported_installed_versions = [
k
for k in self.versions_installed
if self.versions[k].status == IDFToolVersion.STATUS_RECOMMENDED
if self.versions[k].status == IDFToolVersion.STATUS_SUPPORTED
and self.versions[k].compatible_with_platform(self._platform)
]
assert len(recommended_versions) <= 1
if recommended_versions:
return recommended_versions[0]
sorted_supported_installed_versions = sorted(
supported_installed_versions, key=lambda x: self.versions[x], reverse=True
)
if sorted_supported_installed_versions:
warn(
''.join(
[
f'Using supported version {sorted_supported_installed_versions[0]} for tool {self.name} ',
f'as recommended version {self.get_recommended_version()} is not installed.',
]
)
)
return sorted_supported_installed_versions[0]
return None
def find_installed_versions(self) -> None:
@ -1152,8 +1172,7 @@ class IDFTool(object):
else:
if ver_str != version:
warn(f'tool {self.name} version {version} is installed, but has reported version {ver_str}')
else:
self.versions_installed.append(version)
self.versions_installed.append(version)
if tool_error:
raise ToolBinaryError
@ -1900,6 +1919,9 @@ def expand_tools_arg(tools_spec: List[str], overall_tools: OrderedDict, targets:
# Filtering by ESP_targets
tools = [k for k in tools if overall_tools[k].is_supported_for_any_of_targets(targets)]
# Processing specific version of tool - defined with '@'
tools.extend([tool_pattern for tool_pattern in tools_spec if '@' in tool_pattern])
return tools
@ -2250,10 +2272,6 @@ def process_tool(
tool_export_paths: List[str] = []
tool_export_vars: Dict[str, str] = {}
try:
tool.find_installed_versions()
except ToolBinaryError:
pass
recommended_version_to_use = tool.get_preferred_installed_version()
if not tool.is_executable and recommended_version_to_use: