|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2026 Adafruit Industries LLC |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +"""Set IDF_CONSTRAINT_FILE for CI. |
| 6 | +
|
| 7 | +CI installs requirements-dev.txt for all ports, but on Espressif builds we must |
| 8 | +also apply the matching ESP-IDF constraints file so pip does not upgrade shared |
| 9 | +packages (for example click) beyond what ESP-IDF allows. This script derives the |
| 10 | +active ESP-IDF major.minor version from version.cmake and exports the exact |
| 11 | +constraints file path into GITHUB_ENV for later install steps. |
| 12 | +""" |
| 13 | + |
| 14 | +import os |
| 15 | +import pathlib |
| 16 | +import re |
| 17 | + |
| 18 | +TOP = pathlib.Path(__file__).resolve().parent.parent |
| 19 | + |
| 20 | + |
| 21 | +def main() -> None: |
| 22 | + version_cmake = TOP / "ports" / "espressif" / "esp-idf" / "tools" / "cmake" / "version.cmake" |
| 23 | + data = version_cmake.read_text(encoding="utf-8") |
| 24 | + |
| 25 | + major = re.search(r"IDF_VERSION_MAJOR\s+(\d+)", data) |
| 26 | + minor = re.search(r"IDF_VERSION_MINOR\s+(\d+)", data) |
| 27 | + if major is None or minor is None: |
| 28 | + raise RuntimeError(f"Unable to parse IDF version from {version_cmake}") |
| 29 | + |
| 30 | + idf_tools_path = os.environ.get("IDF_TOOLS_PATH") |
| 31 | + if not idf_tools_path: |
| 32 | + raise RuntimeError("IDF_TOOLS_PATH is not set") |
| 33 | + |
| 34 | + constraint = ( |
| 35 | + pathlib.Path(idf_tools_path) / f"espidf.constraints.v{major.group(1)}.{minor.group(1)}.txt" |
| 36 | + ) |
| 37 | + |
| 38 | + github_env = os.environ.get("GITHUB_ENV") |
| 39 | + if github_env: |
| 40 | + with open(github_env, "a", encoding="utf-8") as f: |
| 41 | + f.write(f"IDF_CONSTRAINT_FILE={constraint}\n") |
| 42 | + |
| 43 | + print(f"Set IDF_CONSTRAINT_FILE={constraint}") |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + main() |
0 commit comments