Skip to content

Commit f13b0cb

Browse files
committed
Generate compile_commands.json into standard build directory
That it is the file ends up in Debug/compile_commands.json instead of build/compile_commands.json. This lines up the behaviour of the generator with that of the code that generates a .clangd file in [ClangdConfigurationFileManager.java](https://github.com/eclipse-cdt/cdt-lsp/blob/ee297ee0ced1747352039e6ee25bcc80c10c7462/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/internal/config/ClangdConfigurationFileManager.java) This code already supports vendors overriding to supply their own (or extended) .clangd contents.
1 parent 1be4ce0 commit f13b0cb

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/CompilationDatabaseGenerationTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void testCompilationDatabaseGeneration() throws Exception {
4444
final IProject app = loadProject("helloworldC");
4545
setGenerateFileOptionEnabled(true);
4646
app.build(IncrementalProjectBuilder.FULL_BUILD, null);
47-
IFile compilationDatabase = app.getFile("build/compile_commands.json");
47+
IFile compilationDatabase = app.getFile("Debug/compile_commands.json");
4848
assertTrue(compilationDatabase.exists());
4949
}
5050

@@ -57,7 +57,7 @@ public void testJsonFormat() throws Exception {
5757
final IProject app = loadProject("helloworldC");
5858
setGenerateFileOptionEnabled(true);
5959
app.build(IncrementalProjectBuilder.FULL_BUILD, null);
60-
IFile commandsFile = app.getFile("build/compile_commands.json");
60+
IFile commandsFile = app.getFile("Debug/compile_commands.json");
6161
if (commandsFile.exists()) {
6262

6363
try (FileReader reader = new FileReader(commandsFile.getLocation().toFile())) {
@@ -88,7 +88,7 @@ public void testMultipleFiles() throws Exception {
8888
IFile aFile = ManagedBuildTestHelper.createFile(app, "src/newFile.c");
8989
setGenerateFileOptionEnabled(true);
9090
app.build(IncrementalProjectBuilder.FULL_BUILD, null);
91-
IFile commandsFile = app.getFile("build/compile_commands.json");
91+
IFile commandsFile = app.getFile("Debug/compile_commands.json");
9292
int numberOfElementsFound = 0;
9393
boolean helloworldCIsPresent = false;
9494
boolean newFileIsPresent = false;
@@ -122,7 +122,7 @@ public void isCPPFileAllowed() throws Exception {
122122
final IProject app = loadProject("helloworldCPP");
123123
setGenerateFileOptionEnabled(true);
124124
app.build(IncrementalProjectBuilder.FULL_BUILD, null);
125-
IFile commandsFile = app.getFile("build/compile_commands.json");
125+
IFile commandsFile = app.getFile("Debug/compile_commands.json");
126126
if (commandsFile.exists()) {
127127

128128
try (FileReader reader = new FileReader(commandsFile.getLocation().toFile())) {
@@ -151,7 +151,7 @@ public void testCompilationDatabaseGenerationNotEnabled() throws Exception {
151151
final IProject app = loadProject("helloworldC");
152152
setGenerateFileOptionEnabled(false);
153153
app.build(IncrementalProjectBuilder.FULL_BUILD, null);
154-
IFile compilationDatabase = app.getFile("build/compile_commands.json");
154+
IFile compilationDatabase = app.getFile("Debug/compile_commands.json");
155155
assertFalse(compilationDatabase.exists());
156156
}
157157

build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/jsoncdb/generator/CompilationDatabaseGenerator.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
public final class CompilationDatabaseGenerator {
5858

5959
private static final String CDB_FILENAME = "compile_commands.json"; //$NON-NLS-1$
60-
private static final String BUILD_FOLDER = "build"; //$NON-NLS-1$
6160
private static final String ERROR_MESSAGE = "Can not set contents to compile_commands.json file"; //$NON-NLS-1$
6261

6362
private IProject project;
@@ -77,14 +76,13 @@ public CompilationDatabaseGenerator(IProject proj, IConfiguration config) {
7776
* @param config
7877
*/
7978
public void generate() {
80-
81-
IPath buildDirectory = project.getFullPath()
82-
.append(IPath.SEPARATOR + CompilationDatabaseGenerator.BUILD_FOLDER);
79+
IPath buildDirectory = ManagedBuildManager.getBuildFullPath(configuration, configuration.getBuilder());
8380
IPath compilationDatabasePath = buildDirectory
8481
.append(IPath.SEPARATOR + CompilationDatabaseGenerator.CDB_FILENAME);
8582
try {
86-
if (!buildDirectory.toFile().exists()) {
87-
createDirectory(CompilationDatabaseGenerator.BUILD_FOLDER);
83+
IWorkspace workspace = ResourcesPlugin.getWorkspace();
84+
if (!workspace.getRoot().exists(buildDirectory)) {
85+
createDirectory(workspace.getRoot().getFolder(buildDirectory).getProjectRelativePath().toString());
8886
}
8987
IFile compileCommandsFile = createFile(compilationDatabasePath);
9088
addToCompilationdatabase(project, compileCommandsFile, configuration);

0 commit comments

Comments
 (0)