diff options
author | Doug Schaefer | 2016-05-25 15:21:22 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-06-14 01:23:10 +0000 |
commit | 5d2cbaaa1c59b45ad44e486d2f876dd8100b1045 (patch) | |
tree | fb2d369ac9d24a2e3fe6b04f9dcc1e95add46a71 /toolchains | |
parent | de37ec61db93ec9c55cd3102ef2f2bb8d2f854c9 (diff) | |
download | org.eclipse.cdt-5d2cbaaa1c59b45ad44e486d2f876dd8100b1045.tar.gz org.eclipse.cdt-5d2cbaaa1c59b45ad44e486d2f876dd8100b1045.tar.xz org.eclipse.cdt-5d2cbaaa1c59b45ad44e486d2f876dd8100b1045.zip |
Cherry picking changes from the CDT 9 branch for Qt and Arduino.
Change-Id: I85eca2b8bb0447d4dd703030c41d90c1f9bcdf89
Diffstat (limited to 'toolchains')
16 files changed, 645 insertions, 237 deletions
diff --git a/toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml b/toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml index cd655da1e4f..a01625ef990 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml +++ b/toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml @@ -1,46 +1,46 @@ -<?xml version="1.0" encoding="UTF-8"?> -<feature - id="org.eclipse.cdt.arduino" - label="%featureName" - version="9.0.0.qualifier" - provider-name="%providerName" - plugin="org.eclipse.cdt.arduino.ui" - license-feature="org.eclipse.license" - license-feature-version="0.0.0"> - - <description> - %description - </description> - - <copyright> - %copyright - </copyright> - - <license url="%licenseURL"> - %license - </license> - - <requires> - <import feature="org.eclipse.launchbar" version="1.0.0"/> - <import feature="org.eclipse.remote.serial" version="1.0.0"/> - <import feature="org.eclipse.remote" version="2.0.0"/> - <import feature="org.eclipse.remote.console" version="2.0.0"/> - <import feature="org.eclipse.cdt" version="9.0.0"/> - <import feature="org.eclipse.launchbar.remote" version="1.0.0.qualifier"/> - </requires> - - <plugin - id="org.eclipse.cdt.arduino.core" - download-size="0" - install-size="0" - version="0.0.0" - unpack="false"/> - - <plugin - id="org.eclipse.cdt.arduino.ui" - download-size="0" - install-size="0" - version="0.0.0" - unpack="false"/> - -</feature> +<?xml version="1.0" encoding="UTF-8"?>
+<feature
+ id="org.eclipse.cdt.arduino"
+ label="%featureName"
+ version="9.0.0.qualifier"
+ provider-name="%providerName"
+ plugin="org.eclipse.cdt.arduino.ui"
+ license-feature="org.eclipse.license"
+ license-feature-version="0.0.0">
+
+ <description>
+ %description
+ </description>
+
+ <copyright>
+ %copyright
+ </copyright>
+
+ <license url="%licenseURL">
+ %license
+ </license>
+
+ <requires>
+ <import feature="org.eclipse.launchbar" version="1.0.0"/>
+ <import feature="org.eclipse.remote.serial" version="1.0.0"/>
+ <import feature="org.eclipse.remote" version="2.0.0"/>
+ <import feature="org.eclipse.remote.console" version="2.0.0"/>
+ <import feature="org.eclipse.cdt" version="9.0.0"/>
+ <import feature="org.eclipse.launchbar.remote" version="1.0.0"/>
+ </requires>
+
+ <plugin
+ id="org.eclipse.cdt.arduino.core"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.cdt.arduino.ui"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+</feature>
diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core.tests/src/org/eclipse/cdt/arduino/core/tests/FullIntegration.java b/toolchains/arduino/org.eclipse.cdt.arduino.core.tests/src/org/eclipse/cdt/arduino/core/tests/FullIntegration.java new file mode 100644 index 00000000000..f70e5bdae4a --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core.tests/src/org/eclipse/cdt/arduino/core/tests/FullIntegration.java @@ -0,0 +1,205 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.tests; + +import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.cdt.arduino.core.internal.Activator; +import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; +import org.eclipse.cdt.arduino.core.internal.ArduinoProjectGenerator; +import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard; +import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager; +import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform; +import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration; +import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfigurationProvider; +import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection; +import org.eclipse.cdt.core.build.ICBuildConfigurationManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.junit.Test; + +@SuppressWarnings("nls") +public class FullIntegration { + + private static final ArduinoManager arduinoManager = Activator.getService(ArduinoManager.class); + private static final IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class); + private static final ICBuildConfigurationManager buildConfigManager = Activator + .getService(ICBuildConfigurationManager.class); + + private void setBoardUrls() throws Exception { + URL[] urls = new URL[] { new URL("http://downloads.arduino.cc/packages/package_index.json"), + new URL("https://adafruit.github.io/arduino-board-index/package_adafruit_index.json") }; + ArduinoPreferences.setBoardUrlList(urls); + } + + private Set<ArduinoBoard> getSkipBuild() throws Exception { + Set<ArduinoBoard> boards = new HashSet<>(); + + // Fails in arduino too + boards.add(arduinoManager.getBoard("arduino", "avr", "robotControl")); + boards.add(arduinoManager.getBoard("arduino", "avr", "robotMotor")); + boards.add(arduinoManager.getBoard("adafruit", "avr", "adafruit32u4")); + + // TODO Need to add support for menu specific build properties + boards.add(arduinoManager.getBoard("arduino", "avr", "mini")); + boards.add(arduinoManager.getBoard("arduino", "avr", "lilypad")); + boards.add(arduinoManager.getBoard("arduino", "avr", "diecimila")); + boards.add(arduinoManager.getBoard("arduino", "avr", "pro")); + boards.add(arduinoManager.getBoard("arduino", "avr", "atmegang")); + boards.add(arduinoManager.getBoard("arduino", "avr", "bt")); + boards.add(arduinoManager.getBoard("arduino", "avr", "mega")); + boards.add(arduinoManager.getBoard("arduino", "avr", "nano")); + boards.add(arduinoManager.getBoard("TeeOnArdu", "avr", "CirPlayTeensyCore")); + boards.add(arduinoManager.getBoard("TeeOnArdu", "avr", "FloraTeensyCore")); + boards.add(arduinoManager.getBoard("TeeOnArdu", "avr", "TeeOnArdu")); + + // TODO build.system.path missing + boards.add(arduinoManager.getBoard("arduino", "sam", "arduino_due_x")); + boards.add(arduinoManager.getBoard("arduino", "sam", "arduino_due_x_dbg")); + boards.add(arduinoManager.getBoard("Intel", "arc32", "arduino_101")); + + if (Platform.getOS().equals(Platform.OS_WIN32)) { + // i586/i686 link missing + boards.add(arduinoManager.getBoard("Intel", "i586", "izmir_fd")); + boards.add(arduinoManager.getBoard("Intel", "i586", "izmir_fg")); + boards.add(arduinoManager.getBoard("Intel", "i686", "izmir_ec")); + } + return boards; + } + + private Set<ArduinoBoard> getSkipUpload() throws Exception { + Set<ArduinoBoard> boards = new HashSet<>(); + + // missing upload.protocol + boards.add(arduinoManager.getBoard("arduino", "avr", "gemma")); + boards.add(arduinoManager.getBoard("adafruit", "avr", "gemma")); + boards.add(arduinoManager.getBoard("adafruit", "avr", "trinket5")); + boards.add(arduinoManager.getBoard("adafruit", "avr", "trinket3")); + + // usbtiny missing + boards.add(arduinoManager.getBoard("adafruit", "avr", "protrinket3")); + boards.add(arduinoManager.getBoard("adafruit", "avr", "protrinket5")); + + return boards; + } + + @Test + public void runTest() throws Exception { + IProgressMonitor monitor = new SysoutProgressMonitor(); + + setArduinoHome(); + setBoardUrls(); + loadPlatforms(monitor); + + Set<ArduinoBoard> skipBuild = getSkipBuild(); + Set<ArduinoBoard> skipUpload = getSkipUpload(); + IProject project = createProject(monitor); + for (ArduinoBoard board : arduinoManager.getInstalledBoards()) { + if (!skipBuild.contains(board)) { + buildBoard(project, board, !skipUpload.contains(board), monitor); + } + } + } + + private void setArduinoHome() throws Exception { + Path workspace = Paths.get(ResourcesPlugin.getWorkspace().getRoot().getLocationURI()); + ArduinoPreferences.setArduinoHome(workspace.resolve(".arduinocdt")); + } + + private void loadPlatforms(IProgressMonitor monitor) throws Exception { + Collection<ArduinoPlatform> plats = arduinoManager.getAvailablePlatforms(monitor); + arduinoManager.installPlatforms(plats, monitor); + } + + private IProject createProject(IProgressMonitor monitor) throws Exception { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + String projectName = "ArduinoTest"; + ArduinoProjectGenerator generator = new ArduinoProjectGenerator("templates/cppsketch/manifest.xml"); //$NON-NLS-1$ + + Job job = new Job("Create") { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + IProject project = root.getProject(projectName); + if (project.exists()) { + project.delete(true, monitor); + } + + generator.setProjectName(projectName); + generator.generate(new HashMap<String, Object>(), monitor); + return Status.OK_STATUS; + } catch (CoreException e) { + return e.getStatus(); + } + } + }; + job.setRule(root); + job.schedule(); + job.join(); + + return generator.getProject(); + } + + private void buildBoard(IProject project, ArduinoBoard board, boolean upload, IProgressMonitor monitor) throws Exception { + ArduinoRemoteConnection arduinoTarget = createTarget(board); + ArduinoBuildConfigurationProvider provider = (ArduinoBuildConfigurationProvider) buildConfigManager + .getProvider(ArduinoBuildConfigurationProvider.ID); + ArduinoBuildConfiguration config = provider.createConfiguration(project, arduinoTarget, "run", monitor); + + System.out.println(String.format("Building board: %s\n %s - %s", board.getName(), board.getId(), + board.getPlatform().getInstallPath())); + + config.generateMakeFile(monitor); + ProcessBuilder processBuilder = new ProcessBuilder().command(config.getBuildCommand()) + .directory(config.getBuildDirectory().toFile()).inheritIO(); + config.setBuildEnvironment(processBuilder.environment()); + Process process = processBuilder.start(); + int rc = process.waitFor(); + if (rc != 0) { + throw new Exception("Build failed"); + } + + // Test to make sure we can get the upload command cleanly + if (upload) { + System.out.println(String.join(" ", config.getUploadCommand("port1"))); + } + } + + private ArduinoRemoteConnection createTarget(ArduinoBoard board) throws Exception { + IRemoteConnectionType type = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID); + IRemoteConnection connection = type.getConnection(board.getName()); + if (connection != null) { + type.removeConnection(connection); + } + + IRemoteConnectionWorkingCopy workingCopy = type.newConnection(board.getName()); + ArduinoRemoteConnection.setBoardId(workingCopy, board); + ArduinoRemoteConnection.setPortName(workingCopy, "port1"); + connection = workingCopy.save(); + + return connection.getService(ArduinoRemoteConnection.class); + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core.tests/src/org/eclipse/cdt/arduino/core/tests/SysoutProgressMonitor.java b/toolchains/arduino/org.eclipse.cdt.arduino.core.tests/src/org/eclipse/cdt/arduino/core/tests/SysoutProgressMonitor.java new file mode 100644 index 00000000000..deb16eba55b --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core.tests/src/org/eclipse/cdt/arduino/core/tests/SysoutProgressMonitor.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.tests; + +import org.eclipse.core.runtime.NullProgressMonitor; + +public class SysoutProgressMonitor extends NullProgressMonitor { + + @Override + public void beginTask(String name, int totalWork) { + if (name.length() > 0) { + System.out.println(name); + System.out.flush(); + } + } + + @Override + public void subTask(String name) { + if (name.length() > 0) { + System.out.println(name); + System.out.flush(); + } + } + + @Override + public void setTaskName(String name) { + if (name.length() > 0) { + System.out.println(name); + System.out.flush(); + } + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoPreferences.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoPreferences.java index c8ac61c5258..988ef26d933 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoPreferences.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoPreferences.java @@ -38,11 +38,15 @@ public class ArduinoPreferences { return Paths.get(getPrefs().get(ARDUINO_HOME, defaultHome)); } + public static void setArduinoHome(Path home) { + getPrefs().put(ARDUINO_HOME, home.toString()); + } + public static String getBoardUrls() { return getPrefs().get(BOARD_URLS, defaultBoardUrls); } - public static Collection<URL> getBoardUrlList() throws CoreException { + public static URL[] getBoardUrlList() throws CoreException { List<URL> urlList = new ArrayList<>(); for (String url : getBoardUrls().split("\n")) { //$NON-NLS-1$ try { @@ -51,7 +55,7 @@ public class ArduinoPreferences { throw Activator.coreException(e); } } - return urlList; + return urlList.toArray(new URL[urlList.size()]); } public static void setBoardUrls(String boardUrls) { @@ -64,6 +68,22 @@ public class ArduinoPreferences { } } + public static void setBoardUrlList(URL[] urls) { + StringBuilder str = new StringBuilder(); + for (int i = 0; i < urls.length - 1; ++i) { + str.append(urls[i].toString()); + str.append('\n'); + } + if (urls.length > 0) { + str.append(urls[urls.length - 1].toString()); + } + setBoardUrls(str.toString()); + } + + public static String getDefaultArduinoHome() { + return defaultHome; + } + public static String getDefaultBoardUrls() { return defaultBoardUrls; } diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoBoard.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoBoard.java index bad4694bc65..0bb2b8d667d 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoBoard.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoBoard.java @@ -13,8 +13,6 @@ import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties; public class ArduinoBoard { - public static final String MENU_QUALIFIER = "menu_"; //$NON-NLS-1$ - private String name; private String id; diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoManager.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoManager.java index 556c80082ce..d894855033b 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoManager.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoManager.java @@ -90,7 +90,7 @@ public class ArduinoManager { return ArduinoPreferences.getArduinoHome().resolve(".version"); //$NON-NLS-1$ } - private void init() throws CoreException { + private synchronized void init() throws CoreException { if (props == null) { if (!Files.exists(ArduinoPreferences.getArduinoHome())) { try { @@ -219,12 +219,12 @@ public class ArduinoManager { return pkg != null ? pkg.getInstalledPlatform(architecture) : null; } - public Collection<ArduinoPlatform> getAvailablePlatforms(IProgressMonitor monitor) throws CoreException { + public synchronized Collection<ArduinoPlatform> getAvailablePlatforms(IProgressMonitor monitor) throws CoreException { List<ArduinoPlatform> platforms = new ArrayList<>(); - Collection<URL> urls = ArduinoPreferences.getBoardUrlList(); - SubMonitor sub = SubMonitor.convert(monitor, urls.size() + 1); + URL[] urls = ArduinoPreferences.getBoardUrlList(); + SubMonitor sub = SubMonitor.convert(monitor, urls.length + 1); - sub.beginTask("Downloading package descriptions", urls.size()); //$NON-NLS-1$ + sub.beginTask("Downloading package descriptions", urls.length); //$NON-NLS-1$ for (URL url : urls) { Path packagePath = ArduinoPreferences.getArduinoHome() .resolve(Paths.get(url.getPath()).getFileName()); @@ -252,7 +252,7 @@ public class ArduinoManager { public void installPlatforms(Collection<ArduinoPlatform> platforms, IProgressMonitor monitor) throws CoreException { SubMonitor sub = SubMonitor.convert(monitor, platforms.size()); for (ArduinoPlatform platform : platforms) { - sub.setTaskName(String.format("Installing %s", platform.getName())); //$NON-NLS-1$ + sub.setTaskName(String.format("Installing %s %s", platform.getName(), platform.getVersion())); //$NON-NLS-1$ platform.install(sub); sub.worked(1); } @@ -292,7 +292,7 @@ public class ArduinoManager { return result; } - private void initPackages() throws CoreException { + private synchronized void initPackages() throws CoreException { if (packages == null) { init(); packages = new HashMap<>(); @@ -326,7 +326,7 @@ public class ArduinoManager { packages = null; } - private ArduinoPackage getPackage(String packageName) throws CoreException { + public ArduinoPackage getPackage(String packageName) throws CoreException { if (packageName == null) { return null; } else { diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPackage.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPackage.java index 3aba4a82eda..19a9fffa1b9 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPackage.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPackage.java @@ -92,24 +92,27 @@ public class ArduinoPackage { if (Files.isDirectory(getInstallPath())) { Path platformTxt = Paths.get("platform.txt"); //$NON-NLS-1$ try { - Files.find(getInstallPath().resolve("hardware"), 2, //$NON-NLS-1$ - (path, attrs) -> path.getFileName().equals(platformTxt)) - .forEach(path -> { - try (FileReader reader = new FileReader(path.toFile())) { - Properties platformProperties = new Properties(); - platformProperties.load(reader); - String arch = path.getName(path.getNameCount() - 2).toString(); - String version = platformProperties.getProperty("version"); //$NON-NLS-1$ - - ArduinoPlatform platform = getPlatform(arch, version); - if (platform != null) { - platform.setPlatformProperties(platformProperties); - installedPlatforms.put(arch, platform); - } // TODO manually add it if was removed from index - } catch (IOException e) { - throw new RuntimeException(e); - } - }); + Path hardware = getInstallPath().resolve("hardware"); + if (Files.exists(hardware)) { + Files.find(hardware, 2, // $NON-NLS-1$ + (path, attrs) -> path.getFileName().equals(platformTxt)).forEach(path -> { + try (FileReader reader = new FileReader(path.toFile())) { + Properties platformProperties = new Properties(); + platformProperties.load(reader); + String arch = path.getName(path.getNameCount() - 2).toString(); + String version = platformProperties.getProperty("version"); //$NON-NLS-1$ + + ArduinoPlatform platform = getPlatform(arch, version); + if (platform != null) { + platform.setPlatformProperties(platformProperties); + installedPlatforms.put(arch, platform); + } // TODO manually add it if was removed + // from index + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } } catch (IOException e) { throw Activator.coreException(e); } @@ -166,6 +169,18 @@ public class ArduinoPackage { return null; } + public ArduinoTool getLatestTool(String toolName) { + ArduinoTool latest = null; + for (ArduinoTool tool : tools) { + if (tool.getName().equals(toolName) && tool.isInstalled()) { + if (latest == null || ArduinoManager.compareVersions(tool.getVersion(), latest.getVersion()) > 0) { + latest = tool; + } + } + } + return latest; + } + @Override public boolean equals(Object obj) { if (obj instanceof ArduinoPackage) { diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPlatform.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPlatform.java index 3e85fa1b87a..26110ac91c0 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPlatform.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPlatform.java @@ -20,7 +20,6 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -31,7 +30,6 @@ import org.eclipse.cdt.arduino.core.internal.Activator; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties; import org.eclipse.cdt.arduino.core.internal.Messages; -import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -209,39 +207,6 @@ public class ArduinoPlatform { return getPackage().getInstallPath().resolve("hardware").resolve(architecture); //$NON-NLS-1$ } - public List<Path> getIncludePath() { - Path installPath = getInstallPath(); - return Arrays.asList(installPath.resolve("cores/{build.core}"), //$NON-NLS-1$ - installPath.resolve("variants/{build.variant}")); //$NON-NLS-1$ - } - - private void getSources(Collection<String> sources, Path dir, boolean recurse) { - for (File file : dir.toFile().listFiles()) { - if (file.isDirectory()) { - if (recurse) { - getSources(sources, file.toPath(), recurse); - } - } else { - if (ArduinoBuildConfiguration.isSource(file.getName())) { - sources.add(ArduinoBuildConfiguration.pathString(file.toPath())); - } - } - } - } - - public Collection<String> getSources(String core, String variant) { - List<String> sources = new ArrayList<>(); - Path srcPath = getInstallPath().resolve("cores").resolve(core); //$NON-NLS-1$ - if (srcPath.toFile().isDirectory()) { - getSources(sources, srcPath, true); - } - Path variantPath = getInstallPath().resolve("variants").resolve(variant); //$NON-NLS-1$ - if (variantPath.toFile().isDirectory()) { - getSources(sources, variantPath, true); - } - return sources; - } - private void initLibraries() throws CoreException { if (libraries == null) { libraries = new HashMap<>(); diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoTool.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoTool.java index c3a9bf42af2..2561cbcc2bd 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoTool.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoTool.java @@ -87,6 +87,7 @@ public class ArduinoTool { for (ArduinoToolSystem system : systems) { if (system.isApplicable()) { system.install(monitor); + return; } } diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java index 39af24d8fd0..877be21da5c 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java @@ -23,8 +23,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -38,6 +40,7 @@ import org.eclipse.cdt.arduino.core.internal.board.ArduinoLibrary; import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager; import org.eclipse.cdt.arduino.core.internal.board.ArduinoPackage; import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform; +import org.eclipse.cdt.arduino.core.internal.board.ArduinoTool; import org.eclipse.cdt.arduino.core.internal.board.ToolDependency; import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection; import org.eclipse.cdt.core.CCorePlugin; @@ -79,6 +82,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te private static final String PACKAGE_NAME = "packageName"; //$NON-NLS-1$ private static final String PLATFORM_NAME = "platformName"; //$NON-NLS-1$ private static final String BOARD_NAME = "boardName"; //$NON-NLS-1$ + private static final String MENU_QUALIFIER = "menu_"; //$NON-NLS-1$ private static ArduinoManager manager = Activator.getService(ArduinoManager.class); @@ -117,8 +121,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te } ArduinoBuildConfiguration(IBuildConfiguration config, String name, ArduinoBoard board, String launchMode, - IToolChain toolChain) - throws CoreException { + IToolChain toolChain) throws CoreException { super(config, name, toolChain); this.board = board; this.launchMode = launchMode; @@ -148,10 +151,9 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te if (menus != null) { Preferences settings = getSettings(); for (String id : menus.getChildren().keySet()) { - String key = ArduinoBoard.MENU_QUALIFIER + id; - String value = target.getRemoteConnection().getAttribute(key); + String value = target.getMenuValue(id); if (value != null) { - settings.put(key, value); + settings.put(MENU_QUALIFIER + id, value); } } @@ -164,7 +166,9 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te } static String generateName(ArduinoBoard board, String launchMode) { - return "arduino." + board.getId() + '.' + launchMode; //$NON-NLS-1$ + ArduinoPlatform platform = board.getPlatform(); + ArduinoPackage pkg = platform.getPackage(); + return pkg.getName() + '.' + platform.getArchitecture() + '.' + board.getId() + '.' + launchMode; } @SuppressWarnings("unchecked") @@ -190,8 +194,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te HierarchicalProperties menus = board.getMenus(); if (menus != null) { for (String id : menus.getChildren().keySet()) { - String key = ArduinoBoard.MENU_QUALIFIER + id; - if (!settings.get(key, "").equals(target.getRemoteConnection().getAttribute(key))) { //$NON-NLS-1$ + if (!settings.get(MENU_QUALIFIER + id, "").equals(target.getMenuValue(id))) { //$NON-NLS-1$ return false; } } @@ -211,19 +214,43 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te // IDE generated properties properties = new Properties(); properties.put("runtime.platform.path", platform.getInstallPath().toString()); //$NON-NLS-1$ - properties.put("runtime.ide.version", "10607"); //$NON-NLS-1$ //$NON-NLS-2$ + properties.put("runtime.ide.version", "10608"); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("software", "ARDUINO"); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("build.arch", platform.getArchitecture().toUpperCase()); //$NON-NLS-1$ String configName = getBuildConfiguration().getName(); if (configName.equals(IBuildConfiguration.DEFAULT_CONFIG_NAME)) { configName = "default"; //$NON-NLS-1$ } - properties.put("build.path", configName); //$NON-NLS-1$ + properties.put("build.path", "."); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("build.variant.path", //$NON-NLS-1$ platform.getInstallPath().resolve("variants").resolve("{build.variant}").toString()); //$NON-NLS-1$ //$NON-NLS-2$ + // Everyone seems to want to use the avr-gcc and avrdude tools + ArduinoPackage arduinoPackage = manager.getPackage("arduino"); //$NON-NLS-1$ + ArduinoTool avrgcc = arduinoPackage.getLatestTool("avr-gcc"); //$NON-NLS-1$ + if (avrgcc != null) { + properties.put("runtime.tools.avr-gcc.path", avrgcc.getInstallPath().toString()); //$NON-NLS-1$ + } + ArduinoTool avrdude = arduinoPackage.getLatestTool("avrdude"); //$NON-NLS-1$ + if (avrdude != null) { + properties.put("runtime.tools.avrdude.path", avrdude.getInstallPath().toString()); //$NON-NLS-1$ + } + + // Super Platform + String core = board.getBoardProperties().getProperty("build.core"); //$NON-NLS-1$ + if (core.contains(":")) { //$NON-NLS-1$ + String[] segments = core.split(":"); //$NON-NLS-1$ + if (segments.length == 2) { + ArduinoPlatform superPlatform = manager.getInstalledPlatform(segments[0], + platform.getArchitecture()); + if (superPlatform != null) { + properties.putAll(superPlatform.getPlatformProperties()); + } + } + } + // Platform - properties.putAll(board.getPlatform().getPlatformProperties()); + properties.putAll(platform.getPlatformProperties()); // Tools for (ToolDependency toolDep : platform.getToolsDependencies()) { @@ -238,10 +265,18 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te Preferences settings = getSettings(); HierarchicalProperties menus = board.getMenus(); if (menus != null) { - for (String menuId : menus.getChildren().keySet()) { - String value = settings.get(ArduinoBoard.MENU_QUALIFIER + menuId, ""); //$NON-NLS-1$ + for (Entry<String, HierarchicalProperties> menuEntry : menus.getChildren().entrySet()) { + String key = menuEntry.getKey(); + String defaultValue; + Iterator<HierarchicalProperties> i = menuEntry.getValue().getChildren().values().iterator(); + if (i.hasNext()) { + defaultValue = i.next().getValue(); + } else { + defaultValue = ""; //$NON-NLS-1$ + } + String value = settings.get(MENU_QUALIFIER + key, defaultValue); if (!value.isEmpty()) { - properties.putAll(board.getMenuProperties(menuId, value)); + properties.putAll(board.getMenuProperties(key, value)); } } } @@ -252,13 +287,6 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te return properties; } - public IFile getMakeFile() throws CoreException { - IFolder buildFolder = (IFolder) getBuildContainer(); - ArduinoBoard board = getBoard(); - String makeFileName = board.getId() + ".mk"; //$NON-NLS-1$ - return buildFolder.getFile(makeFileName); - } - public Map<String, Object> getBuildModel() throws CoreException { IProject project = getProject(); ArduinoBoard board = getBoard(); @@ -301,7 +329,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te buildModel.put("project_name", project.getName()); //$NON-NLS-1$ String includes = null; - for (Path include : platform.getIncludePath()) { + for (Path include : getIncludePath(platform, properties)) { if (includes == null) { includes = "-I"; //$NON-NLS-1$ } else { @@ -316,10 +344,35 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te } properties.put("includes", includes); //$NON-NLS-1$ - Path platformPath = platform.getInstallPath(); - buildModel.put("platform_path", pathString(platformPath).replace("+", "\\+")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - buildModel.put("platform_srcs", //$NON-NLS-1$ - platform.getSources(properties.getProperty("build.core"), properties.getProperty("build.variant"))); //$NON-NLS-1$ //$NON-NLS-2$ + ArduinoPlatform corePlatform = platform; + String core = properties.getProperty("build.core"); //$NON-NLS-1$ + if (core.contains(":")) { //$NON-NLS-1$ + String[] segments = core.split(":"); //$NON-NLS-1$ + if (segments.length == 2) { + corePlatform = manager.getInstalledPlatform(segments[0], platform.getArchitecture()); + core = segments[1]; + } + } + Path corePath = corePlatform.getInstallPath().resolve("cores").resolve(core); //$NON-NLS-1$ + buildModel.put("platform_core_path", pathString(corePath)); //$NON-NLS-1$ + List<String> coreSources = new ArrayList<>(); + getSources(coreSources, corePath, true); + buildModel.put("platform_core_srcs", coreSources); //$NON-NLS-1$ + + ArduinoPlatform variantPlatform = platform; + String variant = properties.getProperty("build.variant"); //$NON-NLS-1$ + if (variant.contains(":")) { //$NON-NLS-1$ + String[] segments = variant.split(":"); //$NON-NLS-1$ + if (segments.length == 2) { + variantPlatform = manager.getInstalledPlatform(segments[0], platform.getArchitecture()); + variant = segments[1]; + } + } + Path variantPath = variantPlatform.getInstallPath().resolve("variants").resolve(variant); //$NON-NLS-1$ + buildModel.put("platform_variant_path", pathString(variantPath)); //$NON-NLS-1$ + List<String> variantSources = new ArrayList<>(); + getSources(variantSources, variantPath, true); + buildModel.put("platform_variant_srcs", variantSources); //$NON-NLS-1$ properties.put("object_file", "$@"); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("source_file", "$<"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -340,13 +393,27 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te return buildModel; } + private static void getSources(Collection<String> sources, Path dir, boolean recurse) { + for (File file : dir.toFile().listFiles()) { + if (file.isDirectory()) { + if (recurse) { + getSources(sources, file.toPath(), recurse); + } + } else { + if (ArduinoBuildConfiguration.isSource(file.getName())) { + sources.add(ArduinoBuildConfiguration.pathString(file.toPath())); + } + } + } + } + public IFile generateMakeFile(IProgressMonitor monitor) throws CoreException { IFolder buildFolder = (IFolder) getBuildContainer(); if (!buildFolder.exists()) { buildFolder.create(true, true, monitor); } - IFile makefile = getMakeFile(); + IFile makefile = buildFolder.getFile("Makefile"); //$NON-NLS-1$ Map<String, Object> buildModel = getBuildModel(); @@ -402,28 +469,35 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te } } - private String resolvePropertyValue(String value, Properties dict) { + private String resolvePropertyValue(String value, Properties dict) throws CoreException { String last; do { last = value; for (int i = value.indexOf('{'); i >= 0; i = value.indexOf('{', i)) { i++; + if (value.charAt(i) == '{') { + i++; + continue; + } + int n = value.indexOf('}', i); if (n >= 0) { String p2 = value.substring(i, n); String r2 = dict.getProperty(p2); if (r2 != null) { value = value.replace('{' + p2 + '}', r2); + } else { + throw Activator.coreException(String.format("Undefined key %s", p2), null); } } i = n; } } while (!value.equals(last)); - return value; + return value.replace("}}", "}").replace("{{", "{"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } - private String resolveProperty(String property, Properties dict) { + private String resolveProperty(String property, Properties dict) throws CoreException { String value = dict.getProperty(property); return value != null ? resolvePropertyValue(value, dict) : null; } @@ -433,17 +507,17 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te } public String[] getBuildCommand() throws CoreException { - return new String[] { getMakeCommand(), "-f", getMakeFile().getName() }; //$NON-NLS-1$ + return new String[] { getMakeCommand() }; } public String[] getCleanCommand() throws CoreException { - return new String[] { getMakeCommand(), "-f", getMakeFile().getName(), "clean" }; //$NON-NLS-1$ //$NON-NLS-2$ + return new String[] { getMakeCommand(), "clean" }; //$NON-NLS-1$ } public String[] getSizeCommand() throws CoreException { // TODO this shouldn't be in the makefile // should be like the upload command - return new String[] { getMakeCommand(), "-f", getMakeFile().getName(), "size" }; //$NON-NLS-1$ //$NON-NLS-2$ + return new String[] { getMakeCommand(), "size" }; //$NON-NLS-1$ } public String getCodeSizeRegex() throws CoreException { @@ -466,8 +540,21 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te public String[] getUploadCommand(String serialPort) throws CoreException { String toolName = getProperties().getProperty("upload.tool"); //$NON-NLS-1$ + ArduinoPlatform platform = getBoard().getPlatform(); + if (toolName.contains(":")) { //$NON-NLS-1$ + String[] segments = toolName.split(":"); //$NON-NLS-1$ + if (segments.length == 2) { + platform = manager.getInstalledPlatform(segments[0], platform.getArchitecture()); + toolName = segments[1]; + } + } Properties properties = getProperties(); + + ArduinoTool uploadTool = platform.getPackage().getLatestTool(toolName); + if (uploadTool != null) { + properties.putAll(uploadTool.getToolProperties()); + } properties.put("serial.port", serialPort); //$NON-NLS-1$ // Little bit of weirdness needed for the bossac tool @@ -482,7 +569,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te properties.put("config.path", "{tools." + toolName + ".config.path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // properties for the tool flattened - HierarchicalProperties toolsProps = new HierarchicalProperties(getBoard().getPlatform().getPlatformProperties()) + HierarchicalProperties toolsProps = new HierarchicalProperties(platform.getPlatformProperties()) .getChild("tools"); //$NON-NLS-1$ if (toolsProps != null) { HierarchicalProperties toolProps = toolsProps.getChild(toolName); @@ -493,13 +580,14 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te // TODO make this a preference properties.put("upload.verbose", properties.getProperty("upload.params.verbose", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + properties.put("upload.verify", properties.getProperty("upload.params.verify", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // TODO needed this for esptool properties.put("upload.resetmethod", "ck"); //$NON-NLS-1$ //$NON-NLS-2$ String command = resolveProperty("upload.pattern", properties); //$NON-NLS-1$ if (command == null) { - return new String[] { "command not specified" }; //$NON-NLS-1$ + throw Activator.coreException("Upload command not specified", null); } if (isWindows) { return splitCommand(command); @@ -508,6 +596,31 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te } } + private Collection<Path> getIncludePath(ArduinoPlatform platform, Properties properties) throws CoreException { + ArduinoPlatform corePlatform = platform; + String core = properties.getProperty("build.core"); //$NON-NLS-1$ + if (core.contains(":")) { //$NON-NLS-1$ + String[] segments = core.split(":"); //$NON-NLS-1$ + if (segments.length == 2) { + corePlatform = manager.getInstalledPlatform(segments[0], platform.getArchitecture()); + core = segments[1]; + } + } + + ArduinoPlatform variantPlatform = platform; + String variant = properties.getProperty("build.variant"); //$NON-NLS-1$ + if (variant.contains(":")) { //$NON-NLS-1$ + String[] segments = variant.split(":"); //$NON-NLS-1$ + if (segments.length == 2) { + variantPlatform = manager.getInstalledPlatform(segments[0], platform.getArchitecture()); + variant = segments[1]; + } + } + + return Arrays.asList(corePlatform.getInstallPath().resolve("cores").resolve(core), //$NON-NLS-1$ + variantPlatform.getInstallPath().resolve("variants").resolve(variant)); //$NON-NLS-1$ + } + // Scanner Info Cache private String[] cachedIncludePath; private String cachedInfoCommand; @@ -537,14 +650,27 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te String commandString = resolveProperty(recipe, properties); List<Path> includePath = new ArrayList<>(); - includePath.addAll(platform.getIncludePath()); + includePath.addAll(getIncludePath(platform, properties)); Collection<ArduinoLibrary> libs = manager.getLibraries(getProject()); for (ArduinoLibrary lib : libs) { includePath.addAll(lib.getIncludePath()); } - String[] includes = includePath.stream() - .map(path -> resolvePropertyValue(path.toString(), properties)).collect(Collectors.toList()) - .toArray(new String[includePath.size()]); + String[] includes = null; + try { + includes = includePath.stream().map(path -> { + try { + return resolvePropertyValue(path.toString(), properties); + } catch (CoreException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toList()).toArray(new String[includePath.size()]); + } catch (RuntimeException e) { + if (e.getCause() != null && e.getCause() instanceof CoreException) { + throw (CoreException) e.getCause(); + } else { + throw e; + } + } // Use cache if we can if (cachedScannerInfo != null && cachedInfoCommand.equals(commandString) diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfigurationProvider.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfigurationProvider.java index 0dfda4599c2..7b4f6adbe5d 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfigurationProvider.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfigurationProvider.java @@ -39,49 +39,28 @@ public class ArduinoBuildConfigurationProvider implements ICBuildConfigurationPr @Override public ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name) throws CoreException { - return new ArduinoBuildConfiguration(config, name); - } - - @Override - public ICBuildConfiguration getDefaultCBuildConfiguration(IProject project) throws CoreException { - ArduinoBoard board = arduinoManager.getBoard("arduino", "avr", "Arduino/Genuino Uno"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (board == null) { - Collection<ArduinoBoard> boards = arduinoManager.getInstalledBoards(); - if (!boards.isEmpty()) { - board = boards.iterator().next(); - } - } - if (board != null) { - String launchMode = "run"; //$NON-NLS-1$ - for (IBuildConfiguration config : project.getBuildConfigs()) { - ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class); - if (cconfig != null) { - ArduinoBuildConfiguration arduinoConfig = cconfig.getAdapter(ArduinoBuildConfiguration.class); - if (arduinoConfig != null && arduinoConfig.getLaunchMode().equals(launchMode) - && arduinoConfig.getBoard().equals(board)) { - return arduinoConfig; - } + if (config.getName().equals(IBuildConfiguration.DEFAULT_CONFIG_NAME)) { + // Use the good ol' Uno as the default + ArduinoBoard board = arduinoManager.getBoard("arduino", "avr", "uno"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (board == null) { + Collection<ArduinoBoard> boards = arduinoManager.getInstalledBoards(); + if (!boards.isEmpty()) { + board = boards.iterator().next(); } } + if (board != null) { + // Create the toolChain + IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class); + IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID); + IToolChain toolChain = new ArduinoToolChain(provider, config); + toolChainManager.addToolChain(toolChain); - // not found, create one - String configName = ArduinoBuildConfiguration.generateName(board, launchMode); - IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName, - null); - - // Create the toolChain - IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class); - IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID); - IToolChain toolChain = new ArduinoToolChain(provider, config); - toolChainManager.addToolChain(toolChain); - - ArduinoBuildConfiguration arduinoConfig = new ArduinoBuildConfiguration(config, configName, board, - launchMode, toolChain); - arduinoConfig.setActive(null); - configManager.addBuildConfiguration(config, arduinoConfig); - return arduinoConfig; + return new ArduinoBuildConfiguration(config, name, board, "run", toolChain); //$NON-NLS-1$ + } + return null; + } else { + return new ArduinoBuildConfiguration(config, name); } - return null; } public ArduinoBuildConfiguration getConfiguration(IProject project, ArduinoRemoteConnection target, diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoRemoteConnection.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoRemoteConnection.java index 380ec26be88..30d3ca89230 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoRemoteConnection.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoRemoteConnection.java @@ -17,12 +17,15 @@ import java.util.Map; import org.eclipse.cdt.arduino.core.internal.Activator; import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard; import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager; +import org.eclipse.cdt.arduino.core.internal.board.ArduinoPackage; +import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform; import org.eclipse.cdt.serial.SerialPort; import org.eclipse.core.runtime.CoreException; import org.eclipse.remote.core.IRemoteCommandShellService; import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnectionChangeListener; import org.eclipse.remote.core.IRemoteConnectionPropertyService; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.RemoteConnectionChangeEvent; import org.eclipse.remote.serial.core.SerialPortCommandShell; @@ -31,10 +34,12 @@ public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService, IRemoteCommandShellService, IRemoteConnectionChangeListener { public static final String TYPE_ID = "org.eclipse.cdt.arduino.core.connectionType"; //$NON-NLS-1$ - public static final String PORT_NAME = "arduinoPortName"; //$NON-NLS-1$ - public static final String PACKAGE_NAME = "arduinoPackageName"; //$NON-NLS-1$ - public static final String PLATFORM_NAME = "arduinoPlatformName"; //$NON-NLS-1$ - public static final String BOARD_NAME = "arduinoBoardName"; //$NON-NLS-1$ + + private static final String PORT_NAME = "arduinoPortName"; //$NON-NLS-1$ + private static final String PACKAGE_NAME = "arduinoPackageName"; //$NON-NLS-1$ + private static final String PLATFORM_NAME = "arduinoPlatformName"; //$NON-NLS-1$ + private static final String BOARD_NAME = "arduinoBoardName"; //$NON-NLS-1$ + private static final String MENU_QUALIFIER = "menu_"; //$NON-NLS-1$ private final IRemoteConnection remoteConnection; private SerialPort serialPort; @@ -47,6 +52,28 @@ public class ArduinoRemoteConnection remoteConnection.addConnectionChangeListener(this); } + public static void setBoardId(IRemoteConnectionWorkingCopy workingCopy, ArduinoBoard board) { + workingCopy.setAttribute(BOARD_NAME, board.getId()); + + ArduinoPlatform platform = board.getPlatform(); + workingCopy.setAttribute(PLATFORM_NAME, platform.getArchitecture()); + + ArduinoPackage pkg = platform.getPackage(); + workingCopy.setAttribute(PACKAGE_NAME, pkg.getName()); + } + + public static void setPortName(IRemoteConnectionWorkingCopy workingCopy, String portName) { + workingCopy.setAttribute(PORT_NAME, portName); + } + + public static void setMenuValue(IRemoteConnectionWorkingCopy workingCopy, String key, String value) { + workingCopy.setAttribute(MENU_QUALIFIER + key, value); + } + + public String getMenuValue(String key) { + return remoteConnection.getAttribute(MENU_QUALIFIER + key); + } + @Override public void connectionChanged(RemoteConnectionChangeEvent event) { if (event.getType() == RemoteConnectionChangeEvent.CONNECTION_REMOVED) { diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/Makefile b/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/Makefile index 48888521aa8..82ec9471ff9 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/Makefile +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/Makefile @@ -15,19 +15,35 @@ PROJECT_OBJS = \ </#if> </#list> -PLATFORM_OBJS = \ -<#list platform_srcs as file> -<#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")> +PLATFORM_CORE_OBJS = \ +<#list platform_core_srcs as file> +<#assign cpp = file?matches("${platform_core_path}/(.*)\\.cpp")> <#if cpp> - ${build_path}/platform/${cpp?groups[1]}.cpp.o \ + ${build_path}/core/${cpp?groups[1]}.cpp.o \ </#if> -<#assign c = file?matches("${platform_path}/(.*)\\.c")> +<#assign c = file?matches("${platform_core_path}/(.*)\\.c")> <#if c> - ${build_path}/platform/${c?groups[1]}.c.o \ + ${build_path}/core/${c?groups[1]}.c.o \ </#if> -<#assign S = file?matches("${platform_path}/(.*)\\.S")> +<#assign S = file?matches("${platform_core_path}/(.*)\\.S")> <#if S> - ${build_path}/platform/${S?groups[1]}.S.o \ + ${build_path}/core/${S?groups[1]}.S.o \ +</#if> +</#list> + +PLATFORM_VARIANT_OBJS = \ +<#list platform_variant_srcs as file> +<#assign cpp = file?matches("${platform_variant_path}/(.*)\\.cpp")> +<#if cpp> + ${build_path}/variant/${cpp?groups[1]}.cpp.o \ +</#if> +<#assign c = file?matches("${platform_variant_path}/(.*)\\.c")> +<#if c> + ${build_path}/variant/${c?groups[1]}.c.o \ +</#if> +<#assign S = file?matches("${platform_variant_path}/(.*)\\.S")> +<#if S> + ${build_path}/variant/${S?groups[1]}.S.o \ </#if> </#list> @@ -80,7 +96,7 @@ ${build_path}/${project_name}.bin: ${build_path}/${project_name}.elf ${build_path}/${project_name}.elf: $(PROJECT_OBJS) $(LIBRARIES_OBJS) ${build_path}/core.a ${recipe_c_combine_pattern} -${build_path}/core.a: $(PLATFORM_OBJS) +${build_path}/core.a: $(PLATFORM_CORE_OBJS) $(PLATFORM_VARIANT_OBJS) clean: $(RMDIR) ${build_path} @@ -102,34 +118,69 @@ ${build_path}/project/${cpp?groups[1]}.cpp.d: ; </#if> </#list> -<#list platform_srcs as file> -<#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")> +<#list platform_core_srcs as file> +<#assign cpp = file?matches("${platform_core_path}/(.*)\\.cpp")> +<#if cpp> +${build_path}/core/${cpp?groups[1]}.cpp.o: ${file} ${build_path}/core/${cpp?groups[1]}.cpp.d + @$(call mymkdir,$(dir $@)) + ${recipe_cpp_o_pattern} + ${recipe_ar_pattern} + +${build_path}/core/${cpp?groups[1]}.cpp.d: ; + +-include ${build_path}/core/${cpp?groups[1]}.cpp.d + +</#if> +<#assign c = file?matches("${platform_core_path}/(.*)\\.c")> +<#if c> +${build_path}/core/${c?groups[1]}.c.o: ${file} ${build_path}/core/${c?groups[1]}.c.d + @$(call mymkdir,$(dir $@)) + ${recipe_c_o_pattern} + ${recipe_ar_pattern} + +${build_path}/core/${c?groups[1]}.c.d: ; + +-include ${build_path}/core/${c?groups[1]}.c.d + +</#if> +<#assign S = file?matches("${platform_core_path}/(.*)\\.S")> +<#if S> +${build_path}/core/${S?groups[1]}.S.o: ${file} + @$(call mymkdir,$(dir $@)) + ${recipe_S_o_pattern} + ${recipe_ar_pattern} + +</#if> +</#list> + +<#list platform_variant_srcs as file> +<#assign cpp = file?matches("${platform_variant_path}/(.*)\\.cpp")> <#if cpp> -${build_path}/platform/${cpp?groups[1]}.cpp.o: ${file} ${build_path}/platform/${cpp?groups[1]}.cpp.d +${build_path}/variant/${cpp?groups[1]}.cpp.o: ${file} ${build_path}/variant/${cpp?groups[1]}.cpp.d @$(call mymkdir,$(dir $@)) ${recipe_cpp_o_pattern} ${recipe_ar_pattern} -${build_path}/platform/${cpp?groups[1]}.cpp.d: ; +${build_path}/variant/${cpp?groups[1]}.cpp.d: ; --include ${build_path}/platform/${cpp?groups[1]}.cpp.d +-include ${build_path}/variant/${cpp?groups[1]}.cpp.d </#if> -<#assign c = file?matches("${platform_path}/(.*)\\.c")> +<#assign c = file?matches("${platform_variant_path}/(.*)\\.c")> <#if c> -${build_path}/platform/${c?groups[1]}.c.o: ${file} ${build_path}/platform/${c?groups[1]}.c.d +${build_path}/variant/${c?groups[1]}.c.o: ${file} ${build_path}/variant/${c?groups[1]}.c.d @$(call mymkdir,$(dir $@)) ${recipe_c_o_pattern} ${recipe_ar_pattern} -${build_path}/platform/${c?groups[1]}.c.d: ; +${build_path}/variant/${c?groups[1]}.c.d: ; --include ${build_path}/platform/${c?groups[1]}.c.d +-include ${build_path}/variant/${c?groups[1]}.c.d </#if> -<#assign S = file?matches("${platform_path}/(.*)\\.S")> +<#assign S = file?matches("${platform_variant_path}/(.*)\\.S")> <#if S> -${build_path}/platform/${S?groups[1]}.S.o: ${file} +${build_path}/variant/${S?groups[1]}.S.o: ${file} @$(call mymkdir,$(dir $@)) ${recipe_S_o_pattern} ${recipe_ar_pattern} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/plugin.xml b/toolchains/arduino/org.eclipse.cdt.arduino.ui/plugin.xml index fa5d081dea3..36d3d0218ac 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.ui/plugin.xml +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/plugin.xml @@ -86,12 +86,6 @@ id="org.eclipse.cdt.arduino.preference.page" name="%preferencePage.name"> </page> - <page - category="org.eclipse.cdt.arduino.preference.page" - class="org.eclipse.cdt.arduino.ui.internal.preferences.ArduinoPlatformsPreferencePage" - id="org.eclipse.cdt.arduino.ui.page.platforms" - name="Platforms"> - </page> </extension> <extension point="org.eclipse.ui.perspectiveExtensions"> diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoTargetPropertyPage.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoTargetPropertyPage.java index 63cdd9dbaaa..a024a3aa821 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoTargetPropertyPage.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoTargetPropertyPage.java @@ -96,15 +96,11 @@ public class ArduinoTargetPropertyPage extends PropertyPage implements IWorkbenc IRemoteConnection remoteConnection = getElement().getAdapter(IRemoteConnection.class); IRemoteConnectionWorkingCopy workingCopy = remoteConnection.getWorkingCopy(); - String portName = portSelector.getItem(portSelector.getSelectionIndex()); - workingCopy.setAttribute(ArduinoRemoteConnection.PORT_NAME, portName); - ArduinoBoard board = boards[boardSelector.getSelectionIndex()]; - workingCopy.setAttribute(ArduinoRemoteConnection.BOARD_NAME, board.getId()); - ArduinoPlatform platform = board.getPlatform(); - workingCopy.setAttribute(ArduinoRemoteConnection.PLATFORM_NAME, platform.getArchitecture()); - ArduinoPackage pkg = platform.getPackage(); - workingCopy.setAttribute(ArduinoRemoteConnection.PACKAGE_NAME, pkg.getName()); + ArduinoRemoteConnection.setBoardId(workingCopy, board); + + String portName = portSelector.getItem(portSelector.getSelectionIndex()); + ArduinoRemoteConnection.setPortName(workingCopy, portName); try { workingCopy.save(); diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/BoardPropertyControl.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/BoardPropertyControl.java index b0bfacd1808..38362faf463 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/BoardPropertyControl.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/BoardPropertyControl.java @@ -188,15 +188,8 @@ public class BoardPropertyControl extends Composite { } public void apply(IRemoteConnectionWorkingCopy workingCopy) { - workingCopy.setAttribute(ArduinoRemoteConnection.PORT_NAME, portName); - - workingCopy.setAttribute(ArduinoRemoteConnection.BOARD_NAME, board.getId()); - - ArduinoPlatform platform = board.getPlatform(); - workingCopy.setAttribute(ArduinoRemoteConnection.PLATFORM_NAME, platform.getArchitecture()); - - ArduinoPackage pkg = platform.getPackage(); - workingCopy.setAttribute(ArduinoRemoteConnection.PACKAGE_NAME, pkg.getName()); + ArduinoRemoteConnection.setBoardId(workingCopy, board); + ArduinoRemoteConnection.setPortName(workingCopy, portName); String key = null; for (Control control : menuControls) { @@ -208,7 +201,7 @@ public class BoardPropertyControl extends Composite { String value = ((List<String>) combo.getData()).get(combo.getSelectionIndex()); if (key != null) { - workingCopy.setAttribute(ArduinoBoard.MENU_QUALIFIER + key, value); + ArduinoRemoteConnection.setMenuValue(workingCopy, key, value); } } } |