use of org.eclipse.cdt.managedbuilder.core.IOption in project arduino-eclipse-plugin by Sloeber.
the class ArduinoGnuMakefileGenerator method calculateOutputsForSource.
/**
* Returns the output <code>IPath</code>s for this invocation of the tool
* with the specified source file The priorities for determining the names
* of the outputs of a tool are: 1. If the tool is the build target and
* primary output, use artifact name & extension - This case does not apply
* here... 2. If an option is specified, use the value of the option 3. If a
* nameProvider is specified, call it 4. If outputNames is specified, use it
* 5. Use the name pattern to generate a transformation macro so that the
* source names can be transformed into the target names using the built-in
* string substitution functions of <code>make</code>.
*
* @param relativePath
* build output directory relative path of the current output
* directory
* @param ruleOutputs
* Vector of rule IPaths that are relative to the build directory
* @param enumeratedPrimaryOutputs
* Vector of IPaths of primary outputs that are relative to the
* build directory
* @param enumeratedSecondaryOutputs
* Vector of IPaths of secondary outputs that are relative to the
* build directory
*/
protected void calculateOutputsForSource(ITool tool, String relativePath, IResource resource, IPath sourceLocation, List<IPath> ruleOutputs, List<IPath> enumeratedPrimaryOutputs, List<IPath> enumeratedSecondaryOutputs) {
String inExt = sourceLocation.getFileExtension();
String outExt = tool.getOutputExtension(inExt);
// IResourceInfo rcInfo = tool.getParentResourceInfo();
IOutputType[] outTypes = tool.getOutputTypes();
if (outTypes != null && outTypes.length > 0) {
for (IOutputType type : outTypes) {
boolean primaryOutput = (type == tool.getPrimaryOutputType());
// if (primaryOutput && ignorePrimary) continue;
String outputPrefix = type.getOutputPrefix();
// if (config != null) {
try {
if (containsSpecialCharacters(sourceLocation.toOSString())) {
outputPrefix = ManagedBuildManager.getBuildMacroProvider().resolveValue(outputPrefix, new String(), " ", IBuildMacroProvider.CONTEXT_CONFIGURATION, this.config);
} else {
outputPrefix = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(outputPrefix, new String(), " ", IBuildMacroProvider.CONTEXT_CONFIGURATION, this.config);
}
} catch (BuildMacroException e) {
/* JABA is not going to write this code */
}
// }
boolean multOfType = type.getMultipleOfType();
IOption option = tool.getOptionBySuperClassId(type.getOptionId());
IManagedOutputNameProvider nameProvider = type.getNameProvider();
String[] outputNames = type.getOutputNames();
// 2. If an option is specified, use the value of the option
if (option != null) {
try {
List<String> outputList = new ArrayList<>();
int optType = option.getValueType();
if (optType == IOption.STRING) {
outputList.add(outputPrefix + option.getStringValue());
} 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) {
@SuppressWarnings("unchecked") List<String> value = (List<String>) option.getValue();
outputList = value;
((Tool) tool).filterValues(optType, outputList);
// Add outputPrefix to each if necessary
if (outputPrefix.length() > 0) {
for (int j = 0; j < outputList.size(); j++) {
outputList.set(j, outputPrefix + outputList.get(j));
}
}
}
for (int j = 0; j < outputList.size(); j++) {
String outputName = outputList.get(j);
// names
try {
String resolved = null;
if (containsSpecialCharacters(sourceLocation.toOSString())) {
resolved = ManagedBuildManager.getBuildMacroProvider().resolveValue(outputName, new String(), " ", IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, null, option, tool));
} else {
resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(outputName, new String(), " ", IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, null, option, tool));
}
if ((resolved = resolved.trim()).length() > 0)
outputName = resolved;
} catch (BuildMacroException e) {
/* JABA is not going to write this code */
}
IPath outPath = Path.fromOSString(outputName);
// relative path of this output directory
if (outPath.segmentCount() == 1) {
outPath = Path.fromOSString(relativePath + outputList.get(j));
}
if (primaryOutput) {
ruleOutputs.add(j, outPath);
enumeratedPrimaryOutputs.add(j, resolvePercent(outPath, sourceLocation));
} else {
ruleOutputs.add(outPath);
enumeratedSecondaryOutputs.add(resolvePercent(outPath, sourceLocation));
}
}
} catch (BuildException ex) {
/* JABA is not going to write this code */
}
} else // 3. If a nameProvider is specified, call it
if (nameProvider != null) {
IPath[] inPaths = new IPath[1];
// ;
inPaths[0] = resource.getProjectRelativePath();
// sourceLocation.removeFirstSegments(project.getLocation().segmentCount());
IPath[] outPaths = null;
try {
IManagedOutputNameProviderJaba newNameProvider = (IManagedOutputNameProviderJaba) nameProvider;
outPaths = newNameProvider.getOutputNames(this.project, this.config, tool, inPaths);
} catch (Exception e) {
// The provided class is not a
// IManagedOutputNameProviderJaba class;
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, //
"The provided class is not of type IManagedOutputNameProviderJaba", e));
}
if (outPaths != null) {
// MODDED BY JABA ADDED to handle
// null as return value
// MODDED By JABA added to
this.usedOutType = type;
// command line
for (int j = 0; j < outPaths.length; j++) {
IPath outPath = outPaths[j];
String outputName = outPaths[j].toOSString();
// names
try {
String resolved = null;
if (containsSpecialCharacters(sourceLocation.toOSString())) {
resolved = ManagedBuildManager.getBuildMacroProvider().resolveValue(outputName, "", " ", IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, null, option, tool));
} else {
resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(outputName, "", " ", IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, null, option, tool));
}
if ((resolved = resolved.trim()).length() > 0)
outputName = resolved;
} catch (BuildMacroException e) {
// JABA is not
// going to write
// this code
}
// relative path of this output directory
if (outPath.segmentCount() == 1) {
outPath = Path.fromOSString(relativePath + outPath.toOSString());
}
if (type.getPrimaryOutput()) {
ruleOutputs.add(j, outPath);
enumeratedPrimaryOutputs.add(j, resolvePercent(outPath, sourceLocation));
} else {
ruleOutputs.add(outPath);
enumeratedSecondaryOutputs.add(resolvePercent(outPath, sourceLocation));
}
}
}
// MODDED BY JABA ADDED
} else // 4. If outputNames is specified, use it
if (outputNames != null) {
for (int j = 0; j < outputNames.length; j++) {
String outputName = outputNames[j];
try {
// try to resolve the build macros in the output
// names
String resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(outputName, new String(), " ", IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, null, option, tool));
if ((resolved = resolved.trim()).length() > 0)
outputName = resolved;
} catch (BuildMacroException e) {
/* JABA is not going to write this code */
}
IPath outPath = Path.fromOSString(outputName);
// path of this output directory
if (outPath.segmentCount() == 1) {
outPath = Path.fromOSString(relativePath + outPath.toOSString());
}
if (primaryOutput) {
ruleOutputs.add(j, outPath);
enumeratedPrimaryOutputs.add(j, resolvePercent(outPath, sourceLocation));
} else {
ruleOutputs.add(outPath);
enumeratedSecondaryOutputs.add(resolvePercent(outPath, sourceLocation));
}
}
} else {
// <code>make</code>.
if (multOfType) {
// This case is not handled - a nameProvider or
// outputNames must be specified
// TODO - report error
} else {
String namePattern = type.getNamePattern();
IPath namePatternPath = null;
if (namePattern == null || namePattern.length() == 0) {
namePattern = relativePath + outputPrefix + IManagedBuilderMakefileGenerator.WILDCARD;
if (outExt != null && outExt.length() > 0) {
namePattern += DOT + outExt;
}
namePatternPath = Path.fromOSString(namePattern);
} else {
if (outputPrefix.length() > 0) {
namePattern = outputPrefix + namePattern;
}
namePatternPath = Path.fromOSString(namePattern);
// relative path of this output directory
if (namePatternPath.segmentCount() == 1) {
namePatternPath = Path.fromOSString(relativePath + namePatternPath.toOSString());
}
}
if (primaryOutput) {
ruleOutputs.add(0, namePatternPath);
enumeratedPrimaryOutputs.add(0, resolvePercent(namePatternPath, sourceLocation));
} else {
ruleOutputs.add(namePatternPath);
enumeratedSecondaryOutputs.add(resolvePercent(namePatternPath, sourceLocation));
}
}
}
}
} else {
// For support of pre-CDT 3.0 integrations.
// NOTE WELL: This only supports the case of a single "target tool"
// that consumes exactly all of the object files, $OBJS, produced
// by other tools in the build and produces a single output.
// In this case, the output file name is the input file name with
// the output extension.
// if (!ignorePrimary) {
String outPrefix = tool.getOutputPrefix();
IPath outPath = Path.fromOSString(relativePath + outPrefix + WILDCARD);
outPath = outPath.addFileExtension(outExt);
ruleOutputs.add(0, outPath);
enumeratedPrimaryOutputs.add(0, resolvePercent(outPath, sourceLocation));
// }
}
}
use of org.eclipse.cdt.managedbuilder.core.IOption 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()]);
}
use of org.eclipse.cdt.managedbuilder.core.IOption in project usbdm-eclipse-plugins by podonoghue.
the class UsbdmGCCSpecsRunSIProvider method getToolPrefix.
/**
* @param project The project to look in for options
* @return The prefix for the build tools
*/
private String getToolPrefix(IProject project) {
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
if (info == null) {
return "";
}
IConfiguration cfg = info.getDefaultConfiguration();
// System.err.println("UsbdmGCCSpecsRunSIProvider.initialize() Found IConfiguration = " + cfg.getName());
IToolChain toolChain = cfg.getToolChain();
// System.err.println("UsbdmGCCSpecsRunSIProvider.initialize() Found toolChain = " + toolChain.getName());
// Find selected build tool (either ARM or Coldfire)
IOption buildToolOption = toolChain.getOptionBySuperClassId(UsbdmConstants.ARM_BUILDTOOLS_OPTIONS);
if (buildToolOption == null) {
buildToolOption = toolChain.getOptionBySuperClassId(UsbdmConstants.COLDFIRE_BUILDTOOLS_OPTIONS);
}
if (buildToolOption == null) {
return "";
}
// Get build path variable
ToolInformationData toolData = ToolInformationData.getToolInformationTable().get(buildToolOption.getValue().toString());
if (toolData == null) {
return "";
}
String toolPrefixVariableId = toolData.getPrefixVariableName();
if (toolPrefixVariableId == null) {
return "";
}
UsbdmSharedSettings settings = UsbdmSharedSettings.getSharedSettings();
String toolPrefix = null;
if (settings != null) {
toolPrefix = settings.get(toolPrefixVariableId);
}
if (toolPrefix == null) {
toolPrefix = "Tool Prefix not set";
return "";
}
// System.err.println("UsbdmGCCSpecsRunSIProvider.initialize() Found tool prefix = " + toolPrefix);
return toolPrefix;
}
use of org.eclipse.cdt.managedbuilder.core.IOption in project usbdm-eclipse-plugins by podonoghue.
the class ApplyOptions method addToOptionForResourceConfig.
// static void listArray(String values[]) {
// for (String s:values) {
// System.err.println("\'"+s+"\'");
// }
// }
private boolean addToOptionForResourceConfig(String id, String[] value, boolean replace, IResourceConfiguration resourceConfig, IOption[] options, IHoldsOptions optionHolder) throws Exception {
boolean modified = false;
String lowerId = id.toLowerCase();
for (IOption option : options) {
if (option.getBaseId().toLowerCase().matches(lowerId)) {
int optionType = option.getBasicValueType();
if ((optionType == IOption.STRING)) {
String newValue = "";
if (!replace) {
// Append to existing values
newValue = option.getStringValue();
}
if (value.length > 0) {
newValue = newValue + value[0];
}
ManagedBuildManager.setOption(resourceConfig, optionHolder, option, newValue);
modified = true;
} else if ((optionType == IOption.ENUMERATED)) {
ManagedBuildManager.setOption(resourceConfig, optionHolder, option, value[0]);
modified = true;
} else if ((optionType == IOption.BOOLEAN)) {
ManagedBuildManager.setOption(resourceConfig, optionHolder, option, value[0].equals("true"));
modified = true;
} else if ((optionType == IOption.STRING_LIST)) {
String[] oldValues = new String[] {};
if (!replace) {
// Append to existing values
oldValues = option.getBasicStringListValue();
}
ManagedBuildManager.setOption(resourceConfig, optionHolder, option, appendArrays(oldValues, value));
modified = true;
} else {
// $NON-NLS-1$ //$NON-NLS-2$
throw new ProcessFailureException("Unexpected option type " + optionType);
}
}
}
return modified;
}
use of org.eclipse.cdt.managedbuilder.core.IOption in project usbdm-eclipse-plugins by podonoghue.
the class ApplyOptions method addToOptionForConfig.
private boolean addToOptionForConfig(String id, String[] value, boolean replace, IConfiguration config, IOption[] options, IHoldsOptions optionHolder) throws Exception {
boolean modified = false;
String lowerId = id.toLowerCase();
for (IOption option : options) {
if (option.getBaseId().toLowerCase().matches(lowerId)) {
int optionType = option.getBasicValueType();
if ((optionType == IOption.STRING)) {
String newValue = "";
if (!replace) {
// Append to existing values
newValue = option.getStringValue();
}
if (value.length > 0) {
newValue = newValue + value[0];
}
ManagedBuildManager.setOption(config, optionHolder, option, newValue);
modified = true;
} else if ((optionType == IOption.ENUMERATED)) {
ManagedBuildManager.setOption(config, optionHolder, option, value[0]);
modified = true;
} else if ((optionType == IOption.BOOLEAN)) {
ManagedBuildManager.setOption(config, optionHolder, option, value[0].equals("true"));
modified = true;
} else if ((optionType == IOption.STRING_LIST)) {
String[] oldValues = new String[] {};
if (!replace) {
// Append to existing values
oldValues = option.getBasicStringListValue();
}
ManagedBuildManager.setOption(config, optionHolder, option, appendArrays(oldValues, value));
modified = true;
} else {
// $NON-NLS-1$ //$NON-NLS-2$
throw new Exception("Unexpected option type " + optionType);
}
}
}
return modified;
}
Aggregations