Skip to content

Commit f77dd2c

Browse files
authored
Better handling of IDF package version (platformio#1420)
Resolves platformio#1418
1 parent 19a2a1e commit f77dd2c

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

builder/frameworks/espidf.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,12 +999,38 @@ def find_default_component(target_configs):
999999
env.Exit(1)
10001000

10011001

1002+
def get_framework_version():
1003+
def _extract_from_cmake_version_file():
1004+
version_cmake_file = os.path.join(
1005+
FRAMEWORK_DIR, "tools", "cmake", "version.cmake"
1006+
)
1007+
if not os.path.isfile(version_cmake_file):
1008+
return
1009+
1010+
with open(version_cmake_file, encoding="utf8") as fp:
1011+
pattern = r"set\(IDF_VERSION_(MAJOR|MINOR|PATCH) (\d+)\)"
1012+
matches = re.findall(pattern, fp.read())
1013+
if len(matches) != 3:
1014+
return
1015+
# If found all three parts of the version
1016+
return ".".join([match[1] for match in matches])
1017+
1018+
pkg = platform.get_package("framework-espidf")
1019+
version = get_original_version(str(pkg.metadata.version.truncate()))
1020+
if not version:
1021+
# Fallback value extracted directly from the cmake version file
1022+
version = _extract_from_cmake_version_file()
1023+
if not version:
1024+
version = "0.0.0"
1025+
1026+
return version
1027+
1028+
10021029
def create_version_file():
10031030
version_file = os.path.join(FRAMEWORK_DIR, "version.txt")
10041031
if not os.path.isfile(version_file):
10051032
with open(version_file, "w") as fp:
1006-
package_version = platform.get_package_version("framework-espidf")
1007-
fp.write(get_original_version(package_version) or package_version)
1033+
fp.write(get_framework_version())
10081034

10091035

10101036
def generate_empty_partition_image(binary_path, image_size):
@@ -1236,7 +1262,7 @@ def get_idf_venv_dir():
12361262
# unnecessary reinstallation of Python dependencies in cases when Arduino
12371263
# as an IDF component requires a different version of the IDF package and
12381264
# hence a different set of Python deps or their versions
1239-
idf_version = get_original_version(platform.get_package_version("framework-espidf"))
1265+
idf_version = get_framework_version()
12401266
return os.path.join(
12411267
env.subst("$PROJECT_CORE_DIR"), "penv", ".espidf-" + idf_version
12421268
)

0 commit comments

Comments
 (0)