我正在使用一个生成compilation database for clang.
的Eclipse插件。我设法加载了托管配置并获得了要编译文件的名称。但是,我需要获取通过调用托管make系统确定的编译器命令(gcc,clang,vc等),因为我需要将这些命令保存到编译数据库中。
有什么方法可以插入CDT编译过程以访问编译器命令吗?
一些背景信息:我编写了自己的构建器插件,该插件在CDT构建器之前执行。插件本身并不那么壮观。但是,它能够加载所有生成可执行文件的构建配置及其相关的工具链,这意味着我可以利用它们。
构建配置存储在映射中,可以通过以下配置名称进行访问:Map<String, List<IConfiguration>> configurations = new TreeMap<>();
Delta访问者是Eclipse PDE示例中提供的访问者的简化:
private class SampleDeltaVisitor implements IResourceDeltaVisitor
{
private final CompilationDatabaseEditor editor;
public SampleDeltaVisitor(CompilationDatabaseEditor editor)
{
this.editor = editor;
}
@Override
public boolean visit(IResourceDelta delta) throws CoreException
{
IResource resource = delta.getResource();
if ((resource.getFileExtension() != null) && (SUPPORTED_FILE_TYPES.contains(resource.getFileExtension())))
{
switch (delta.getKind())
{
case IResourceDelta.ADDED:
System.out.println("Adding " + resource.getName());
editor.addEntry(resource.getFullPath().toOSString(), "", resource.getFullPath().removeLastSegments(1).toOSString());
break;
case IResourceDelta.REMOVED:
System.out.println("Removing " + resource.getName());
editor.removeEntry(resource.getFullPath().toOSString(), "", resource.getFullPath().removeLastSegments(1).toOSString());
break;
case IResourceDelta.CHANGED:
System.out.println("Changing " + resource.getName());
editor.removeEntry(resource.getFullPath().toOSString(), "", resource.getFullPath().removeLastSegments(1).toOSString());
editor.addEntry(resource.getFullPath().toOSString(), "", resource.getFullPath().removeLastSegments(1).toOSString());
break;
}
}
//return true to continue visiting children.
return true;
}
}