use of org.eclipse.cdt.managedbuilder.core.IResourceInfo in project arduino-eclipse-plugin by Sloeber.
the class ArduinoGnuMakefileGenerator method addFragmentMakefileEntriesForSource.
/*
* (non-Javadoc Adds the entries for a particular source file to the
* fragment makefile
*
* @param buildVarToRuleStringMap map of build variable names to the list of
* files assigned to the variable
*
* @param ruleBuffer buffer to add generated nmakefile text to
*
* @param folder the top level build output directory
*
* @param relativePath build output directory relative path of the current
* output directory
*
* @param resource the source file for this invocation of the tool - this
* may be null for a generated output
*
* @param sourceLocation the full path of the source
*
* @param resConfig the IResourceConfiguration associated with this file or
* null
*
* @param varName the build variable to add this invocation's outputs to if
* <code>null</code>, use the file extension to find the name
*
* @param generatedSource if <code>true</code>, this file was generated by
* another tool in the tool-chain
*/
protected void addFragmentMakefileEntriesForSource(LinkedHashMap<String, String> buildVarToRuleStringMap, StringBuffer ruleBuffer, IFolder folder, String relativePath, IResource resource, IPath sourceLocation, IResourceInfo rcInfo, String varName, boolean generatedSource) {
// Determine which tool, if any, builds files with this extension
String ext = sourceLocation.getFileExtension();
ITool tool = null;
// Use the tool from the resource configuration if there is one
if (rcInfo instanceof IFileInfo) {
IFileInfo fi = (IFileInfo) rcInfo;
ITool[] tools = fi.getToolsToInvoke();
if (tools != null && tools.length > 0) {
tool = tools[0];
// if(!tool.getCustomBuildStep())
addToBuildVar(buildVarToRuleStringMap, ext, varName, relativePath, sourceLocation, generatedSource);
}
}
ToolInfoHolder h = getToolInfo(rcInfo.getPath());
ITool[] buildTools = h.buildTools;
// if(tool == null && rcInfo.getPath().segmentCount() != 0){
if (tool == null) {
h = getToolInfo(Path.EMPTY);
buildTools = h.buildTools;
for (ITool buildTool : buildTools) {
if (buildTool.buildsFileType(ext)) {
tool = buildTool;
addToBuildVar(buildVarToRuleStringMap, ext, varName, relativePath, sourceLocation, generatedSource);
break;
}
}
}
if (tool != null) {
// Generate the rule to build this source file
IInputType primaryInputType = tool.getPrimaryInputType();
IInputType inputType = tool.getInputType(ext);
if ((primaryInputType != null && !primaryInputType.getMultipleOfType()) || (inputType == null && tool != this.config.calculateTargetTool())) {
// Try to add the rule for the file
List<IPath> generatedOutputs = new ArrayList<>();
List<IPath> generatedDepFiles = new ArrayList<>();
// MODED moved JABA JAn Baeyens get the out type from the add
// source call
this.usedOutType = null;
addRuleForSource(relativePath, ruleBuffer, resource, sourceLocation, rcInfo, generatedSource, generatedDepFiles, generatedOutputs);
// to the variable
if (generatedDepFiles.size() > 0) {
for (int k = 0; k < generatedDepFiles.size(); k++) {
IPath generatedDepFile = generatedDepFiles.get(k);
addMacroAdditionFile(buildVarToRuleStringMap, getDepMacroName(ext).toString(), (generatedDepFile.isAbsolute() ? "" : DOTSLASH) + generatedDepFile.toOSString());
}
}
// If the generated outputs of this tool are input to another
// tool,
// 1. add the output to the appropriate macro
// 2. If the tool does not have multipleOfType input, generate
// the rule.
// IOutputType outType = tool.getPrimaryOutputType();
// MODED
// moved JABA JAn Baeyens get the out type from the add source
// call
String buildVariable = null;
if (this.usedOutType != null) {
if (tool.getCustomBuildStep()) {
// tool does not currently define a build variable
if (generatedOutputs.size() > 0) {
IPath firstOutput = generatedOutputs.get(0);
String firstExt = firstOutput.getFileExtension();
ToolInfoHolder tmpH = getFolderToolInfo(rcInfo.getPath());
ITool[] tmpBuildTools = tmpH.buildTools;
for (ITool tmpBuildTool : tmpBuildTools) {
if (tmpBuildTool.buildsFileType(firstExt)) {
String bV = tmpBuildTool.getPrimaryInputType().getBuildVariable();
if (bV.length() > 0) {
buildVariable = bV;
break;
}
}
}
}
} else {
buildVariable = this.usedOutType.getBuildVariable();
}
} else {
// For support of pre-CDT 3.0 integrations.
buildVariable = OBJS_MACRO;
}
for (int k = 0; k < generatedOutputs.size(); k++) {
IPath generatedOutput;
IResource generateOutputResource;
if (generatedOutputs.get(k).isAbsolute()) {
// TODO: Should we use relative paths when possible
// (e.g., see MbsMacroSupplier.calculateRelPath)
generatedOutput = generatedOutputs.get(k);
// If this file has an absolute path, then the
// generateOutputResource will not be correct
// because the file is not under the project. We use
// this resource in the calls to the dependency
// generator
generateOutputResource = this.project.getFile(generatedOutput);
} else {
generatedOutput = getPathForResource(this.project).append(getBuildWorkingDir()).append(generatedOutputs.get(k));
generateOutputResource = this.project.getFile(getBuildWorkingDir().append(generatedOutputs.get(k)));
}
IResourceInfo nextRcInfo;
if (rcInfo instanceof IFileInfo) {
nextRcInfo = this.config.getResourceInfo(rcInfo.getPath().removeLastSegments(1), false);
} else {
nextRcInfo = rcInfo;
}
addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer, folder, relativePath, generateOutputResource, generatedOutput, nextRcInfo, buildVariable, true);
}
}
} else {
// If this is a secondary input, add it to build vars
if (varName == null) {
for (ITool buildTool : buildTools) {
if (buildTool.isInputFileType(ext)) {
addToBuildVar(buildVarToRuleStringMap, ext, varName, relativePath, sourceLocation, generatedSource);
break;
}
}
} else // If this generated output is identified as a secondary output, add
// the file to the build variable
{
IOutputType[] secondaryOutputs = this.config.getToolChain().getSecondaryOutputs();
if (secondaryOutputs.length > 0) {
if (isSecondaryOutputVar(h, secondaryOutputs, varName)) {
addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, sourceLocation, generatedSource);
}
}
}
}
}
use of org.eclipse.cdt.managedbuilder.core.IResourceInfo in project linuxtools by eclipse.
the class CProjectBuildHelpers method setOptionInCDTTool.
/**
* <h1>Set Option in CDT</h1>
* Same as {@link #setOptionInCDT(IProject project, String optionIDString, boolean value) setOption_in } <br>
* except you can specify the parent tool manually (in case current implementation does not support what yon need.
*
* @param project an IProject
* @param optionIDString ID of option as defined in plugin.xml. e.g gnu.cpp.compiler.option.debugging.gprof
* @param value true/false
* @param toolSuperClassId
* Name of the tool where the option resides. E.g 'GCC C Compiler' or 'GCC C++ Compiler'. <br>
* To find out, check/uncheck an option, inspect the .cproject file, look for the option,<br>
* then see what tool it's under. See the name property
* @return true if all went well, false otherwise
*/
private static boolean setOptionInCDTTool(IProject project, String optionIDString, boolean value, String toolSuperClassId) {
// Get configuration
IConfiguration activeConf = helperGetActiveConfiguration(project);
// Get the ITool the option.
ITool gccCompileriTool = helperGetGccCompilerToolBySuperClass(toolSuperClassId, activeConf);
// Get Template Opiton.
// Get Option ~Immutable. This is like a 'templete' that we will base the actual option on.
IOption optionTemplate = gccCompileriTool.getOptionById(optionIDString);
// Check that we got a good option template.
if (optionTemplate == null) {
// This could fail if the specified option doesn't exist or is miss-spelled.
MessageDialogSyncedRunnable.openErrorSyncedRunnable(ProfilingMessages.errorTitle, ProfilingMessages.errorGetOptionTemplate);
return false;
}
// Get Actual Option
//
// Now we acquire an option that can be 'set' to something.
// In contrast to the immutable option above, if the user never checked/unchecked the option by hand,
// then the first time 'set' of this option will work correctly. Whereas
// the immutable option would only work if the user checked/unchecked the option by hand before.
IOption mutableOptionToSet = null;
try {
mutableOptionToSet = gccCompileriTool.getOptionToSet(optionTemplate, false);
mutableOptionToSet.setValue(value);
} catch (BuildException e) {
// This is reached if the template that was provided was bad.
MessageDialogSyncedRunnable.openErrorSyncedRunnable(ProfilingMessages.errorTitle, ProfilingMessages.errorGetOptionForWriting);
}
// get resource info. (where things are saved to).
IResourceInfo resourceInfo = activeConf.getResourceInfos()[0];
// Mark the option as enabled in the build manager.
ManagedBuildManager.setOption(resourceInfo, gccCompileriTool, mutableOptionToSet, true);
// Save this business to disk.
ManagedBuildManager.saveBuildInfo(project, true);
return true;
}
use of org.eclipse.cdt.managedbuilder.core.IResourceInfo in project arduino-eclipse-plugin by Sloeber.
the class ArduinoGnuMakefileGenerator method addSources.
/**
* Returns a <code>StringBuffer</code> containing makefile text for all of
* the sources contributed by a container (project directory/subdirectory)
* to the fragement makefile
*
* @param module
* project resource directory/subdirectory
* @return StringBuffer generated text for the fragement makefile
*/
protected StringBuffer addSources(IContainer module) throws CoreException {
// Calculate the new directory relative to the build output
IPath moduleRelativePath = module.getProjectRelativePath();
String relativePath = moduleRelativePath.toOSString();
relativePath += relativePath.length() == 0 ? "" : FILE_SEPARATOR;
// For build macros in the configuration, create a map which will map
// them
// to a string which holds its list of sources.
LinkedHashMap<String, String> buildVarToRuleStringMap = new LinkedHashMap<>();
// to the build macros
for (Entry<String, List<IPath>> entry : this.buildSrcVars.entrySet()) {
String macroName = entry.getKey();
addMacroAdditionPrefix(buildVarToRuleStringMap, macroName, null, false);
}
for (Entry<String, List<IPath>> entry : this.buildOutVars.entrySet()) {
String macroName = entry.getKey();
addMacroAdditionPrefix(buildVarToRuleStringMap, macroName, DOTSLASH + relativePath, false);
}
// String buffers
// Return buffer
StringBuffer buffer = new StringBuffer();
StringBuffer ruleBuffer = new StringBuffer(COMMENT_SYMBOL + WHITESPACE + ManagedMakeMessages.getResourceString(MOD_RULES) + NEWLINE);
// Visit the resources in this folder and add each one to a sources
// macro, and generate a build rule, if appropriate
IResource[] resources = module.members();
IResourceInfo rcInfo;
IFolder folder = this.project.getFolder(this.config.getName());
for (IResource resource : resources) {
if (resource.getType() == IResource.FILE) {
// Check whether this resource is excluded from build
IPath rcProjRelPath = resource.getProjectRelativePath();
if (!isSource(rcProjRelPath))
continue;
rcInfo = this.config.getResourceInfo(rcProjRelPath, false);
// if( (rcInfo.isExcluded()) )
// continue;
addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer, folder, relativePath, resource, getPathForResource(resource), rcInfo, null, false);
}
}
// Write out the macro addition entries to the buffer
buffer.append(writeAdditionMacros(buildVarToRuleStringMap));
return buffer.append(ruleBuffer + NEWLINE);
}
use of org.eclipse.cdt.managedbuilder.core.IResourceInfo in project arduino-eclipse-plugin by Sloeber.
the class ArduinoGnuMakefileGenerator method getAdditionalResourcesForSource.
/**
* Returns any additional resources specified for the tool in other
* InputType elements and AdditionalInput elements
*/
protected IPath[] getAdditionalResourcesForSource(ITool tool) {
List<IPath> allRes = new ArrayList<>();
IInputType[] types = tool.getInputTypes();
for (IInputType type : types) {
// Additional resources come from 2 places.
// 1. From AdditionalInput childen
IPath[] res = type.getAdditionalResources();
for (IPath re : res) {
allRes.add(re);
}
// 2. From InputTypes that other than the primary input type
if (!type.getPrimaryInput() && type != tool.getPrimaryInputType()) {
String var = type.getBuildVariable();
if (var != null && var.length() > 0) {
allRes.add(Path.fromOSString("$(" + type.getBuildVariable() + ")"));
} else {
// Use file extensions
String[] typeExts = type.getSourceExtensions(tool);
for (IResource projectResource : this.projectResources) {
if (projectResource.getType() == IResource.FILE) {
String fileExt = projectResource.getFileExtension();
if (fileExt == null) {
fileExt = new String();
}
for (String typeExt : typeExts) {
if (fileExt.equals(typeExt)) {
allRes.add(projectResource.getProjectRelativePath());
break;
}
}
}
}
}
// If an assignToOption has been specified, set the value of the
// option to the inputs
IOption assignToOption = tool.getOptionBySuperClassId(type.getAssignToOptionId());
IOption option = tool.getOptionBySuperClassId(type.getOptionId());
if (assignToOption != null && option == null) {
try {
int optType = assignToOption.getValueType();
IResourceInfo rcInfo = tool.getParentResourceInfo();
if (rcInfo != null) {
if (optType == IOption.STRING) {
String optVal = new String();
for (int j = 0; j < allRes.size(); j++) {
if (j != 0) {
optVal += " ";
}
String resPath = allRes.get(j).toString();
if (!resPath.startsWith("$(")) {
IResource addlResource = this.project.getFile(resPath);
if (addlResource != null) {
IPath addlPath = addlResource.getLocation();
if (addlPath != null) {
resPath = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), addlPath).toString();
}
}
}
optVal += ManagedBuildManager.calculateRelativePath(getTopBuildDir(), Path.fromOSString(resPath)).toString();
}
ManagedBuildManager.setOption(rcInfo, tool, assignToOption, optVal);
} else if (optType == IOption.STRING_LIST || optType == IOption.LIBRARIES || optType == IOption.OBJECTS || optType == IOption.INCLUDE_FILES || optType == IOption.LIBRARY_PATHS || optType == IOption.LIBRARY_FILES || optType == IOption.MACRO_FILES) {
// TODO: do we need to do anything with undefs
// here?
// Note that the path(s) must be translated from
// project relative
// to top build directory relative
String[] paths = new String[allRes.size()];
for (int j = 0; j < allRes.size(); j++) {
paths[j] = allRes.get(j).toString();
if (!paths[j].startsWith("$(")) {
IResource addlResource = this.project.getFile(paths[j]);
if (addlResource != null) {
IPath addlPath = addlResource.getLocation();
if (addlPath != null) {
paths[j] = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), addlPath).toString();
}
}
}
}
ManagedBuildManager.setOption(rcInfo, tool, assignToOption, paths);
} else if (optType == IOption.BOOLEAN) {
boolean b = false;
if (allRes.size() > 0)
b = true;
ManagedBuildManager.setOption(rcInfo, tool, assignToOption, b);
} else if (optType == IOption.ENUMERATED || optType == IOption.TREE) {
if (allRes.size() > 0) {
String s = allRes.get(0).toString();
ManagedBuildManager.setOption(rcInfo, tool, assignToOption, s);
}
}
allRes.clear();
}
} catch (BuildException ex) {
/* JABA is not going to write this code */
}
}
}
}
return allRes.toArray(new IPath[allRes.size()]);
}
Aggregations