Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more failsafe IDF version get #1420

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading