1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-03-28 14:56:28 +01:00
cdt/jsoncdb
betamax e138646434
Ensure full ICBuildConfiguration environment is used during scanning (#1095)
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 #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 <jonah@kichwacoders.com>
2025-02-25 21:56:41 -05:00
..
aggregator Bump version to CDT 12.0.0 (#911) 2024-10-08 12:52:15 -04:00
org.eclipse.cdt.jsoncdb.arm Build with Tycho 4.0.6 (#715) 2024-02-22 21:38:57 -05:00
org.eclipse.cdt.jsoncdb.arm.tests Upgrade build.properties warnings to errors 2022-11-06 18:29:28 -05:00
org.eclipse.cdt.jsoncdb.core Ensure full ICBuildConfiguration environment is used during scanning (#1095) 2025-02-25 21:56:41 -05:00
org.eclipse.cdt.jsoncdb.core.doc Lower build.properties errors to warnings for some projects 2022-11-07 23:13:26 -05:00
org.eclipse.cdt.jsoncdb.core.tests Upgrade build.properties warnings to errors 2022-11-06 18:29:28 -05:00
org.eclipse.cdt.jsoncdb.core.ui Build with Tycho 4.0.6 (#715) 2024-02-22 21:38:57 -05:00
org.eclipse.cdt.jsoncdb.freescale Prepare repo for 11.7.0 development (#813) 2024-06-05 13:19:53 -04:00
org.eclipse.cdt.jsoncdb.freescale.tests #461 Add support for freescale compiler (#462) 2023-12-28 18:08:20 -05:00
org.eclipse.cdt.jsoncdb.hpenonstop Build with Tycho 4.0.6 (#715) 2024-02-22 21:38:57 -05:00
org.eclipse.cdt.jsoncdb.hpenonstop.tests Upgrade build.properties warnings to errors 2022-11-06 18:29:28 -05:00
org.eclipse.cdt.jsoncdb.intel Build with Tycho 4.0.6 (#715) 2024-02-22 21:38:57 -05:00
org.eclipse.cdt.jsoncdb.microsoft Upgrade build.properties warnings to errors 2022-11-06 18:29:28 -05:00
org.eclipse.cdt.jsoncdb.microsoft.tests Upgrade build.properties warnings to errors 2022-11-06 18:29:28 -05:00
org.eclipse.cdt.jsoncdb.nvidia Build with Tycho 4.0.6 (#715) 2024-02-22 21:38:57 -05:00
org.eclipse.cdt.jsoncdb.nvidia.tests Upgrade build.properties warnings to errors 2022-11-06 18:29:28 -05:00
pom.xml Bump version to CDT 12.0.0 (#911) 2024-10-08 12:52:15 -04:00