Skip to content

Commit bfce795

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 bfce795

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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)