Search in sources :

Example 1 with TxtFile

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

the class BoardDescription method getEnvVars.

/**
 * 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 Map<String, String> getEnvVars() {
    updateWhenDirty();
    TxtFile pluginPreProcessingPlatformTxt = new TxtFile(ConfigurationPreferences.getPreProcessingPlatformFile());
    TxtFile pluginPostProcessingPlatformTxt = new TxtFile(ConfigurationPreferences.getPostProcessingPlatformFile());
    BoardTxtFile pluginPreProcessingBoardsTxt = new BoardTxtFile(ConfigurationPreferences.getPreProcessingBoardsFile());
    BoardTxtFile pluginPostProcessingBoardsTxt = new BoardTxtFile(ConfigurationPreferences.getPostProcessingBoardsFile());
    Map<String, String> allVars = pluginPreProcessingPlatformTxt.getAllEnvironVars(EMPTY);
    allVars.putAll(pluginPreProcessingBoardsTxt.getBoardEnvironVars(getBoardID()));
    String architecture = getArchitecture();
    IPath coreHardwarePath = getreferencedCoreHardwarePath();
    allVars.put(ENV_KEY_BUILD_ARCH, architecture.toUpperCase());
    allVars.put(ENV_KEY_HARDWARE_PATH, coreHardwarePath.removeLastSegments(1).toOSString());
    allVars.put(ENV_KEY_BUILD_SYSTEM_PATH, coreHardwarePath.append(SYSTEM).toOSString());
    allVars.put(ENV_KEY_PLATFORM_PATH, getreferencingPlatformPath().toOSString());
    allVars.put(ENV_KEY_SERIAL_PORT, getActualUploadPort());
    allVars.put(ENV_KEY_SERIAL_DOT_PORT, getActualUploadPort());
    // $NON-NLS-1$
    allVars.put(ENV_KEY_SERIAL_PORT_FILE, getActualUploadPort().replace("/dev/", EMPTY));
    // if actual core path is osstring regression test issue555 willl fail teensy
    // stuff
    allVars.put(ENV_KEY_BUILD_ACTUAL_CORE_PATH, getActualCoreCodePath().toString());
    IPath variantPath = getActualVariantPath();
    if (variantPath != null) {
        allVars.put(ENV_KEY_BUILD_VARIANT_PATH, variantPath.toOSString());
    } else {
        // teensy does not use variants
        allVars.put(ENV_KEY_BUILD_VARIANT_PATH, EMPTY);
    }
    PlatformTxtFile referencedPlatfromFile = getreferencedCorePlatformFile();
    // process the platform file referenced by the boards.txt
    if (referencedPlatfromFile != null) {
        allVars.putAll(referencedPlatfromFile.getAllEnvironVars());
    }
    PlatformTxtFile referencingPlatfromFile = getReferencingPlatformFile();
    // process the platform file next to the selected boards.txt
    if (referencingPlatfromFile != null) {
        allVars.putAll(referencingPlatfromFile.getAllEnvironVars());
    }
    // put in the installed tools info
    allVars.putAll(getEnVarPlatformInfo());
    // boards settings not coming from menu selections
    allVars.putAll(myBoardTxtFile.getBoardEnvironVars(getBoardID()));
    // board settings from menu selections
    Map<String, String> options = getOptions();
    KeyValueTree rootData = myBoardTxtFile.getData();
    KeyValueTree menuData = rootData.getChild(getBoardID() + DOT + MENU);
    for (Entry<String, String> curOption : options.entrySet()) {
        String menuID = curOption.getKey();
        String SelectedMenuItemID = curOption.getValue();
        KeyValueTree curSelectedMenuItem = menuData.getChild(menuID + DOT + SelectedMenuItemID);
        allVars.putAll(curSelectedMenuItem.toKeyValues(EMPTY, false));
    }
    // This moved last. See github issue 1410
    Programmers[] localProgrammers = Programmers.fromBoards(this);
    String programmer = getProgrammer();
    for (Programmers curProgrammer : localProgrammers) {
        String programmerID = curProgrammer.getIDFromNiceName(programmer);
        if (programmerID != null) {
            allVars.putAll(curProgrammer.getAllEnvironVars(programmerID));
        }
    }
    // add the stuff that comes with the plugin that is marked as post
    allVars.putAll(pluginPostProcessingPlatformTxt.getAllEnvironVars(EMPTY));
    allVars.putAll(pluginPostProcessingBoardsTxt.getBoardEnvironVars(getBoardID()));
    // Do some coded post processing
    allVars.putAll(getEnvVarsPostProcessing(allVars));
    return allVars;
}
Also used : IPath(org.eclipse.core.runtime.IPath) PlatformTxtFile(io.sloeber.core.txt.PlatformTxtFile) BoardTxtFile(io.sloeber.core.txt.BoardTxtFile) PlatformTxtFile(io.sloeber.core.txt.PlatformTxtFile) TxtFile(io.sloeber.core.txt.TxtFile) BoardTxtFile(io.sloeber.core.txt.BoardTxtFile) KeyValueTree(io.sloeber.core.txt.KeyValueTree) Programmers(io.sloeber.core.txt.Programmers)

Example 2 with TxtFile

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

the class SloeberProject method readConfigFromFiles.

/**
 * Read the sloeber configuration file and setup the project
 *
 * @return true if the files exist
 */
private boolean readConfigFromFiles() {
    IFile file = getConfigLocalFile();
    IFile versionFile = getConfigVersionFile();
    if (!(file.exists() || versionFile.exists())) {
        // no sloeber files found
        return false;
    }
    if (file.exists()) {
        myCfgFile = new TxtFile(file.getLocation().toFile());
        if (versionFile.exists()) {
            myCfgFile.mergeFile(versionFile.getLocation().toFile());
        }
    } else {
        myCfgFile = new TxtFile(versionFile.getLocation().toFile());
    }
    KeyValueTree allFileConfigs = myCfgFile.getData().getChild(CONFIG);
    for (Entry<String, KeyValueTree> curChild : allFileConfigs.getChildren().entrySet()) {
        String curConfName = curChild.getKey();
        BoardDescription boardDesc = new BoardDescription(myCfgFile, getBoardPrefix(curConfName));
        CompileDescription compileDescription = new CompileDescription(myCfgFile, getCompilePrefix(curConfName));
        OtherDescription otherDesc = new OtherDescription(myCfgFile, getOtherPrefix(curConfName));
        String curConfKey = curConfName;
        myBoardDescriptions.put(curConfKey, boardDesc);
        myCompileDescriptions.put(curConfKey, compileDescription);
        myOtherDescriptions.put(curConfKey, otherDesc);
    }
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) TxtFile(io.sloeber.core.txt.TxtFile) KeyValueTree(io.sloeber.core.txt.KeyValueTree)

Aggregations

KeyValueTree (io.sloeber.core.txt.KeyValueTree)2 TxtFile (io.sloeber.core.txt.TxtFile)2 BoardTxtFile (io.sloeber.core.txt.BoardTxtFile)1 PlatformTxtFile (io.sloeber.core.txt.PlatformTxtFile)1 Programmers (io.sloeber.core.txt.Programmers)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1