-
Notifications
You must be signed in to change notification settings - Fork 214
CMake built-ins detection successful when compile_commands.json compiler #1095
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
Conversation
Hi @jonahgraham
|
This code doesn't work right, interestingly it suffers from the same problem as the last point in this comment #1067 (comment) This is the return value of getenvp: Without your patch it looks like this: Sadly neither is correct. In the first the I think I will fix this @betamaxbandit - but I will send back to you for review. |
In the new code the Line 464 in 2a62d58
This code assumes that the value being prepended to is non-null. I will include the fix for this alongside this commit. |
Under certain conditions*, the compiler param in the command field of the compile_commands.json is a relative path rather than absolute. When this happens, the built-ins detection was not successful and the following exception was thrown: !ENTRY org.eclipse.cdt.core 4 0 2025-02-23 20:32:10.752 !MESSAGE Error: Cannot run program "gcc": Launching failed !STACK 0 java.io.IOException: Cannot run program "gcc": Launching failed at org.eclipse.cdt.utils.spawner.Spawner.exec(Spawner.java:450) at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:147) at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:134) at org.eclipse.cdt.utils.spawner.ProcessFactory$Builder.start(ProcessFactory.java:273) at org.eclipse.cdt.utils.spawner.ProcessFactory.exec(ProcessFactory.java:366) at org.eclipse.cdt.core.CommandLauncher.execute(CommandLauncher.java:189) at org.eclipse.cdt.jsoncdb.core.internal.builtins.CompilerBuiltinsDetector.detectBuiltins(CompilerBuiltinsDetector.java:111) at org.eclipse.cdt.jsoncdb.core.CompileCommandsJsonParser.detectBuiltins(CompileCommandsJsonParser.java:290) at org.eclipse.cdt.jsoncdb.core.CompileCommandsJsonParser.processJsonFile(CompileCommandsJsonParser.java:193) at org.eclipse.cdt.jsoncdb.core.CompileCommandsJsonParser.parse(CompileCommandsJsonParser.java:455) at org.eclipse.cdt.cmake.core.CMakeBuildConfiguration.processCompileCommandsFile(CMakeBuildConfiguration.java:361) at org.eclipse.cdt.cmake.core.CMakeBuildConfiguration.build(CMakeBuildConfiguration.java:241) This meant that source file includes were not indexed and could not be opened using Open Declaration (F3) and info markers of the following type appeared in the Problems view: gcc -E -P -dM -Wp,-v "...extCmakegcc\\build\\cmake.run.win32.x86_64.Local\\detect_compiler_builtins.c" Cannot run program "gcc": Launching failed Error: Program "gcc" not found in PATH PATH=[...] extCmakegcc Unknown Compiler Builtins Detector Problem gcc -E -P -dM -Wp,-v "...extCmakegcc\\build\\cmake.run.win32.x86_64.Local\\detect_compiler_builtins.c" Cannot run program "gcc": Launching failed This patch fixes the environment issue for Core Build projects, by calling ICBuildConfiguration.setBuildEnvironment(Map<String, String>) as part of the built-ins detection setup, thereby supporting absolute and relative compiler paths. Addresses Issue: CDT CMake Improvements eclipse-cdt#1000, IDE-82683-REQ-011 Source code navigation and Built-ins detection *: CMake produces relative compiler path When the CMAKE_<LANG>_COMPILER variable (eg CMAKE_C_COMPILER) is set in the CMakeLists.txt *after* the project() or language commands, it causes a relative path to be used. For example, in the CMakeLists.txt below, gcc is set after project() command: cmake_minimum_required(VERSION 3.10) project (track2) set(CMAKE_C_COMPILER gcc) add_executable(${PROJECT_NAME} track2.c) The above script creates a relative compiler path in compile_commands.json: "command": "gcc -O3 -DNDEBUG -o ... Normally the CMAKE_C_COMPILER variable should be set before the project() comannd. "command": "C:\\msys64\\mingw64\\bin\\c++.exe -IC... Co-authored-by: Jonah Graham <[email protected]>
53d79e8
to
6451743
Compare
Hmm, I never see a null at the end of PATH returned from getEnvp, when building on Windows. Maybe the setup is different on Linux. I downloaded your latest PS for this change and applied changes from:
Maybe I'm missing something. |
@betamaxbandit and I reviewed this together in a pair programming session |
path is relative
Under certain conditions*, the compiler param in the command field of the compile_commands.json is a relative path rather than absolute. When this happens, the built-ins detection was not successful and the following exception was thrown:
!ENTRY org.eclipse.cdt.core 4 0 2025-02-23 20:32:10.752 !MESSAGE Error: Cannot run program "gcc": Launching failed !STACK 0
java.io.IOException: Cannot run program "gcc": Launching failed
at org.eclipse.cdt.utils.spawner.Spawner.exec(Spawner.java:450)
at org.eclipse.cdt.utils.spawner.Spawner.(Spawner.java:147)
at org.eclipse.cdt.utils.spawner.Spawner.(Spawner.java:134)
at org.eclipse.cdt.utils.spawner.ProcessFactory$Builder.start(ProcessFactory.java:273)
at org.eclipse.cdt.utils.spawner.ProcessFactory.exec(ProcessFactory.java:366)
at org.eclipse.cdt.core.CommandLauncher.execute(CommandLauncher.java:189)
at org.eclipse.cdt.jsoncdb.core.internal.builtins.CompilerBuiltinsDetector.detectBuiltins(CompilerBuiltinsDetector.java:111)
at org.eclipse.cdt.jsoncdb.core.CompileCommandsJsonParser.detectBuiltins(CompileCommandsJsonParser.java:290)
at org.eclipse.cdt.jsoncdb.core.CompileCommandsJsonParser.processJsonFile(CompileCommandsJsonParser.java:193)
at org.eclipse.cdt.jsoncdb.core.CompileCommandsJsonParser.parse(CompileCommandsJsonParser.java:455)
at org.eclipse.cdt.cmake.core.CMakeBuildConfiguration.processCompileCommandsFile(CMakeBuildConfiguration.java:361)
at org.eclipse.cdt.cmake.core.CMakeBuildConfiguration.build(CMakeBuildConfiguration.java:241)
This meant that source file includes were not indexed and could not be opened using Open Declaration (F3) and info markers of the following type appeared in the Problems view:
gcc -E -P -dM -Wp,-v
"...extCmakegcc\build\cmake.run.win32.x86_64.Local\detect_compiler_builtins.c"
Cannot run program "gcc": Launching failed
Error: Program "gcc" not found in PATH
PATH=[...]
extCmakegcc Unknown Compiler Builtins Detector Problem
gcc -E -P -dM -Wp,-v
"...extCmakegcc\build\cmake.run.win32.x86_64.Local\detect_compiler_builtins.c"
Cannot run program "gcc": Launching failed
This patch fixes the environment issue for Core Build projects, by calling ICBuildConfiguration.setBuildEnvironment(Map<String, String>) as part of the built-ins detection setup, thereby supporting absolute and relative compiler paths.
Addresses Issue: CDT CMake Improvements #1000, IDE-82683-REQ-011 Source code navigation and Built-ins detection
*: CMake produces relative compiler path
When the CMAKE__COMPILER variable (eg CMAKE_C_COMPILER) is set in the CMakeLists.txt after the project() or language commands, it causes a relative path to be used. For example, in the CMakeLists.txt below, gcc is set after project() command:
cmake_minimum_required(VERSION 3.10)
project (track2)
set(CMAKE_C_COMPILER gcc)
add_executable(${PROJECT_NAME} track2.c)
The above script creates a relative compiler path in compile_commands.json:
"command": "gcc -O3 -DNDEBUG -o ...
Normally the CMAKE_C_COMPILER variable should be set before the project() comannd.
"command": "C:\msys64\mingw64\bin\c++.exe -IC...