Search in sources :

Example 1 with InternalBoardDescriptor

use of io.sloeber.core.InternalBoardDescriptor 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);
}
Also used : IContributedEnvironment(org.eclipse.cdt.core.envvar.IContributedEnvironment) InternalBoardDescriptor(io.sloeber.core.InternalBoardDescriptor) IEnvironmentVariableManager(org.eclipse.cdt.core.envvar.IEnvironmentVariableManager) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 2 with InternalBoardDescriptor

use of io.sloeber.core.InternalBoardDescriptor in project arduino-eclipse-plugin by Sloeber.

the class Libraries method findAllHarwareLibraries.

/**
 * Searches all the hardware dependent libraries of a project. If this is a
 * board referencing a core then the libraries of the referenced core are
 * added as well
 *
 * @param project
 *            the project to find all hardware libraries for
 * @return all the library folder names. May contain empty values.
 */
private static Map<String, IPath> findAllHarwareLibraries(ICConfigurationDescription confdesc) {
    Map<String, IPath> ret = new HashMap<>();
    BoardDescriptor boardDescriptor = new InternalBoardDescriptor(confdesc);
    // first add the referenced
    IPath libPath = boardDescriptor.getReferencedLibraryPath();
    if (libPath != null) {
        ret.putAll(findAllSubFolders(libPath));
    }
    // then add the referencing
    libPath = boardDescriptor.getReferencingLibraryPath();
    if (libPath != null) {
        ret.putAll(findAllSubFolders(libPath));
    }
    return ret;
}
Also used : IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) InternalBoardDescriptor(io.sloeber.core.InternalBoardDescriptor) BoardDescriptor(io.sloeber.core.api.BoardDescriptor) InternalBoardDescriptor(io.sloeber.core.InternalBoardDescriptor)

Example 3 with InternalBoardDescriptor

use of io.sloeber.core.InternalBoardDescriptor in project arduino-eclipse-plugin by Sloeber.

the class Helpers method addCodeFolder.

/**
 * This method creates a link folder in the project and add the folder as a
 * source path to the project it also adds the path to the include folder if the
 * include path parameter points to a path that contains a subfolder named
 * "utility" this subfolder will be added to the include path as well <br/>
 * Forget about this. Arduino made this all so complicated I don't know anymore
 * what needs to be added to what<br/>
 * <br/>
 *
 * note Arduino has these subfolders in the libraries that need to be
 * include.<br/>
 * <br/>
 *
 * note that in the current eclipse version, there is no need to add the
 * subfolder as a code folder. This may change in the future as it looks like a
 * bug to me.<br/>
 *
 * @param project
 * @param Path
 * @throws CoreException
 *
 * @see addLibraryDependency {@link #addLibraryDependency(IProject, IProject)}
 */
