@@ -1585,11 +1585,37 @@ def get_idf_venv_dir():
15851585
15861586def ensure_python_venv_available ():
15871587
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+
15881602 def _is_venv_outdated (venv_data_file ):
15891603 try :
15901604 with open (venv_data_file , "r" , encoding = "utf8" ) as fp :
15911605 venv_data = json .load (fp )
15921606 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+ )
15931619 return True
15941620 return False
15951621 except :
@@ -1604,7 +1630,7 @@ def _create_venv(venv_dir):
16041630
16051631 if os .path .isdir (venv_dir ):
16061632 try :
1607- print ("Removing an oudated IDF virtual environment" )
1633+ print ("Removing an outdated IDF virtual environment" )
16081634 shutil .rmtree (venv_dir )
16091635 except OSError :
16101636 print (
@@ -1629,8 +1655,12 @@ def _create_venv(venv_dir):
16291655 venv_data_file = os .path .join (venv_dir , "pio-idf-venv.json" )
16301656 if not os .path .isfile (venv_data_file ) or _is_venv_outdated (venv_data_file ):
16311657 _create_venv (venv_dir )
1658+ install_python_deps ()
16321659 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+ }
16341664 json .dump (venv_info , fp , indent = 2 )
16351665
16361666
@@ -1649,11 +1679,10 @@ def get_python_exe():
16491679
16501680
16511681#
1652- # ESP-IDF requires Python packages with specific versions in a virtual environment
1682+ # Ensure Python environment contains everything required for IDF
16531683#
16541684
16551685ensure_python_venv_available ()
1656- install_python_deps ()
16571686
16581687# ESP-IDF package doesn't contain .git folder, instead package version is specified
16591688# in a special file "version.h" in the root folder of the package
@@ -1859,7 +1888,15 @@ def get_python_exe():
18591888# Extra flags which need to be explicitly specified in LINKFLAGS section because SCons
18601889# cannot merge them correctly
18611890extra_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+ ],
18631900)
18641901link_args ["LINKFLAGS" ] = sorted (list (set (link_args ["LINKFLAGS" ]) - set (extra_flags )))
18651902
0 commit comments