@@ -991,24 +991,38 @@ def find_default_component(target_configs):
991
991
env .Exit (1 )
992
992
993
993
994
- def get_version_cmake_file ():
995
- version_cmake = os .path .join (FRAMEWORK_DIR , "tools" , "cmake" , "version.cmake" )
996
- with open (version_cmake , "r" ) as file :
997
- string = file .read ().replace ("\n " , "" ).replace ("(" , " " ).replace (")" , " " )
998
- list = string .split ()
999
- v_major = list [(list .index ("IDF_VERSION_MAJOR" ))+ 1 ]
1000
- v_minor = list [(list .index ("IDF_VERSION_MINOR" ))+ 1 ]
1001
- v_patch = list [(list .index ("IDF_VERSION_PATCH" ))+ 1 ]
1002
- version = v_major + "." + v_minor + "." + v_patch
1003
- return version
994
+ def get_framework_version ():
995
+ def _extract_from_cmake_version_file ():
996
+ version_cmake_file = os .path .join (
997
+ FRAMEWORK_DIR , "tools" , "cmake" , "version.cmake"
998
+ )
999
+ if not os .path .isfile (version_cmake_file ):
1000
+ return
1001
+
1002
+ with open (version_cmake_file , encoding = "utf8" ) as fp :
1003
+ pattern = r"set\(IDF_VERSION_(MAJOR|MINOR|PATCH) (\d+)\)"
1004
+ matches = re .findall (pattern , fp .read ())
1005
+ if len (matches ) != 3 :
1006
+ return
1007
+ # If found all three parts of the version
1008
+ return "." .join ([match [1 ] for match in matches ])
1009
+
1010
+ pkg = platform .get_package ("framework-espidf" )
1011
+ version = get_original_version (str (pkg .metadata .version .truncate ()))
1012
+ if not version :
1013
+ # Fallback value extracted directly from the cmake version file
1014
+ version = _extract_from_cmake_version_file ()
1015
+ if not version :
1016
+ version = "0.0.0"
1017
+
1018
+ return version
1004
1019
1005
1020
1006
1021
def create_version_file ():
1007
1022
version_file = os .path .join (FRAMEWORK_DIR , "version.txt" )
1008
1023
if not os .path .isfile (version_file ):
1009
1024
with open (version_file , "w" ) as fp :
1010
- version = get_version_cmake_file ()
1011
- fp .write (version )
1025
+ fp .write (get_framework_version ())
1012
1026
1013
1027
1014
1028
def generate_empty_partition_image (binary_path , image_size ):
@@ -1241,8 +1255,10 @@ def get_idf_venv_dir():
1241
1255
# unnecessary reinstallation of Python dependencies in cases when Arduino
1242
1256
# as an IDF component requires a different version of the IDF package and
1243
1257
# hence a different set of Python deps or their versions
1244
- idf_version = get_version_cmake_file ()
1245
- return os .path .join (env .subst ("$PROJECT_CORE_DIR" ), "penv" , ".espidf-" + idf_version )
1258
+ idf_version = get_framework_version ()
1259
+ return os .path .join (
1260
+ env .subst ("$PROJECT_CORE_DIR" ), "penv" , ".espidf-" + idf_version
1261
+ )
1246
1262
1247
1263
1248
1264
def ensure_python_venv_available ():
0 commit comments