public static void addCodeFolder(IProject project, IPath toLinkFolder, String LinkName, ICConfigurationDescription configurationDescription, boolean forceRoot) throws CoreException {
    IFolder link = project.getFolder(LinkName);
    LinkFolderToFolder(project, toLinkFolder, new Path(LinkName));
    // Now the folder has been created we need to make sure the special
    // folders are added to the path
    String possibleIncludeFolder = "utility";
    File file = toLinkFolder.append(possibleIncludeFolder).toFile();
    if (file.exists()) {
        addIncludeFolder(configurationDescription, link.getFullPath().append(possibleIncludeFolder));
    }
    if (forceRoot) {
        addIncludeFolder(configurationDescription, link.getFullPath());
    } else {
        // add src or root give priority to src
        possibleIncludeFolder = Library.LIBRARY_SOURCE_FODER;
        file = toLinkFolder.append(possibleIncludeFolder).toFile();
        if (file.exists()) {
            addIncludeFolder(configurationDescription, link.getFullPath().append(possibleIncludeFolder));
        } else {
            addIncludeFolder(configurationDescription, link.getFullPath());
        }
    }
    possibleIncludeFolder = "arch";
    file = toLinkFolder.append(possibleIncludeFolder).toFile();
    if (file.exists()) {
        InternalBoardDescriptor boardDescriptor = new InternalBoardDescriptor(configurationDescription);
        addIncludeFolder(configurationDescription, link.getFullPath().append(possibleIncludeFolder).append(boardDescriptor.getArchitecture()));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) InternalBoardDescriptor(io.sloeber.core.InternalBoardDescriptor) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with InternalBoardDescriptor

use of io.sloeber.core.InternalBoardDescriptor in project arduino-eclipse-plugin by Sloeber.

the class ConfigurationChangeListener method handleEvent.

@Override
public void handleEvent(CProjectDescriptionEvent event) {
    if (event.getEventType() != CProjectDescriptionEvent.ABOUT_TO_APPLY) {
        return;
    }
    ICProjectDescription projDesc = event.getNewCProjectDescription();
    // only handle arduino nature projects
    try {
        if (!event.getProject().hasNature(Const.ARDUINO_NATURE_ID)) {
            if (event.getProject().hasNature("it.baeyens.arduinonature")) {
                // $NON-NLS-1$
                // this is the old nature so make necessary changes
                IProjectDescription desc = projDesc.getProject().getDescription();
                // replace the ino to cpp tool
                ICommand[] buildSpec = desc.getBuildSpec();
                for (ICommand curCommand : buildSpec) {
                    if (curCommand.getBuilderName().equals("it.baeyens.arduino.core.inoToCpp")) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        curCommand.setBuilderName("io.sloeber.arduino.core.inoToCpp");
                    }
                }
                desc.setBuildSpec(buildSpec);
                // set the correct natures
                Helpers.addTheNatures(desc);
                projDesc.getProject().setDescription(desc, null);
                // manually.
                class TheDialog implements Runnable {

                    @Override
                    public void run() {
                        MessageDialog dialog = new // $NON-NLS-1$
                        MessageDialog(// $NON-NLS-1$
                        null, // $NON-NLS-1$
                        "Your action is needed.", // $NON-NLS-1$
                        null, // $NON-NLS-1$
                        "Your project/sketch has partially been migrated from baeyens.it to sloeber.io.\nYou still need to change the toolchain!", MessageDialog.QUESTION, new String[] { // $NON-NLS-1$
                        "Show me datailed instructions (opens browser)", // $NON-NLS-1$
                        "I know the routine" }, 0);
                        if (dialog.open() == 0) {
                            // $NON-NLS-1$
                            org.eclipse.swt.program.Program.launch("https://baeyens.it/eclipse/toolchainFix.php");
                        }
                    }
                }
                TheDialog theDialog = new TheDialog();
                Display.getDefault().syncExec(theDialog);
            } else {
                return;
            }
        }
    } catch (Exception e) {
        // don't care don't update
        return;
    }
    // TODO check here how this behaves when changing a config and select
    // ok.
    // It seems to me this is rerunning the config change which is not
    // nessesary in this case
    // We have a arduino project so we are safe.
    ICProjectDescription oldprojDesc = event.getOldCProjectDescription();
    ICConfigurationDescription activeConf = projDesc.getActiveConfiguration();
    IProject activeProject = projDesc.getProject();
    InternalBoardDescriptor oldBoardDescriptor = (InternalBoardDescriptor) BoardDescriptor.makeBoardDescriptor(oldprojDesc.getActiveConfiguration());
    InternalBoardDescriptor newBoardDescriptor = (InternalBoardDescriptor) BoardDescriptor.makeBoardDescriptor(activeConf);
    if (oldBoardDescriptor.equals(newBoardDescriptor)) {
        if (event.getProject().getName().equals(oldBoardDescriptor.getProjectName())) {
            if (oldprojDesc.getActiveConfiguration().getName().equals(projDesc.getActiveConfiguration().getName())) {
                // only act when there is change
                return;
            }
        }
    }
    Helpers.setTheEnvironmentVariables(activeProject, activeConf, newBoardDescriptor);
    try {
        Helpers.addArduinoCodeToProject(newBoardDescriptor, activeProject, activeConf);
    } catch (Exception e) {
        // $NON-NLS-1$
        Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "failed to add include folder", e));
    }
    Libraries.reAttachLibrariesToProject(activeConf);
    projDesc.setActiveConfiguration(activeConf);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription) InternalBoardDescriptor(io.sloeber.core.InternalBoardDescriptor) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IProject(org.eclipse.core.resources.IProject)

Aggregations

InternalBoardDescriptor (io.sloeber.core.InternalBoardDescriptor)4 File (java.io.File)2 IFile (org.eclipse.core.resources.IFile)2 IPath (org.eclipse.core.runtime.IPath)2 BoardDescriptor (io.sloeber.core.api.BoardDescriptor)1 HashMap (java.util.HashMap)1 IContributedEnvironment (org.eclipse.cdt.core.envvar.IContributedEnvironment)1 IEnvironmentVariableManager (org.eclipse.cdt.core.envvar.IEnvironmentVariableManager)1 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)1 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)1 ICommand (org.eclipse.core.resources.ICommand)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1