Better handling of IDF package version (#1420)

Resolves #1418
This commit is contained in:
Jason2866
2024-07-08 15:27:15 +02:00
committed by GitHub
parent 19a2a1e408
commit f77dd2c993
+29 -3
View File
@@ -999,12 +999,38 @@ def find_default_component(target_configs):
env.Exit(1)
def get_framework_version():
def _extract_from_cmake_version_file():
version_cmake_file = os.path.join(
FRAMEWORK_DIR, "tools", "cmake", "version.cmake"
)
if not os.path.isfile(version_cmake_file):
return
with open(version_cmake_file, encoding="utf8") as fp:
pattern = r"set\(IDF_VERSION_(MAJOR|MINOR|PATCH) (\d+)\)"
matches = re.findall(pattern, fp.read())
if len(matches) != 3:
return
# If found all three parts of the version
return ".".join([match[1] for match in matches])
pkg = platform.get_package("framework-espidf")
version = get_original_version(str(pkg.metadata.version.truncate()))
if not version:
# Fallback value extracted directly from the cmake version file
version = _extract_from_cmake_version_file()
if not version:
version = "0.0.0"
return version
def create_version_file():
version_file = os.path.join(FRAMEWORK_DIR, "version.txt")
if not os.path.isfile(version_file):
with open(version_file, "w") as fp:
package_version = platform.get_package_version("framework-espidf")
fp.write(get_original_version(package_version) or package_version)
fp.write(get_framework_version())
def generate_empty_partition_image(binary_path, image_size):
@@ -1236,7 +1262,7 @@ def get_idf_venv_dir():
# unnecessary reinstallation of Python dependencies in cases when Arduino
# as an IDF component requires a different version of the IDF package and
# hence a different set of Python deps or their versions
idf_version = get_original_version(platform.get_package_version("framework-espidf"))
idf_version = get_framework_version()
return os.path.join(
env.subst("$PROJECT_CORE_DIR"), "penv", ".espidf-" + idf_version
)