use of org.eclipse.cdt.core.settings.model.util.IPathSettingsContainerVisitor in project arduino-eclipse-plugin by Sloeber.
the class ArduinoGnuMakefileGenerator method regenerateDependencies.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator#
* regenerateDependencies()
*/
@Override
public void regenerateDependencies(boolean force) throws CoreException {
// A hack for the pre-3.x GCC compilers is to put dummy targets for deps
final IWorkspaceRoot root = CCorePlugin.getWorkspace().getRoot();
final CoreException[] es = new CoreException[1];
this.toolInfos.accept(new IPathSettingsContainerVisitor() {
@SuppressWarnings("synthetic-access")
@Override
public boolean visit(PathSettingsContainer container) {
ToolInfoHolder h = (ToolInfoHolder) container.getValue();
// Collect the methods that will need to be called
List<String> depExts = new ArrayList<>();
IManagedDependencyGenerator2[] postProcessors = new IManagedDependencyGenerator2[h.buildTools.length];
boolean callPopulateDummyTargets = collectDependencyGeneratorInformation(h, depExts, postProcessors);
// Is there anyone to call if we do find dependency files?
if (!callPopulateDummyTargets) {
int i;
for (i = 0; i < postProcessors.length; i++) {
if (postProcessors[i] != null)
break;
}
if (i == postProcessors.length)
return true;
}
IResourceInfo rcInfo = ArduinoGnuMakefileGenerator.this.config.getResourceInfo(container.getPath(), false);
for (IPath path : getDependencyMakefiles(h)) {
// The path to search for the dependency makefile
IPath relDepFilePath = ArduinoGnuMakefileGenerator.this.topBuildDir.append(path);
IFile depFile = root.getFile(relDepFilePath);
if (depFile == null || !depFile.isAccessible())
continue;
try {
callDependencyPostProcessors(rcInfo, h, depFile, postProcessors, callPopulateDummyTargets, true);
} catch (CoreException e) {
es[0] = e;
return false;
}
}
return true;
}
});
if (es[0] != null)
throw es[0];
}
use of org.eclipse.cdt.core.settings.model.util.IPathSettingsContainerVisitor in project arduino-eclipse-plugin by Sloeber.
the class ArduinoGnuMakefileGenerator method populateSourcesMakefile.
protected void populateSourcesMakefile(IFile fileHandle) throws CoreException {
// Add the comment
StringBuilder builder1 = addDefaultHeader();
// Determine the set of macros
this.toolInfos.accept(new IPathSettingsContainerVisitor() {
@Override
public boolean visit(PathSettingsContainer container) {
ToolInfoHolder h = (ToolInfoHolder) container.getValue();
ITool[] buildTools = h.buildTools;
HashSet<String> handledInputExtensions = new HashSet<>();
String buildMacro;
for (ITool buildTool : buildTools) {
if (buildTool.getCustomBuildStep())
continue;
// Add the known sources macros
String[] extensionsList = buildTool.getAllInputExtensions();
for (String ext : extensionsList) {
// create a macro of the form "EXTENSION_SRCS :="
String extensionName = ext;
if (// !getOutputExtensions().contains(extensionName) &&
!handledInputExtensions.contains(extensionName)) {
handledInputExtensions.add(extensionName);
buildMacro = getSourceMacroName(extensionName).toString();
if (!ArduinoGnuMakefileGenerator.this.buildSrcVars.containsKey(buildMacro)) {
ArduinoGnuMakefileGenerator.this.buildSrcVars.put(buildMacro, new ArrayList<IPath>());
}
// Add any generated dependency file macros
IManagedDependencyGeneratorType depType = buildTool.getDependencyGeneratorForExtension(extensionName);
if (depType != null) {
int calcType = depType.getCalculatorType();
if (calcType == IManagedDependencyGeneratorType.TYPE_COMMAND || calcType == IManagedDependencyGeneratorType.TYPE_BUILD_COMMANDS || calcType == IManagedDependencyGeneratorType.TYPE_PREBUILD_COMMANDS) {
buildMacro = getDepMacroName(extensionName).toString();
if (!ArduinoGnuMakefileGenerator.this.buildDepVars.containsKey(buildMacro)) {
ArduinoGnuMakefileGenerator.this.buildDepVars.put(buildMacro, new ArduinoGnuDependencyGroupInfo(buildMacro, (calcType != IManagedDependencyGeneratorType.TYPE_PREBUILD_COMMANDS)));
}
if (!ArduinoGnuMakefileGenerator.this.buildOutVars.containsKey(buildMacro)) {
ArduinoGnuMakefileGenerator.this.buildOutVars.put(buildMacro, new ArrayList<IPath>());
}
}
}
}
}
// Add the specified output build variables
IOutputType[] outTypes = buildTool.getOutputTypes();
if (outTypes != null && outTypes.length > 0) {
for (IOutputType outputType : outTypes) {
buildMacro = outputType.getBuildVariable();
if (!ArduinoGnuMakefileGenerator.this.buildOutVars.containsKey(buildMacro)) {
ArduinoGnuMakefileGenerator.this.buildOutVars.put(buildMacro, new ArrayList<IPath>());
}
}
} else {
// For support of pre-CDT 3.0 integrations.
buildMacro = OBJS_MACRO;
if (!ArduinoGnuMakefileGenerator.this.buildOutVars.containsKey(buildMacro)) {
ArduinoGnuMakefileGenerator.this.buildOutVars.put(buildMacro, new ArrayList<IPath>());
}
}
}
return true;
}
});
// Add the macros to the makefile
for (Entry<String, List<IPath>> entry : this.buildSrcVars.entrySet()) {
String macroName = new Path(entry.getKey()).toOSString();
builder1.append(macroName + WHITESPACE + ":=" + WHITESPACE + NEWLINE);
}
Set<Entry<String, List<IPath>>> set = this.buildOutVars.entrySet();
for (Entry<String, List<IPath>> entry : set) {
String macroName = new Path(entry.getKey()).toOSString();
builder1.append(macroName + WHITESPACE + ":=" + WHITESPACE + NEWLINE);
}
// Add a list of subdirectories to the makefile
builder1.append(NEWLINE + addSubdirectories());
// Save the file
save(builder1, fileHandle);
}
use of org.eclipse.cdt.core.settings.model.util.IPathSettingsContainerVisitor in project arduino-eclipse-plugin by Sloeber.
the class ArduinoGnuMakefileGenerator method generateDependencies.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator
* #generateDependencies()
*/
@Override
public void generateDependencies() throws CoreException {
final PathSettingsContainer postProcs = PathSettingsContainer.createRootContainer();
// Note: PopulateDummyTargets is a hack for the pre-3.x GCC compilers
// Collect the methods that will need to be called
this.toolInfos.accept(new IPathSettingsContainerVisitor() {
@SuppressWarnings("synthetic-access")
@Override
public boolean visit(PathSettingsContainer container) {
ToolInfoHolder h = (ToolInfoHolder) container.getValue();
List<String> depExts = new ArrayList<>();
IManagedDependencyGenerator2[] postProcessors = new IManagedDependencyGenerator2[h.buildTools.length];
boolean callPopulateDummyTargets = collectDependencyGeneratorInformation(h, depExts, postProcessors);
// Is there anyone to call if we do find dependency files?
if (!callPopulateDummyTargets) {
int i;
for (i = 0; i < postProcessors.length; i++) {
if (postProcessors[i] != null)
break;
}
if (i == postProcessors.length)
return true;
}
PathSettingsContainer child = postProcs.getChildContainer(container.getPath(), true, true);
DepInfo di = new DepInfo();
di.depExts = depExts;
di.postProcessors = postProcessors;
di.callPopulateDummyTargets = callPopulateDummyTargets;
child.setValue(di);
return true;
}
});
IWorkspaceRoot root = CCorePlugin.getWorkspace().getRoot();
for (IResource res : getSubdirList()) {
// The builder creates a subdir with same name as source in the
// build location
IContainer subDir = (IContainer) res;
IPath projectRelativePath = subDir.getProjectRelativePath();
IResourceInfo rcInfo = this.config.getResourceInfo(projectRelativePath, false);
PathSettingsContainer cr = postProcs.getChildContainer(rcInfo.getPath(), false, true);
if (cr == null || cr.getValue() == null)
continue;
DepInfo di = (DepInfo) cr.getValue();
ToolInfoHolder h = getToolInfo(projectRelativePath);
IPath buildRelativePath = this.topBuildDir.append(projectRelativePath);
IFolder buildFolder = root.getFolder(buildRelativePath);
if (buildFolder == null)
continue;
if (!buildFolder.exists())
continue;
// Find all of the dep files in the generated subdirectories
IResource[] files = buildFolder.members();
for (IResource file : files) {
String fileExt = file.getFileExtension();
for (String ext : di.depExts) {
if (ext.equals(fileExt)) {
IFile depFile = root.getFile(file.getFullPath());
if (depFile == null)
continue;
callDependencyPostProcessors(rcInfo, h, depFile, di.postProcessors, di.callPopulateDummyTargets, false);
}
}
}
}
}
Aggregations