use of org.eclipse.cdt.managedbuilder.core.IManagedOutputNameProvider in project arduino-eclipse-plugin by Sloeber.
the class ArduinoManagedBuildGnuToolInfo method calculateOutputs.
/*
* 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 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>.
*
* NOTE: If an option is not specified and this is not the primary output
* type, the outputs from the type are not added to the command line
*/
public boolean calculateOutputs(ArduinoGnuMakefileGenerator makeGen, IConfiguration config, HashSet<String> handledInputExtensions, boolean lastChance) {
boolean done = true;
Vector<String> myCommandOutputs = new Vector<>();
Vector<String> myEnumeratedPrimaryOutputs = new Vector<>();
Vector<String> myEnumeratedSecondaryOutputs = new Vector<>();
HashMap<String, List<IPath>> myOutputMacros = new HashMap<>();
// The next two fields are used together
Vector<String> myBuildVars = new Vector<>();
Vector<Vector<String>> myBuildVarsValues = new Vector<>();
// Get the outputs for this tool invocation
IOutputType[] outTypes = this.tool.getOutputTypes();
if (outTypes != null && outTypes.length > 0) {
for (int i = 0; i < outTypes.length; i++) {
Vector<String> typeEnumeratedOutputs = new Vector<>();
IOutputType type = outTypes[i];
String outputPrefix = type.getOutputPrefix();
if (config != null) {
try {
outputPrefix = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(// $NON-NLS-1$
outputPrefix, // $NON-NLS-1$
"", // $NON-NLS-1$
" ", IBuildMacroProvider.CONTEXT_CONFIGURATION, config);
} catch (BuildMacroException e) {
// JABA is not going to add
// code
}
}
String variable = type.getBuildVariable();
boolean multOfType = type.getMultipleOfType();
boolean primaryOutput = (type == this.tool.getPrimaryOutputType());
IOption option = this.tool.getOptionBySuperClassId(type.getOptionId());
IManagedOutputNameProvider nameProvider = type.getNameProvider();
String[] outputNames = type.getOutputNames();
// use artifact name & extension
if (this.bIsTargetTool && primaryOutput) {
String outputName = outputPrefix + this.targetName;
if (this.targetExt.length() > 0) {
outputName += (DOT + this.targetExt);
}
myCommandOutputs.add(outputName);
typeEnumeratedOutputs.add(outputName);
// But this doesn't use any output macro...
} else // 2. If an option is specified, use the value of the option
if (option != null) {
try {
List<String> outputs = new ArrayList<>();
int optType = option.getValueType();
if (optType == IOption.STRING) {
outputs.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();
outputs = value;
this.tool.filterValues(optType, outputs);
// Add outputPrefix to each if necessary
if (outputPrefix.length() > 0) {
for (int j = 0; j < outputs.size(); j++) {
outputs.set(j, outputPrefix + outputs.get(j));
}
}
}
for (int j = 0; j < outputs.size(); j++) {
String outputName = outputs.get(j);
try {
// try to resolve the build macros in the output
// names
String resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(// $NON-NLS-1$
outputName, // $NON-NLS-1$
"", // $NON-NLS-1$
" ", IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(option, this.tool));
if ((resolved = resolved.trim()).length() > 0)
outputs.set(j, resolved);
} catch (BuildMacroException e) {
// JABA is not
// going to add
// code
}
}
// NO - myCommandOutputs.addAll(outputs);
typeEnumeratedOutputs.addAll(outputs);
if (variable.length() > 0) {
List<IPath> outputPaths = new ArrayList<>();
for (int j = 0; j < outputs.size(); j++) {
outputPaths.add(Path.fromOSString(outputs.get(j)));
}
if (myOutputMacros.containsKey(variable)) {
List<IPath> currList = myOutputMacros.get(variable);
currList.addAll(outputPaths);
myOutputMacros.put(variable, currList);
} else {
myOutputMacros.put(variable, outputPaths);
}
}
} catch (BuildException ex) {
// JABA is not going to add
// code
}
} else // 3. If a nameProvider is specified, call it
if (nameProvider != null) {
// The inputs must have been calculated before we can do
// this
IPath[] outNames = null;
if (!this.inputsCalculated) {
done = false;
} else {
Vector<String> inputs = getEnumeratedInputs();
IPath[] inputPaths = new IPath[inputs.size()];
for (int j = 0; j < inputPaths.length; j++) {
inputPaths[j] = Path.fromOSString(inputs.get(j));
}
// if (inputPaths.length == 0) {
try {
IManagedOutputNameProviderJaba newNameProvider = (IManagedOutputNameProviderJaba) nameProvider;
outNames = newNameProvider.getOutputNames(this.project, config, this.tool, inputPaths);
} 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", // $NON-NLS-1$
e));
}
// JABA end of insertion
if (outNames != null) {
for (int j = 0; j < outNames.length; j++) {
String outputName = outNames[j].toOSString();
try {
// try to resolve the build macros in the
// output names
String resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(// $NON-NLS-1$
outputName, // $NON-NLS-1$
"", // $NON-NLS-1$
" ", IBuildMacroProvider.CONTEXT_CONFIGURATION, config);
if ((resolved = resolved.trim()).length() > 0) {
outputName = resolved;
outNames[j] = Path.fromOSString(resolved);
}
} catch (BuildMacroException e) {
// JABA is not
// going to add
// code
}
if (primaryOutput) {
myCommandOutputs.add(outputName);
}
typeEnumeratedOutputs.add(outputName);
}
}
}
if (variable.length() > 0 && outNames != null) {
if (myOutputMacros.containsKey(variable)) {
List<IPath> currList = myOutputMacros.get(variable);
currList.addAll(Arrays.asList(outNames));
myOutputMacros.put(variable, currList);
} else {
myOutputMacros.put(variable, new ArrayList<>(Arrays.asList(outNames)));
}
}
} else // 4. If outputNames is specified, use it
if (outputNames != null) {
if (outputNames.length > 0) {
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(// $NON-NLS-1$
outputName, // $NON-NLS-1$
"", // $NON-NLS-1$
" ", IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(option, this.tool));
if ((resolved = resolved.trim()).length() > 0)
outputNames[j] = resolved;
} catch (BuildMacroException e) {
// JABA is not
// going to add
// code
}
}
List<String> namesList = Arrays.asList(outputNames);
if (primaryOutput) {
myCommandOutputs.addAll(namesList);
}
typeEnumeratedOutputs.addAll(namesList);
if (variable.length() > 0) {
List<IPath> outputPaths = new ArrayList<>();
for (int j = 0; j < namesList.size(); j++) {
outputPaths.add(Path.fromOSString(namesList.get(j)));
}
if (myOutputMacros.containsKey(variable)) {
List<IPath> currList = myOutputMacros.get(variable);
currList.addAll(outputPaths);
myOutputMacros.put(variable, currList);
} else {
myOutputMacros.put(variable, outputPaths);
}
}
}
} else {
// <code>make</code>.
if (multOfType) {
// This case is not handled - a nameProvider or
// outputNames must be specified
List<String> errList = new ArrayList<>();
// $NON-NLS-1$
errList.add(ManagedMakeMessages.getResourceString("MakefileGenerator.error.no.nameprovider"));
myCommandOutputs.addAll(errList);
} else {
String namePattern = type.getNamePattern();
if (namePattern == null || namePattern.length() == 0) {
namePattern = outputPrefix + IManagedBuilderMakefileGenerator.WILDCARD;
String outExt = (type.getOutputExtensions(this.tool))[0];
if (outExt != null && outExt.length() > 0) {
namePattern += DOT + outExt;
}
} else if (outputPrefix.length() > 0) {
namePattern = outputPrefix + namePattern;
}
// this
if (!this.inputsCalculated) {
done = false;
} else {
Vector<String> inputs = getEnumeratedInputs();
String fileName;
if (inputs.size() > 0) {
// Get the input file name
fileName = (Path.fromOSString(inputs.get(0))).removeFileExtension().lastSegment();
// the raw macro name.
if (fileName.startsWith("$(") && fileName.endsWith(")")) {
// $NON-NLS-1$ //$NON-NLS-2$
fileName = fileName.substring(2, fileName.length() - 1);
}
} else {
// $NON-NLS-1$
fileName = "default";
}
// Replace the % with the file name
if (primaryOutput) {
// $NON-NLS-1$
myCommandOutputs.add(namePattern.replaceAll("%", fileName));
}
// $NON-NLS-1$
typeEnumeratedOutputs.add(namePattern.replaceAll("%", fileName));
if (variable.length() > 0) {
List<IPath> outputs = new ArrayList<>();
outputs.add(Path.fromOSString(fileName));
if (myOutputMacros.containsKey(variable)) {
List<IPath> currList = myOutputMacros.get(variable);
currList.addAll(outputs);
myOutputMacros.put(variable, currList);
} else {
myOutputMacros.put(variable, outputs);
}
}
}
}
}
if (variable.length() > 0) {
myBuildVars.add(variable);
myBuildVarsValues.add(typeEnumeratedOutputs);
}
if (primaryOutput) {
myEnumeratedPrimaryOutputs.addAll(typeEnumeratedOutputs);
} else {
myEnumeratedSecondaryOutputs.addAll(typeEnumeratedOutputs);
}
}
} else {
if (this.bIsTargetTool) {
String outputPrefix = this.tool.getOutputPrefix();
String outputName = outputPrefix + this.targetName;
if (this.targetExt.length() > 0) {
outputName += (DOT + this.targetExt);
}
myCommandOutputs.add(outputName);
myEnumeratedPrimaryOutputs.add(outputName);
} 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
}
}
// Add the output macros of this tool to the buildOutVars map
Set<Entry<String, List<IPath>>> entrySet = myOutputMacros.entrySet();
for (Entry<String, List<IPath>> entry : entrySet) {
String macroName = entry.getKey();
List<IPath> newMacroValue = entry.getValue();
Map<String, List<IPath>> map = makeGen.getBuildOutputVars();
if (map.containsKey(macroName)) {
List<IPath> macroValue = map.get(macroName);
macroValue.addAll(newMacroValue);
map.put(macroName, macroValue);
} else {
map.put(macroName, newMacroValue);
}
}
this.outputVariablesCalculated = true;
if (done) {
this.commandOutputs.addAll(myCommandOutputs);
this.enumeratedPrimaryOutputs.addAll(myEnumeratedPrimaryOutputs);
this.enumeratedSecondaryOutputs.addAll(myEnumeratedSecondaryOutputs);
this.outputVariables.addAll(myOutputMacros.keySet());
this.outputsCalculated = true;
for (int i = 0; i < myBuildVars.size(); i++) {
makeGen.addMacroAdditionFiles(makeGen.getTopBuildOutputVars(), myBuildVars.get(i), myBuildVarsValues.get(i));
}
return true;
}
return false;
}
use of org.eclipse.cdt.managedbuilder.core.IManagedOutputNameProvider 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));
// }
}
}
Aggregations