@@ -1585,11 +1585,37 @@ def get_idf_venv_dir():
1585
1585
1586
1586
def ensure_python_venv_available ():
1587
1587
1588
+ def _get_idf_venv_python_version ():
1589
+ try :
1590
+ version = subprocess .check_output (
1591
+ [
1592
+ get_python_exe (),
1593
+ "-c" ,
1594
+ "import sys;print('{0}.{1}.{2}-{3}.{4}'.format(*list(sys.version_info)))"
1595
+ ], text = True
1596
+ )
1597
+ return version .strip ()
1598
+ except subprocess .CalledProcessError as e :
1599
+ print ("Failed to extract Python version from IDF virtual env!" )
1600
+ return None
1601
+
1588
1602
def _is_venv_outdated (venv_data_file ):
1589
1603
try :
1590
1604
with open (venv_data_file , "r" , encoding = "utf8" ) as fp :
1591
1605
venv_data = json .load (fp )
1592
1606
if venv_data .get ("version" , "" ) != IDF_ENV_VERSION :
1607
+ print (
1608
+ "Warning! IDF virtual environment version changed!"
1609
+ )
1610
+ return True
1611
+ if (
1612
+ venv_data .get ("python_version" , "" )
1613
+ != _get_idf_venv_python_version ()
1614
+ ):
1615
+ print (
1616
+ "Warning! Python version in the IDF virtual environment"
1617
+ " differs from the current Python!"
1618
+ )
1593
1619
return True
1594
1620
return False
1595
1621
except :
@@ -1604,7 +1630,7 @@ def _create_venv(venv_dir):
1604
1630
1605
1631
if os .path .isdir (venv_dir ):
1606
1632
try :
1607
- print ("Removing an oudated IDF virtual environment" )
1633
+ print ("Removing an outdated IDF virtual environment" )
1608
1634
shutil .rmtree (venv_dir )
1609
1635
except OSError :
1610
1636
print (
@@ -1629,8 +1655,12 @@ def _create_venv(venv_dir):
1629
1655
venv_data_file = os .path .join (venv_dir , "pio-idf-venv.json" )
1630
1656
if not os .path .isfile (venv_data_file ) or _is_venv_outdated (venv_data_file ):
1631
1657
_create_venv (venv_dir )
1658
+ install_python_deps ()
1632
1659
with open (venv_data_file , "w" , encoding = "utf8" ) as fp :
1633
- venv_info = {"version" : IDF_ENV_VERSION }
1660
+ venv_info = {
1661
+ "version" : IDF_ENV_VERSION ,
1662
+ "python_version" : _get_idf_venv_python_version ()
1663
+ }
1634
1664
json .dump (venv_info , fp , indent = 2 )
1635
1665
1636
1666
@@ -1649,11 +1679,10 @@ def get_python_exe():
1649
1679
1650
1680
1651
1681
#
1652
- # ESP-IDF requires Python packages with specific versions in a virtual environment
1682
+ # Ensure Python environment contains everything required for IDF
1653
1683
#
1654
1684
1655
1685
ensure_python_venv_available ()
1656
- install_python_deps ()
1657
1686
1658
1687
# ESP-IDF package doesn't contain .git folder, instead package version is specified
1659
1688
# in a special file "version.h" in the root folder of the package
@@ -1859,7 +1888,15 @@ def get_python_exe():
1859
1888
# Extra flags which need to be explicitly specified in LINKFLAGS section because SCons
1860
1889
# cannot merge them correctly
1861
1890
extra_flags = filter_args (
1862
- link_args ["LINKFLAGS" ], ["-T" , "-u" , "-Wl,--start-group" , "-Wl,--end-group" ]
1891
+ link_args ["LINKFLAGS" ],
1892
+ [
1893
+ "-T" ,
1894
+ "-u" ,
1895
+ "-Wl,--start-group" ,
1896
+ "-Wl,--end-group" ,
1897
+ "-Wl,--whole-archive" ,
1898
+ "-Wl,--no-whole-archive" ,
1899
+ ],
1863
1900
)
1864
1901
link_args ["LINKFLAGS" ] = sorted (list (set (link_args ["LINKFLAGS" ]) - set (extra_flags )))
1865
1902
0 commit comments