use of org.eclipse.cdt.core.envvar.IContributedEnvironment in project arduino-eclipse-plugin by Sloeber.
the class Helpers method setTheEnvironmentVariables.
/**
* This method creates environment variables based on the platform.txt and
* boards.txt. platform.txt is processed first and then boards.txt. This way
* boards.txt settings can overwrite common settings in platform.txt The
* environment variables are only valid for the project given as parameter The
* project properties are used to identify the boards.txt and platform.txt as
* well as the board id to select the settings in the board.txt file At the end
* also the path variable is set
*
* To be able to quickly fix boards.txt and platform.txt problems I also added a
* pre and post platform and boards files that are processed before and after
* the arduino delivered boards.txt file.
*
* @param project
* the project for which the environment variables are set
* @param arduinoProperties
* the info of the selected board to set the variables for
*/
public static void setTheEnvironmentVariables(IProject project, ICConfigurationDescription confDesc, InternalBoardDescriptor boardsDescriptor) {
// first get all the data we need
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
Programmers[] localProgrammers = Programmers.fromBoards(boardsDescriptor);
String boardid = boardsDescriptor.getBoardID();
InternalBoardDescriptor pluginPreProcessingBoardsTxt = new InternalBoardDescriptor(new TxtFile(ConfigurationPreferences.getPreProcessingBoardsFile()), boardid);
InternalBoardDescriptor pluginPostProcessingBoardsTxt = new InternalBoardDescriptor(new TxtFile(ConfigurationPreferences.getPostProcessingBoardsFile()), boardid);
File pluginPreProcessingPlatformTxt = ConfigurationPreferences.getPreProcessingPlatformFile();
File pluginPostProcessingPlatformTxt = ConfigurationPreferences.getPostProcessingPlatformFile();
// Now we have all info we can start processing
// set the output folder as derive
// first remove all Arduino Variables so there is no memory effect
removeAllEraseEnvironmentVariables(contribEnv, confDesc);
setTheEnvironmentVariablesSetTheDefaults(project.getName(), contribEnv, confDesc, boardsDescriptor);
// add the stuff that comes with the plugin that are marked as pre
setTheEnvironmentVariablesAddAFile(new String(), contribEnv, confDesc, pluginPreProcessingPlatformTxt, false);
setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, pluginPreProcessingBoardsTxt, false);
File referencedPlatfromFile = boardsDescriptor.getreferencedPlatformFile();
// process the platform file referenced by the boards.txt
if (referencedPlatfromFile != null && referencedPlatfromFile.exists()) {
setTheEnvironmentVariablesAddAFile(contribEnv, confDesc, referencedPlatfromFile);
}
File referencingPlatfromFile = boardsDescriptor.getReferencingPlatformFile();
// process the platform file next to the selected boards.txt
if (referencingPlatfromFile != null && referencingPlatfromFile.exists()) {
setTheEnvironmentVariablesAddAFile(contribEnv, confDesc, referencingPlatfromFile);
}
setTheEnvironmentVariablesAddThePlatformInfo(boardsDescriptor, contribEnv, confDesc);
// add the boards file
setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, boardsDescriptor, true);
String programmer = boardsDescriptor.getProgrammer();
for (Programmers curProgrammer : localProgrammers) {
String programmerID = curProgrammer.getBoardIDFromBoardName(programmer);
if (programmerID != null) {
InternalBoardDescriptor progBoard = new InternalBoardDescriptor(curProgrammer, programmerID);
setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, progBoard, false);
}
}
// add the stuff that comes with the plugin that is marked as post
setTheEnvironmentVariablesAddAFile(contribEnv, confDesc, pluginPostProcessingPlatformTxt);
setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, pluginPostProcessingBoardsTxt, false);
// Do some coded post processing
setTheEnvironmentVariablesPostProcessing(contribEnv, confDesc, boardsDescriptor);
}
use of org.eclipse.cdt.core.envvar.IContributedEnvironment in project arduino-eclipse-plugin by Sloeber.
the class BoardDescriptor method saveConfiguration.
public boolean saveConfiguration(ICConfigurationDescription confDesc, IContributedEnvironment contribEnvIn) {
boolean needsSettingDirty = false;
if (confDesc != null) {
BoardDescriptor curBoardDesCriptor = makeBoardDescriptor(confDesc);
needsSettingDirty = curBoardDesCriptor.needsSettingDirty(this);
IContributedEnvironment contribEnv = contribEnvIn;
if (contribEnv == null) {
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
contribEnv = envManager.getContributedEnvironment();
}
Common.setBuildEnvironmentVariable(contribEnv, confDesc, "JANTJE.SELECTED.PLATFORM", getreferencingPlatformPath().toString());
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_BOARD_NAME, getBoardName());
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_BOARDS_FILE, getReferencingBoardsFile().toString());
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_BOARD_ID, this.myBoardID);
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_ARCITECTURE_ID, getArchitecture());
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_PACKAGE_ID, getPackage());
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_UPLOAD_PORT, this.myUploadPort);
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_PROJECT_NAME, confDesc.getProjectDescription().getProject().getName());
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_OS, this.myOSName);
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_WORKSPACE_LOCATION, this.myWorkSpaceLocation);
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_ECLIPSE_LOCATION, this.myWorkEclipseLocation);
Common.setBuildEnvironmentVariable(confDesc, JANTJE_ACTION_UPLOAD, this.myProgrammer);
String value = KeyValue.makeString(this.myOptions);
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_MENU_SELECTION, value);
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT, this.myUploadPort);
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT_FILE, this.myUploadPort.replace("/dev/", new String()));
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_ACTUAL_CORE_PATH, getActualCoreCodePath().toOSString());
IPath variantPath = getActualVariantPath();
if (variantPath != null) {
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_VARIANT_PATH, variantPath.toOSString());
} else {
// teensy does not use variants
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_VARIANT_PATH, new String());
}
}
// Also save last used values
myStorageNode.put(KEY_LAST_USED_BOARDS_FILE, getReferencingBoardsFile().toString());
myStorageNode.put(KEY_LAST_USED_BOARD, this.myBoardID);
myStorageNode.put(KEY_LAST_USED_UPLOAD_PORT, this.myUploadPort);
myStorageNode.put(KEY_LAST_USED_UPLOAD_PROTOCOL, this.myProgrammer);
myStorageNode.put(KEY_LAST_USED_BOARD_MENU_OPTIONS, KeyValue.makeString(this.myOptions));
return needsSettingDirty;
}
use of org.eclipse.cdt.core.envvar.IContributedEnvironment in project arduino-eclipse-plugin by Sloeber.
the class arduinoUploader method uploadUsingPreferences.
@Override
public boolean uploadUsingPreferences(IFile hexFile, BoardDescriptor inBoardDescriptor, IProgressMonitor monitor) {
String MComPort = new String();
String boardName = new String();
boolean needsPassword = false;
boolean needsUpdatedConfig = false;
BoardDescriptor boardDescriptor = BoardDescriptor.makeBoardDescriptor(inBoardDescriptor);
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(this.myProject);
ICConfigurationDescription configurationDescription = prjDesc.getConfigurationByName(this.mycConf);
try {
needsPassword = envManager.getVariable(Const.ENV_KEY_NETWORK_AUTH, configurationDescription, true).getValue().equalsIgnoreCase(Const.TRUE);
} catch (Exception e) {
// ignore all errors
}
if (!boardDescriptor.usesProgrammer()) {
String NewSerialPort = ArduinoSerial.makeArduinoUploadready(this.myConsole.newMessageStream(), this.myProject, this.mycConf, boardDescriptor);
if (!boardDescriptor.getUploadPort().equals(NewSerialPort)) {
boardDescriptor.setUploadPort(NewSerialPort);
needsUpdatedConfig = true;
}
}
// for web authorized upload
if (needsPassword) {
setEnvironmentvarsForAutorizedUpload(contribEnv, configurationDescription, MComPort);
}
if (needsUpdatedConfig) {
try {
boardDescriptor.saveConfiguration(configurationDescription, null);
} catch (Exception e) {
Common.log(new // $NON-NLS-1$
Status(// $NON-NLS-1$
IStatus.ERROR, // $NON-NLS-1$
Const.CORE_PLUGIN_ID, // $NON-NLS-1$
"Failed to save configuration before upload", e));
return false;
}
}
String command = boardDescriptor.getUploadCommand(configurationDescription);
if (command == null) {
// $NON-NLS-1$
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to get the Upload recipe "));
return false;
}
try {
GenericLocalUploader.RunConsoledCommand(this.myConsole, command, monitor);
} catch (IOException e1) {
// $NON-NLS-1$
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to run the Upload recipe ", e1));
return false;
}
if (boardName.startsWith("Arduino Due ")) {
// $NON-NLS-1$
ArduinoSerial.reset_Arduino_by_baud_rate(MComPort, 115200, 100);
}
return true;
}
use of org.eclipse.cdt.core.envvar.IContributedEnvironment 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.core.envvar.IContributedEnvironment in project arduino-eclipse-plugin by Sloeber.
the class CompileOptions method save.
/**
* save the compilation options in this configuration description.
*
* @param configuration
* must be a valid configuration description
*/
public void save(ICConfigurationDescription configuration) {
CompileOptions curOptions = new CompileOptions(configuration);
if (needsDirtyFlag(curOptions)) {
IProject project = configuration.getProjectDescription().getProject();
Helpers.setDirtyFlag(project, configuration);
}
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
IEnvironmentVariable var = new EnvironmentVariable(ENV_KEY_JANTJE_WARNING_LEVEL, this.myWarningLevel.toString());
contribEnv.addVariable(var, configuration);
if (this.isWarningLevel()) {
var = new EnvironmentVariable(ENV_KEY_WARNING_LEVEL_OFF, ENV_KEY_WARNING_LEVEL_ON);
contribEnv.addVariable(var, configuration);
}
if (this.myAlternativeSizeCommand) {
var = new EnvironmentVariable(ENV_KEY_JANTJE_SIZE_SWITCH, // $NON-NLS-1$
"${" + ENV_KEY_JANTJE_SIZE_COMMAND + // $NON-NLS-1$
"}");
contribEnv.addVariable(var, configuration);
} else {
var = new EnvironmentVariable(ENV_KEY_JANTJE_SIZE_SWITCH, // $NON-NLS-1$
"${" + Common.get_ENV_KEY_RECIPE(Const.ACTION_SIZE) + // $NON-NLS-1$
"}");
contribEnv.addVariable(var, configuration);
}
var = new EnvironmentVariable(ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS, this.my_C_andCPP_CompileOptions);
contribEnv.addVariable(var, configuration);
var = new EnvironmentVariable(ENV_KEY_JANTJE_ADDITIONAL_CPP_COMPILE_OPTIONS, this.my_CPP_CompileOptions);
contribEnv.addVariable(var, configuration);
var = new EnvironmentVariable(ENV_KEY_JANTJE_ADDITIONAL_C_COMPILE_OPTIONS, this.my_C_CompileOptions);
contribEnv.addVariable(var, configuration);
var = new EnvironmentVariable(ENV_KEY_JANTJE_ASSEMBLY_COMPILE_OPTIONS, this.my_Assembly_CompileOptions);
contribEnv.addVariable(var, configuration);
var = new EnvironmentVariable(ENV_KEY_JANTJE_ARCHIVE_COMPILE_OPTIONS, this.my_Archive_CompileOptions);
contribEnv.addVariable(var, configuration);
var = new EnvironmentVariable(ENV_KEY_JANTJE_LINK_COMPILE_OPTIONS, this.my_Link_CompileOptions);
contribEnv.addVariable(var, configuration);
var = new EnvironmentVariable(ENV_KEY_JANTJE_ALL_COMPILE_OPTIONS, this.my_All_CompileOptions);
contribEnv.addVariable(var, configuration);
}
Aggregations