Search in sources :

Example 6 with IEnvironmentVariable

use of org.eclipse.cdt.core.envvar.IEnvironmentVariable in project arduino-eclipse-plugin by Sloeber.

the class Shared method applyKnownWorkArounds.

/*
	 * For some boards that do not run out of the box we know how to fix it. This
	 * code fixes these things
	 */
public static void applyKnownWorkArounds() {
    /*
		 * for chipkit PONTECH UAV100 board boards.txt contains
		 * usbono_pic32.compiler.c.extra_flags=-G1024 -Danything=1 and platform.txt
		 * contains ... {compiler.define} "{compiler.cpp.extra_flags}"
		 * {build.extra_flags} ... resulting in ... "-G1024 -Danything=1" ... Arduino
		 * IDE magically makes this ... "-G1024" -Danything=1 ... But I refuse to do
		 * this type of smart parsing because modifying text files is lots easier
		 * therefore as a workaround I replace "{compiler.cpp.extra_flags}" in
		 * platform.txt with {compiler.cpp.extra_flags}
		 */
    java.nio.file.Path packageRoot = Paths.get(ConfigurationPreferences.getInstallationPathPackages().toOSString());
    java.nio.file.Path platform_txt = packageRoot.resolve("chipKIT").resolve("hardware").resolve("pic32").resolve("2.0.1").resolve("platform.txt");
    if (platform_txt.toFile().exists()) {
        FileModifiers.replaceInFile(platform_txt.toFile(), false, "\"{compiler.cpp.extra_flags}\"", "{compiler.cpp.extra_flags}");
    }
    /*
		 * oak on windows does not come with all required libraries and assumes arduino
		 * IDE has them available So I set sloeber_path_extension to the teensy root
		 *
		 */
    if (SystemUtils.IS_OS_WINDOWS) {
        java.nio.file.Path arduinoIDERoot = Paths.get(MySystem.getTeensyPlatform());
        if (arduinoIDERoot.toFile().exists()) {
            try {
                // /cater for null pointer
                arduinoIDERoot = arduinoIDERoot.getParent().getParent();
                IEnvironmentVariable var = new EnvironmentVariable("sloeber_path_extension", arduinoIDERoot.toString());
                IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode("org.eclipse.cdt.core");
                Preferences t = myScope.node("environment").node("workspace").node(var.getName().toUpperCase());
                t.put("delimiter", var.getDelimiter());
                t.put("operation", "append");
                t.put("value", var.getValue());
                myScope.flush();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    /*
		 * oak on linux comes with a esptool2 in a wrong folder.
		 * As it is only 1 file I move the file
		 *
		 */
    if (SystemUtils.IS_OS_LINUX) {
        java.nio.file.Path esptool2root = packageRoot.resolve("digistump").resolve("tools").resolve("esptool2").resolve("0.9.1");
        java.nio.file.Path esptool2wrong = esptool2root.resolve("0.9.1").resolve("esptool2");
        java.nio.file.Path esptool2right = esptool2root.resolve("esptool2");
        if (esptool2wrong.toFile().exists()) {
            try {
                Files.move(esptool2wrong, esptool2right);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    /*
		 * Elector heeft core Platino maar de directory noemt platino.
		 * In windows geen probleem maar in case sensitive linux dus wel
		 */
    if (SystemUtils.IS_OS_LINUX) {
        java.nio.file.Path cores = packageRoot.resolve("Elektor").resolve("hardware").resolve("avr").resolve("1.0.0").resolve("cores");
        java.nio.file.Path coreWrong = cores.resolve("platino");
        java.nio.file.Path coreGood = cores.resolve("Platino");
        if (coreWrong.toFile().exists()) {
            coreWrong.toFile().renameTo(coreGood.toFile());
        }
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IEnvironmentVariable(org.eclipse.cdt.core.envvar.IEnvironmentVariable) EnvironmentVariable(org.eclipse.cdt.core.envvar.EnvironmentVariable) IEnvironmentVariable(org.eclipse.cdt.core.envvar.IEnvironmentVariable) IOException(java.io.IOException) Preferences(org.osgi.service.prefs.Preferences) ConfigurationPreferences(io.sloeber.core.common.ConfigurationPreferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Aggregations

IEnvironmentVariable (org.eclipse.cdt.core.envvar.IEnvironmentVariable)6 EnvironmentVariable (org.eclipse.cdt.core.envvar.EnvironmentVariable)4 IOException (java.io.IOException)3 CoreException (org.eclipse.core.runtime.CoreException)3 ArrayList (java.util.ArrayList)2 IContributedEnvironment (org.eclipse.cdt.core.envvar.IContributedEnvironment)2 CompileOptions (io.sloeber.core.api.CompileOptions)1 ConfigurationPreferences (io.sloeber.core.common.ConfigurationPreferences)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 IEnvironmentVariableManager (org.eclipse.cdt.core.envvar.IEnvironmentVariableManager)1 CoreModel (org.eclipse.cdt.core.model.CoreModel)1 IBinary (org.eclipse.cdt.core.model.IBinary)1 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)1 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)1 BuildException (org.eclipse.cdt.managedbuilder.core.BuildException)1 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)1