Skip to content

Commit

Permalink
Better handling of IDF package version (#1420)
Browse files Browse the repository at this point in the history
Resolves #1418
  • Loading branch information
Jason2866 committed Jul 8, 2024
1 parent 19a2a1e commit f77dd2c
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions builder/frameworks/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit f77dd2c

Please sign in to comment.