1
1
#!/usr/bin/env python
2
2
# coding=utf-8
3
3
#
4
- # SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
4
+ # SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
5
5
#
6
6
# SPDX-License-Identifier: Apache-2.0
7
7
#
@@ -1568,6 +1568,94 @@ def action_check(args): # type: ignore
1568
1568
raise SystemExit (1 )
1569
1569
1570
1570
1571
+ # The following functions are used in process_tool which is a part of the action_export.
1572
+ def handle_recommended_version_to_use (
1573
+ tool ,
1574
+ tool_name ,
1575
+ version_to_use ,
1576
+ prefer_system_hint ,
1577
+ ): # type: (IDFTool, str, str, str) -> Tuple[list, dict]
1578
+ tool_export_paths = tool .get_export_paths (version_to_use )
1579
+ tool_export_vars = tool .get_export_vars (version_to_use )
1580
+ if tool .version_in_path and tool .version_in_path not in tool .versions :
1581
+ info ('Not using an unsupported version of tool {} found in PATH: {}.' .format (
1582
+ tool .name , tool .version_in_path ) + prefer_system_hint , f = sys .stderr )
1583
+ return tool_export_paths , tool_export_vars
1584
+
1585
+
1586
+ def handle_supported_or_deprecated_version (tool , tool_name ): # type: (IDFTool, str) -> None
1587
+ version_obj : IDFToolVersion = tool .versions [tool .version_in_path ] # type: ignore
1588
+ if version_obj .status == IDFToolVersion .STATUS_SUPPORTED :
1589
+ info ('Using a supported version of tool {} found in PATH: {}.' .format (tool_name , tool .version_in_path ),
1590
+ f = sys .stderr )
1591
+ info ('However the recommended version is {}.' .format (tool .get_recommended_version ()),
1592
+ f = sys .stderr )
1593
+ elif version_obj .status == IDFToolVersion .STATUS_DEPRECATED :
1594
+ warn ('using a deprecated version of tool {} found in PATH: {}' .format (tool_name , tool .version_in_path ))
1595
+
1596
+
1597
+ def handle_missing_versions (
1598
+ tool ,
1599
+ tool_name ,
1600
+ install_cmd ,
1601
+ prefer_system_hint
1602
+ ): # type: (IDFTool, str, str, str) -> None
1603
+ fatal ('tool {} has no installed versions. Please run \' {}\' to install it.' .format (
1604
+ tool .name , install_cmd ))
1605
+ if tool .version_in_path and tool .version_in_path not in tool .versions :
1606
+ info ('An unsupported version of tool {} was found in PATH: {}. ' .format (tool_name , tool .version_in_path ) +
1607
+ prefer_system_hint , f = sys .stderr )
1608
+
1609
+
1610
+ def process_tool (
1611
+ tool ,
1612
+ tool_name ,
1613
+ args ,
1614
+ install_cmd ,
1615
+ prefer_system_hint
1616
+ ): # type: (IDFTool, str, argparse.Namespace, str, str) -> Tuple[list, dict, bool]
1617
+ tool_found : bool = True
1618
+ tool_export_paths : List [str ] = []
1619
+ tool_export_vars : Dict [str , str ] = {}
1620
+
1621
+ tool .find_installed_versions ()
1622
+ recommended_version_to_use = tool .get_preferred_installed_version ()
1623
+
1624
+ if not tool .is_executable and recommended_version_to_use :
1625
+ tool_export_vars = tool .get_export_vars (recommended_version_to_use )
1626
+ return tool_export_paths , tool_export_vars , tool_found
1627
+
1628
+ if recommended_version_to_use and not args .prefer_system :
1629
+ tool_export_paths , tool_export_vars = handle_recommended_version_to_use (
1630
+ tool , tool_name , recommended_version_to_use , prefer_system_hint
1631
+ )
1632
+ return tool_export_paths , tool_export_vars , tool_found
1633
+
1634
+ if tool .version_in_path :
1635
+ if tool .version_in_path not in tool .versions :
1636
+ # unsupported version
1637
+ if args .prefer_system : # type: ignore
1638
+ warn ('using an unsupported version of tool {} found in PATH: {}' .format (
1639
+ tool .name , tool .version_in_path ))
1640
+ return tool_export_paths , tool_export_vars , tool_found
1641
+ else :
1642
+ # unsupported version in path
1643
+ pass
1644
+ else :
1645
+ # supported/deprecated version in PATH, use it
1646
+ handle_supported_or_deprecated_version (tool , tool_name )
1647
+ return tool_export_paths , tool_export_vars , tool_found
1648
+
1649
+ if not tool .versions_installed :
1650
+ if tool .get_install_type () == IDFTool .INSTALL_ALWAYS :
1651
+ handle_missing_versions (tool , tool_name , install_cmd , prefer_system_hint )
1652
+ tool_found = False
1653
+ # If a tool found, but it is optional and does not have versions installed, use whatever is in PATH.
1654
+ return tool_export_paths , tool_export_vars , tool_found
1655
+
1656
+ return tool_export_paths , tool_export_vars , tool_found
1657
+
1658
+
1571
1659
def action_export (args ): # type: ignore
1572
1660
if args .deactivate and different_idf_detected ():
1573
1661
deactivate_statement (args )
@@ -1587,58 +1675,10 @@ def action_export(args): # type: ignore
1587
1675
for name , tool in tools_info .items ():
1588
1676
if tool .get_install_type () == IDFTool .INSTALL_NEVER :
1589
1677
continue
1590
- tool .find_installed_versions ()
1591
- version_to_use = tool .get_preferred_installed_version ()
1592
-
1593
- if not tool .is_executable and version_to_use :
1594
- tool_export_vars = tool .get_export_vars (version_to_use )
1595
- export_vars = {** export_vars , ** tool_export_vars }
1596
- continue
1597
-
1598
- if tool .version_in_path :
1599
- if tool .version_in_path not in tool .versions :
1600
- # unsupported version
1601
- if args .prefer_system : # type: ignore
1602
- warn ('using an unsupported version of tool {} found in PATH: {}' .format (
1603
- tool .name , tool .version_in_path ))
1604
- continue
1605
- else :
1606
- # unsupported version in path
1607
- pass
1608
- else :
1609
- # supported/deprecated version in PATH, use it
1610
- version_obj = tool .versions [tool .version_in_path ]
1611
- if version_obj .status == IDFToolVersion .STATUS_SUPPORTED :
1612
- info ('Using a supported version of tool {} found in PATH: {}.' .format (name , tool .version_in_path ),
1613
- f = sys .stderr )
1614
- info ('However the recommended version is {}.' .format (tool .get_recommended_version ()),
1615
- f = sys .stderr )
1616
- elif version_obj .status == IDFToolVersion .STATUS_DEPRECATED :
1617
- warn ('using a deprecated version of tool {} found in PATH: {}' .format (name , tool .version_in_path ))
1618
- continue
1619
-
1620
- if not tool .versions_installed :
1621
- if tool .get_install_type () == IDFTool .INSTALL_ALWAYS :
1622
- all_tools_found = False
1623
- fatal ('tool {} has no installed versions. Please run \' {}\' to install it.' .format (
1624
- tool .name , install_cmd ))
1625
- if tool .version_in_path and tool .version_in_path not in tool .versions :
1626
- info ('An unsupported version of tool {} was found in PATH: {}. ' .format (name , tool .version_in_path ) +
1627
- prefer_system_hint , f = sys .stderr )
1628
- continue
1629
- else :
1630
- # tool is optional, and does not have versions installed
1631
- # use whatever is available in PATH
1632
- continue
1633
-
1634
- if tool .version_in_path and tool .version_in_path not in tool .versions :
1635
- info ('Not using an unsupported version of tool {} found in PATH: {}.' .format (
1636
- tool .name , tool .version_in_path ) + prefer_system_hint , f = sys .stderr )
1637
-
1638
- export_paths = tool .get_export_paths (version_to_use )
1639
- if export_paths :
1640
- paths_to_export += export_paths
1641
- tool_export_vars = tool .get_export_vars (version_to_use )
1678
+ tool_export_paths , tool_export_vars , tool_found = process_tool (tool , name , args , install_cmd , prefer_system_hint )
1679
+ if not tool_found :
1680
+ all_tools_found = False
1681
+ paths_to_export += tool_export_paths
1642
1682
export_vars = {** export_vars , ** tool_export_vars }
1643
1683
1644
1684
current_path = os .getenv ('PATH' )
0 commit comments