use of org.eclipse.cdt.core.envvar.IEnvironmentVariableManager in project arduino-eclipse-plugin by Sloeber.
the class ArduinoLanguageProvider method getCompilerCommand.
@Override
protected String getCompilerCommand(String languageId) {
String compilerCommand = new String();
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(this.currentProject);
if (prjDesc == null)
return compilerCommand;
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
ICConfigurationDescription confDesc = prjDesc.getActiveConfiguration();
String recipeKey = new String();
String extraOptions = new String();
CompileOptions compileOptions = new CompileOptions(confDesc);
if (languageId.equals("org.eclipse.cdt.core.gcc")) {
recipeKey = Common.get_ENV_KEY_RECIPE(Const.ACTION_C_to_O);
extraOptions = compileOptions.get_C_CompileOptions();
} else if (languageId.equals("org.eclipse.cdt.core.g++")) {
recipeKey = Common.get_ENV_KEY_RECIPE(Const.ACTION_CPP_to_O);
extraOptions = compileOptions.get_CPP_CompileOptions();
} else {
ManagedBuilderCorePlugin.error("Unable to find compiler command for language " + languageId + " in toolchain=" + getToolchainId());
}
extraOptions = extraOptions + " " + compileOptions.get_C_andCPP_CompileOptions() + " " + compileOptions.get_All_CompileOptions();
try {
compilerCommand = envManager.getVariable(recipeKey + Const.DOT + "1", confDesc, false).getValue();
compilerCommand = compilerCommand + envManager.getVariable(recipeKey + Const.DOT + "2", confDesc, false).getValue();
compilerCommand = compilerCommand + envManager.getVariable(recipeKey + Const.DOT + "3", confDesc, false).getValue();
} catch (Exception e) {
compilerCommand = new String();
}
compilerCommand = compilerCommand + ' ' + extraOptions;
return compilerCommand.replaceAll(" -o ", " ");
}
use of org.eclipse.cdt.core.envvar.IEnvironmentVariableManager 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.IEnvironmentVariableManager 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.IEnvironmentVariableManager 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.IEnvironmentVariableManager 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