build system: cmake reinstalls gcc every run
arm-none-eabi-checks.cmake contains functions to check and install correct version of gcc-arm-none-eabi,
if specified version is not found. gcc_get_version() does not properly check current gcc version of gcc that was installed in tools/ directory.
Current Behavior
gcc_get_version() only checks for compiler version of systemwide gcc-arm-none-eabi. Dockerfile does not install correct version into the image. Because version check fails every time, gcc is downloaded/installed always when cmake configuration step is invoked.
Steps to Reproduce
- make sure cmake is not initialized
- run ./build.sh <ANY>, for example FLYWOOF745
Expected behavior
gcc_get_version() checks for already downloaded compiler version. (from tools/ directory)
Just enter your version here
Check version
This behavior occurs because the gcc_get_version function calls find_program(gcc ${prog}), and the result of the search is automatically cached in CMakeCache.txt (e.g., gcc:FILEPATH=/usr/bin/arm-none-eabi-gcc) before the new version is installed.
I propose the following solution:
diff --git a/cmake/arm-none-eabi-checks.cmake b/cmake/arm-none-eabi-checks.cmake
index f31a26c3e..b80ca8622 100644
--- a/cmake/arm-none-eabi-checks.cmake
+++ b/cmake/arm-none-eabi-checks.cmake
@@ -131,6 +131,12 @@ function(arm_none_eabi_gcc_check)
if(COMPILER_VERSION_CHECK AND NOT arm_none_eabi_gcc_version STREQUAL version)
message("-- expecting ${prog} version ${arm_none_eabi_gcc_version}, but got version ${version} instead")
arm_none_eabi_gcc_install()
+ unset(gcc CACHE)
+ gcc_get_version(version
+ TRIPLET ${arm_none_eabi_triplet}
+ PROGRAM_NAME prog
+ PROGRAM_PATH prog_path
+ )
return()
endif()
endfunction()
In the case where a new version needs to be installed, we explicitly clear the cached gcc variable and then call gcc_get_version again. This ensures that the new version’s path is stored in the cache during the first cmake run.
Final change might look like this:
diff --git a/cmake/arm-none-eabi-checks.cmake b/cmake/arm-none-eabi-checks.cmake
index f31a26c3e..a379f5592 100644
--- a/cmake/arm-none-eabi-checks.cmake
+++ b/cmake/arm-none-eabi-checks.cmake
@@ -125,12 +125,23 @@ function(arm_none_eabi_gcc_check)
if(NOT version)
message("-- could not find ${prog}")
arm_none_eabi_gcc_install()
+ gcc_get_version(version
+ TRIPLET ${arm_none_eabi_triplet}
+ PROGRAM_NAME prog
+ PROGRAM_PATH prog_path
+ )
return()
endif()
message("-- found ${prog} ${version} at ${prog_path}")
if(COMPILER_VERSION_CHECK AND NOT arm_none_eabi_gcc_version STREQUAL version)
message("-- expecting ${prog} version ${arm_none_eabi_gcc_version}, but got version ${version} instead")
arm_none_eabi_gcc_install()
+ unset(gcc CACHE)
+ gcc_get_version(version
+ TRIPLET ${arm_none_eabi_triplet}
+ PROGRAM_NAME prog
+ PROGRAM_PATH prog_path
+ )
return()
endif()
endfunction()
Justification:
If gcc is not installed, then after running cmake, the following entry appears in CMakeCache.txt:
gcc:FILEPATH=gcc-NOTFOUND
On the next cmake run, the path will be updated to the correct location of the installed gcc. By calling gcc_get_version immediately after installation, the cache will then contain:
gcc:FILEPATH=/src/tools/arm-gnu-toolchain-13.2.rel1/bin/arm-none-eabi-gcc
which is the intended result. In the case where the system gcc version does not match the required one, the cache may store:
gcc:FILEPATH=/usr/bin/arm-none-eabi-gcc
Due to this cached path, gcc will not be updated in subsequent runs, and the installation will be unnecessarily repeated on every cmake invocation — which is the very issue that prompted the creation of this patch.
To prevent such behavior, it is necessary to either remove the cache file or explicitly reset the variable and call gcc_get_version again, which this patch does.
After applying this patch, the correct path of the installed gcc is cached on the first run of cmake, avoiding redundant reinstallation.
This is especially important because https://github.com/iNavFlight/inav/pull/10982 fixes a broken one-time cmake initialization check, and this patch ensures the correct behavior in conjunction with it.
arm-none-eabi-checks.cmakecontains functions to check and install correct version of gcc-arm-none-eabi, if specified version is not found. gcc_get_version() does not properly check current gcc version of gcc that was installed in tools/ directory.Current Behavior
gcc_get_version() only checks for compiler version of systemwide gcc-arm-none-eabi. Dockerfile does not install correct version into the image. Because version check fails every time, gcc is downloaded/installed always when cmake configuration step is invoked.
Steps to Reproduce
1. make sure cmake is not initialized 2. run ./build.sh , for example FLYWOOF745Expected behavior
gcc_get_version() checks for already downloaded compiler version. (from tools/ directory)
Thanks for your feedback. I've made PR with fixing this issue.