Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added feature to generate compile_commands.json file, in the Common
Builder. Created a new extension point to provide the opportunity to incorporate additional information into the file
- Loading branch information
1 parent
2e38e74
commit beb9200
Showing
9 changed files
with
705 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
build/org.eclipse.cdt.managedbuilder.core/schema/compilationDatabaseContributor.exsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!-- Schema file written by PDE --> | ||
<schema targetNamespace="org.eclipse.cdt.managedbuilder.core" xmlns="http://www.w3.org/2001/XMLSchema"> | ||
<annotation> | ||
<appInfo> | ||
<meta.schema plugin="org.eclipse.cdt.managedbuilder.core" id="compilationDatabaseContributor" name="Compilation Database Contributor"/> | ||
</appInfo> | ||
<documentation> | ||
This extension point allows to add specific information to compile_commands.json file. | ||
</documentation> | ||
</annotation> | ||
|
||
<element name="extension"> | ||
<annotation> | ||
<appInfo> | ||
<meta.element /> | ||
</appInfo> | ||
</annotation> | ||
<complexType> | ||
<sequence minOccurs="1" maxOccurs="unbounded"> | ||
<choice> | ||
<element ref="compilationDatabase"/> | ||
</choice> | ||
</sequence> | ||
<attribute name="point" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="id" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="name" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
<appInfo> | ||
<meta.attribute translatable="true"/> | ||
</appInfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<element name="compilationDatabase"> | ||
<annotation> | ||
<documentation> | ||
Compilation Database for C/C++ projects | ||
</documentation> | ||
</annotation> | ||
<complexType> | ||
<attribute name="toolchainID" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
Toolchain ID | ||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="runner" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
<appInfo> | ||
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.managedbuilder.core.jsoncdb.generator.api.ICompilationDatabaseContributor"/> | ||
</appInfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
|
||
|
||
|
||
|
||
|
||
</schema> |
22 changes: 22 additions & 0 deletions
22
....core/src/org/eclipse/cdt/managedbuilder/core/jsoncdb/CompilationDatabaseInformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023, 2024 Renesas Electronics Corp. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
********************************************************************************/ | ||
package org.eclipse.cdt.managedbuilder.core.jsoncdb; | ||
|
||
/** | ||
* The compilation database array of “command objects” members to be used for | ||
* the extension point | ||
* directory: The working directory of the compilation. | ||
* command: The compile command. file: The main translation unit source | ||
* processed by this compilation step. | ||
* @since 9.7 | ||
*/ | ||
|
||
public record CompilationDatabaseInformation(String directory, String command, String file) { | ||
} |
33 changes: 33 additions & 0 deletions
33
...core/src/org/eclipse/cdt/managedbuilder/core/jsoncdb/ICompilationDatabaseContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023, 2024 Renesas Electronics Europe. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
********************************************************************************/ | ||
package org.eclipse.cdt.managedbuilder.core.jsoncdb; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.cdt.managedbuilder.core.IConfiguration; | ||
import org.eclipse.jdt.annotation.NonNull; | ||
|
||
/** | ||
* @since 9.7 | ||
*/ | ||
public interface ICompilationDatabaseContributor { | ||
|
||
/** | ||
* @param config | ||
* Adds a new list of files to the compilation database | ||
* Implementors should provide concrete implementations of this | ||
* interface. IConfiguration will be taken as input, accessing the project and will generate a list of | ||
* additional files to be added to compile_commands.json | ||
* @return A non-null list of files that will be added to compilation database | ||
*/ | ||
@NonNull | ||
public List<CompilationDatabaseInformation> getAdditionalFiles(@NonNull IConfiguration config); | ||
|
||
} |
137 changes: 137 additions & 0 deletions
137
...pse/cdt/managedbuilder/core/jsoncdb/generator/CompilationDatabaseContributionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023, 2024 Renesas Electronics Corp. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
********************************************************************************/ | ||
package org.eclipse.cdt.managedbuilder.core.jsoncdb.generator; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.cdt.managedbuilder.core.IConfiguration; | ||
import org.eclipse.cdt.managedbuilder.core.IToolChain; | ||
import org.eclipse.cdt.managedbuilder.core.jsoncdb.CompilationDatabaseInformation; | ||
import org.eclipse.cdt.managedbuilder.core.jsoncdb.ICompilationDatabaseContributor; | ||
import org.eclipse.core.runtime.Assert; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IConfigurationElement; | ||
import org.eclipse.core.runtime.IExtension; | ||
import org.eclipse.core.runtime.IExtensionPoint; | ||
import org.eclipse.core.runtime.Platform; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.jdt.annotation.NonNull; | ||
|
||
final class CompilationDatabaseContributionManager { | ||
private static final String ATTRIB_RUNNER = "runner"; //$NON-NLS-1$ | ||
private static final String ATTRIB_TOOLCHAIN_ID = "toolchainID"; //$NON-NLS-1$ | ||
private static final String ID_COMPILATIONDATABASE = "compilationDatabase"; //$NON-NLS-1$ | ||
private static final String EXTENSION_ID = "compilationDatabaseContributor"; //$NON-NLS-1$ | ||
@NonNull | ||
private final Map<String, ICompilationDatabaseContributor> loadedInstances; | ||
|
||
private class EmptyCompilationDatabaseContributor implements ICompilationDatabaseContributor { | ||
|
||
@Override | ||
public final @NonNull List<CompilationDatabaseInformation> getAdditionalFiles(@NonNull IConfiguration config) { | ||
return Collections.emptyList(); | ||
} | ||
} | ||
|
||
private Map<String, IConfigurationElement> factoryExtensions; | ||
private static CompilationDatabaseContributionManager instance; | ||
|
||
private CompilationDatabaseContributionManager() { | ||
factoryExtensions = new HashMap<>(); | ||
loadedInstances = new HashMap<>(); | ||
initalise(); | ||
} | ||
|
||
public static synchronized CompilationDatabaseContributionManager getInstance() { | ||
if (CompilationDatabaseContributionManager.instance == null) { | ||
CompilationDatabaseContributionManager.instance = new CompilationDatabaseContributionManager(); | ||
} | ||
return CompilationDatabaseContributionManager.instance; | ||
} | ||
|
||
private void initalise() { | ||
Map<String, IConfigurationElement> loadedExtension = new HashMap<>(); | ||
|
||
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint( | ||
"org.eclipse.cdt.managedbuilder.core", CompilationDatabaseContributionManager.EXTENSION_ID); //$NON-NLS-1$ | ||
if (extension != null) { | ||
IExtension[] extensions = extension.getExtensions(); | ||
for (IExtension extension2 : extensions) { | ||
IConfigurationElement[] configElements = extension2.getConfigurationElements(); | ||
for (IConfigurationElement configElement : configElements) { | ||
if (CompilationDatabaseContributionManager.ID_COMPILATIONDATABASE.equals(configElement.getName())) { // $NON-NLS-1$ | ||
String toolchainId = configElement | ||
.getAttribute(CompilationDatabaseContributionManager.ATTRIB_TOOLCHAIN_ID); | ||
String className = configElement | ||
.getAttribute(CompilationDatabaseContributionManager.ATTRIB_RUNNER); | ||
if (toolchainId != null && className != null) { | ||
loadedExtension.put(toolchainId, configElement); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
factoryExtensions = loadedExtension; | ||
} | ||
|
||
/** | ||
* Get the Code Assist tool with the specified id | ||
* | ||
* @param id | ||
* @return Tool extension or a list with no element if not found. | ||
* @throws CoreException | ||
*/ | ||
|
||
@NonNull | ||
public synchronized ICompilationDatabaseContributor getCompilationDatabaseContributor( | ||
@NonNull IConfiguration config) { | ||
IToolChain toolChain = config.getToolChain(); | ||
while (toolChain != null) { | ||
String toolchainId = toolChain.getBaseId(); | ||
if (loadedInstances.containsKey(toolchainId)) { | ||
ICompilationDatabaseContributor contributor = loadedInstances.get(toolchainId); | ||
Assert.isNotNull(contributor); | ||
return contributor; | ||
} else if (factoryExtensions.containsKey(toolchainId)) { | ||
return createCdbInstance(toolchainId); | ||
} else { | ||
toolChain = toolChain.getSuperClass(); | ||
} | ||
} | ||
return new EmptyCompilationDatabaseContributor(); | ||
} | ||
|
||
@NonNull | ||
private ICompilationDatabaseContributor createCdbInstance(String toolchainId) { | ||
IConfigurationElement ele = factoryExtensions.get(toolchainId); | ||
if (ele != null) { | ||
ICompilationDatabaseContributor loaded = null; | ||
try { | ||
loaded = (ICompilationDatabaseContributor) ele | ||
.createExecutableExtension(CompilationDatabaseContributionManager.ATTRIB_RUNNER); | ||
|
||
} catch (CoreException e) { | ||
Platform.getLog(getClass()).log(Status.error("Not able to create instance", e)); //$NON-NLS-1$ | ||
} | ||
if (loaded == null) { | ||
loaded = new EmptyCompilationDatabaseContributor(); | ||
} | ||
loadedInstances.put(toolchainId, loaded); | ||
return loaded; | ||
} | ||
|
||
return new EmptyCompilationDatabaseContributor(); | ||
} | ||
|
||
} |
Oops, something went wrong.