use of org.eclipse.cdt.managedbuilder.core.BuildException in project usbdm-eclipse-plugins by podonoghue.
the class DisassembleCFileHandler method execute.
// public static void pipeStream(InputStream input, OutputStream output)
// throws IOException {
//
// byte buffer[] = new byte[1024];
// int numRead = 0;
//
// while (input.available() > 0) {
// numRead = input.read(buffer);
// output.write(buffer, 0, numRead);
// }
// output.flush();
// }
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String os = System.getProperty("os.name");
boolean isLinux = (os != null) && os.toUpperCase().contains("LINUX");
Object source = HandlerUtil.getCurrentSelection(event);
// System.err.println("Event source = "+source.toString()+"\n class = "+source.getClass().toString());
if (!(source instanceof TreeSelection)) {
// System.err.println("Source is not an instance of TreeSelection");
return null;
}
TreeSelection selection = (TreeSelection) source;
if (!(selection.getFirstElement() instanceof IBinary)) {
// System.err.println("Selection.getFirstElement() is not an instance of org.eclipse.cdt.core.model.IBinary");
return null;
}
IBinary binary = (IBinary) selection.getFirstElement();
IResource resource = binary.getUnderlyingResource();
IPath resourcePath = resource.getLocation();
IPath dissassemblyPath = resourcePath.removeFileExtension().addFileExtension("lis");
// Get Environment (path etc)
CoreModel cdtCoreModel = org.eclipse.cdt.core.model.CoreModel.getDefault();
ICProjectDescription cProjectDescription = cdtCoreModel.getProjectDescription(resource.getProject());
ICConfigurationDescription cConfigurationDescription = cProjectDescription.getActiveConfiguration();
IContributedEnvironment contributedEnvironment = CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment();
IEnvironmentVariable[] environmentVariablesArray = contributedEnvironment.getVariables(cConfigurationDescription);
HashMap<String, String> environmentMap = new HashMap<String, String>();
for (IEnvironmentVariable ev : environmentVariablesArray) {
String name = ev.getName();
if ((!isLinux) && name.equals("PATH")) {
name = "Path";
}
// System.err.println("Adding Environment variable: "+name+" => "+ev.getValue());
environmentMap.put(name, ev.getValue());
}
// String resourceName = resource.getName();
// System.err.println("resourceName = "+resourceName);
IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(resource);
IConfiguration configuration = buildInfo.getDefaultConfiguration();
// System.err.println("configuration = "+configuration);
// Find lister tool in configuration
ITool[] toolArray = configuration.getTools();
ITool tool = null;
for (ITool t : toolArray) {
Pattern p = Pattern.compile("net\\.sourceforge\\.usbdm\\.cdt\\..*\\.toolchain\\.lister\\..*");
if (p.matcher(t.getId()).matches()) {
tool = configuration.getTool(t.getId());
break;
}
}
if (tool == null) {
return null;
}
// System.err.println("tool.getName = "+tool.getName());
// System.err.println("tool.getToolCommand = "+tool.getToolCommand());
// Get command line generator
IManagedCommandLineGenerator commandLineGenerator = tool.getCommandLineGenerator();
// Get command line
try {
String[] inputs = { resourcePath.lastSegment() };
IManagedCommandLineInfo commandLineInfo = commandLineGenerator.generateCommandLineInfo(tool, tool.getToolCommand(), tool.getToolCommandFlags(resourcePath, dissassemblyPath), "", ">", dissassemblyPath.lastSegment(), inputs, "${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}");
// System.err.println("cl.toString() = "+commandLineInfo.toString());
// System.err.println("cl.getCommandLine() = "+commandLineInfo.getCommandLine());
String[] commandArray = null;
if (isLinux) {
// Construct command (Use cmd for PATH changes!)
ArrayList<String> command = new ArrayList<String>(20);
command.add("/bin/sh");
command.add("-c");
command.add(commandLineInfo.getCommandLine());
commandArray = (String[]) command.toArray(new String[command.size()]);
} else {
// Construct command (Use cmd for PATH changes!)
ArrayList<String> command = new ArrayList<String>(20);
command.add("cmd.exe");
command.add("/C");
command.add(commandLineInfo.getCommandLine());
commandArray = (String[]) command.toArray(new String[command.size()]);
}
// Run command
// System.err.println("Running...");
ProcessBuilder pb = new ProcessBuilder(commandArray);
pb.environment().putAll(environmentMap);
File commandFile = findExecutableOnPath(pb.environment().get("PATH"), commandLineInfo.getCommandName());
if (commandFile != null) {
// System.err.println("commandFile.toPath() = "+ commandFile.toPath());
// System.err.println("pwd = "+ resourcePath.removeLastSegments(1).toFile());
}
// System.err.println("=================== Environment variables ===================");
// for (String envName : pb.environment().keySet()) {
// System.err.println("Environment variable: "+envName+" => "+pb.environment().get(envName));
// }
// System.err.println("=================== End of Environment variables ===================");
pb.redirectInput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
pb.redirectOutput(Redirect.INHERIT);
pb.directory(resourcePath.removeLastSegments(1).toFile());
// System.err.println("WD =" + pb.directory());
Process p = pb.start();
// System.err.println("Waiting...");
p.waitFor();
// System.err.println("Exit value = " + p.waitFor());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (BuildException e) {
e.printStackTrace();
}
try {
// Refresh parent directory so file is visible
resource.getParent().refreshLocal(1, null);
} catch (CoreException e) {
e.printStackTrace();
}
try {
// Open disassembled file in editor
IPath asmPath = resource.getFullPath().removeFileExtension().addFileExtension("lis");
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IDE.openEditor(page, ResourcesPlugin.getWorkspace().getRoot().getFile(asmPath));
} catch (PartInitException e) {
e.printStackTrace();
}
// System.err.println("Completed");
return null;
}
use of org.eclipse.cdt.managedbuilder.core.BuildException in project m2e-nar by maven-nar.
the class OptionSetter method setOption.
public void setOption(final String optionId, final boolean value) throws CoreException {
try {
for (final ITool tool : config.getToolsBySuperClassId(toolId)) {
final IOption option = tool.getOptionBySuperClassId(optionId);
config.setOption(tool, option, value);
}
} catch (BuildException e) {
throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't set " + optionId + " option", e));
}
}
use of org.eclipse.cdt.managedbuilder.core.BuildException 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.BuildException 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.BuildException 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