Skip to content

Fix for the compiler path in compile_commands.json file #1138

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alicetrifu
Copy link
Contributor

Compiler path was wrongly created when anything was set on the "Prefix" option from "Cross Settings". The code needs to check if anything is set there before creating the default path for the compiler.

Copy link

github-actions bot commented Apr 10, 2025

Test Results

   602 files   -    34     602 suites   - 34   13m 17s ⏱️ - 23m 13s
10 222 tests  - 1 217  10 198 ✅  - 1 097  24 💤  - 120  0 ❌ ±0 
10 260 runs   - 1 194  10 236 ✅  - 1 076  24 💤  - 118  0 ❌ ±0 

Results for commit 2c4aa3f. ± Comparison against base commit 04105c2.

This pull request removes 1217 tests.
org.eclipse.cdt.debug.gdbjtag.core.tests.jtagdevice.GDBJtagDeviceContributionTest ‑ testGdbJtagDeviceContribution
org.eclipse.cdt.debug.gdbjtag.core.tests.launch.GDBJtagLaunchTest ‑ testGdbJtagLaunch[gdb]
org.eclipse.cdt.debug.gdbjtag.core.tests.launch.GDBJtagLaunchTest ‑ testGdbJtagLaunch[gdbserver]
org.eclipse.cdt.tests.dsf.gdb.tests.CommandLineArgsTest ‑ testSettingArgumentsWithQuotes[gdb]
org.eclipse.cdt.tests.dsf.gdb.tests.CommandLineArgsTest ‑ testSettingArgumentsWithQuotes[gdbserver]
org.eclipse.cdt.tests.dsf.gdb.tests.CommandLineArgsTest ‑ testSettingArgumentsWithSpecialSymbols[gdb]
org.eclipse.cdt.tests.dsf.gdb.tests.CommandLineArgsTest ‑ testSettingArgumentsWithSpecialSymbols[gdbserver]
org.eclipse.cdt.tests.dsf.gdb.tests.CommandLineArgsTest ‑ testSettingArgumentsWithSymbols[gdb]
org.eclipse.cdt.tests.dsf.gdb.tests.CommandLineArgsTest ‑ testSettingArgumentsWithSymbols[gdbserver]
org.eclipse.cdt.tests.dsf.gdb.tests.CommandLineArgsTest ‑ testSettingArgumentsWithTabs[gdb]
…

♻️ This comment has been updated with latest results.

@alicetrifu alicetrifu force-pushed the fixPathForCompiler1130 branch from 1151c1e to dabaf25 Compare April 10, 2025 14:34
Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like roughly the correct solution. Just some cleanup and review the caching.

@alicetrifu alicetrifu force-pushed the fixPathForCompiler1130 branch from 080da79 to d448a14 Compare April 10, 2025 15:57
Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well in the normal cases, but there are some corner cases that aren't handled well, see the individual comments.

@alicetrifu alicetrifu force-pushed the fixPathForCompiler1130 branch from d448a14 to 2c4aa3f Compare April 11, 2025 07:41
if (arguments.length <= 1) {
return ""; //$NON-NLS-1$
}
return String.join(" ", Arrays.copyOfRange(arguments, 1, arguments.length)); //$NON-NLS-1$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an invalid way of converting a list to a command line string. For example gcc "My file.c" -o "My file.o" would turn into "/usr/bin/gcc" My file.c -o My file.o which won't be interpreted properly. Please ensure quoting is done as appropriate and meets the spec of compile_commands.json linked here

org.eclipse.cdt.utils.CommandLineUtil.argumentsToString(Collection, boolean) may or may not actually match the requirements. I hope that it does as it would be simpler than implementing a new case. If argumentsToString does not meet requirements, I recommend adding a new method to CommandLineUtil and the appropriate tests to CommandLineUtilTest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @jonahgraham . Thank you for the review. I Think we need to fix this by implementing indeed a new case. I did this and also added a JUnit test especially for this so we can check this properly.

Please let me know if you think we need to do any other adjustments.

Thank you!

private String findCompilerInPath(ITool tool, IConfiguration config) {
if (toolMap.containsKey(tool)) {
return "\"" + toolMap.get(tool) + "\""; //$NON-NLS-1$//$NON-NLS-2$
private String findCompilerInPath(ITool tool, IConfiguration config, String compilerName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tool is now unused.

Suggested change
private String findCompilerInPath(ITool tool, IConfiguration config, String compilerName) {
private String findCompilerInPath(IConfiguration config, String compilerName) {

@@ -70,7 +71,7 @@ public final class CompilationDatabaseGenerator {
* Checked on each build
* Used before we look up the environment
*/
private Map<ITool, String> toolMap = new HashMap<>();
private Map<String, String> toolMap = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we now have a key of a string it is much less obvious what that key is, so please document it. Perhaps a line like this in the javadoc: Map of compiler name (as calculated by {@link #getCompilerName(String)}) to the absolute path of the compiler.

Compiler path was wrongly created when anything was set on the "Prefix"
option from "Cross Settings". The code needs to check if anything is set
there before creating the default path for the compiler.
@alicetrifu alicetrifu force-pushed the fixPathForCompiler1130 branch from 2c4aa3f to 84316a4 Compare April 24, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CDT fails to generate correct commands in compile_commands.json file
2 participants