Skip to content

Commit ead943e

Browse files
authored
failsafe IDF version get
1 parent 5c119c9 commit ead943e

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

builder/frameworks/espidf.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -991,24 +991,38 @@ def find_default_component(target_configs):
991991
env.Exit(1)
992992

993993

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
10041019

10051020

10061021
def create_version_file():
10071022
version_file = os.path.join(FRAMEWORK_DIR, "version.txt")
10081023
if not os.path.isfile(version_file):
10091024
with open(version_file, "w") as fp:
1010-
version = get_version_cmake_file()
1011-
fp.write(version)
1025+
fp.write(get_framework_version())
10121026

10131027

10141028
def generate_empty_partition_image(binary_path, image_size):
@@ -1241,8 +1255,10 @@ def get_idf_venv_dir():
12411255
# unnecessary reinstallation of Python dependencies in cases when Arduino
12421256
# as an IDF component requires a different version of the IDF package and
12431257
# 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+
)
12461262

12471263

12481264
def ensure_python_venv_available():

0 commit comments

Comments
 (0)