arm-cmake-toolchains icon indicating copy to clipboard operation
arm-cmake-toolchains copied to clipboard

Trailing space interferes with regex match for GCC version

Open crazybolillo opened this issue 2 years ago • 0 comments

Using Arch Linux and clang-arm-gcc-toolchain.cmake, the GCC version can't be parsed due to a trailing space on the regex. Here is the version string generated:

arm-none-eabi-gcc (Arch Repository) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Running cmake generates the following error, since no version can be extracted:

CMake Error at vendor/arm-cmake/clang-arm-gcc-toolchain.cmake:20 (string):
  string sub-command STRIP requires two arguments.

Playing around, I was able to match the version and fix the issue with the following diff:

diff --git a/clang-arm-gcc-toolchain.cmake b/clang-arm-gcc-toolchain.cmake
index 627b879..afacba6 100644
--- a/clang-arm-gcc-toolchain.cmake
+++ b/clang-arm-gcc-toolchain.cmake
@@ -16,7 +16,7 @@ execute_process(COMMAND ${ARM_GCC_C_COMPILER} -print-sysroot
 # get GNU ARM GCC version
 execute_process(COMMAND ${ARM_GCC_C_COMPILER} --version
     OUTPUT_VARIABLE ARM_GCC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
-string(REGEX MATCH " [0-9]+\.[0-9]+\.[0-9]+ " ARM_GCC_VERSION ${ARM_GCC_VERSION})
+string(REGEX MATCH " [0-9]+\.[0-9]+\.[0-9]+" ARM_GCC_VERSION ${ARM_GCC_VERSION})
 string(STRIP ${ARM_GCC_VERSION} ARM_GCC_VERSION)
 # set compiler triple
 set(triple ${TOOLCHAIN_TRIPLE})

Did not test it on other distributions but I wonder why the trailing spaces can't be removed altogether, it means the STRIP instruction after it would not be needed as well.

crazybolillo avatar Oct 04 '23 04:10 crazybolillo