mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
[Arduino] Fix up derivation of upload command.
Change-Id: I97caa1e9ca954d1a60a1fe9e73daa3cf2e0d439e
This commit is contained in:
parent
66f822e464
commit
8990e95620
3 changed files with 59 additions and 16 deletions
|
@ -53,14 +53,14 @@ public class FullIntegration {
|
||||||
ArduinoPreferences.setBoardUrlList(urls);
|
ArduinoPreferences.setBoardUrlList(urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<ArduinoBoard> getSkipBoards() throws Exception {
|
private Set<ArduinoBoard> getSkipBuild() throws Exception {
|
||||||
Set<ArduinoBoard> boards = new HashSet<ArduinoBoard>();
|
Set<ArduinoBoard> boards = new HashSet<>();
|
||||||
|
|
||||||
// Fails in arduino too
|
// Fails in arduino too
|
||||||
boards.add(arduinoManager.getBoard("arduino", "avr", "robotControl"));
|
boards.add(arduinoManager.getBoard("arduino", "avr", "robotControl"));
|
||||||
boards.add(arduinoManager.getBoard("arduino", "avr", "robotMotor"));
|
boards.add(arduinoManager.getBoard("arduino", "avr", "robotMotor"));
|
||||||
boards.add(arduinoManager.getBoard("adafruit", "avr", "adafruit32u4"));
|
boards.add(arduinoManager.getBoard("adafruit", "avr", "adafruit32u4"));
|
||||||
|
|
||||||
// TODO Need to add support for menu specific build properties
|
// TODO Need to add support for menu specific build properties
|
||||||
boards.add(arduinoManager.getBoard("arduino", "avr", "mini"));
|
boards.add(arduinoManager.getBoard("arduino", "avr", "mini"));
|
||||||
boards.add(arduinoManager.getBoard("arduino", "avr", "lilypad"));
|
boards.add(arduinoManager.getBoard("arduino", "avr", "lilypad"));
|
||||||
|
@ -73,7 +73,7 @@ public class FullIntegration {
|
||||||
boards.add(arduinoManager.getBoard("TeeOnArdu", "avr", "CirPlayTeensyCore"));
|
boards.add(arduinoManager.getBoard("TeeOnArdu", "avr", "CirPlayTeensyCore"));
|
||||||
boards.add(arduinoManager.getBoard("TeeOnArdu", "avr", "FloraTeensyCore"));
|
boards.add(arduinoManager.getBoard("TeeOnArdu", "avr", "FloraTeensyCore"));
|
||||||
boards.add(arduinoManager.getBoard("TeeOnArdu", "avr", "TeeOnArdu"));
|
boards.add(arduinoManager.getBoard("TeeOnArdu", "avr", "TeeOnArdu"));
|
||||||
|
|
||||||
// TODO build.system.path missing
|
// TODO build.system.path missing
|
||||||
boards.add(arduinoManager.getBoard("arduino", "sam", "arduino_due_x"));
|
boards.add(arduinoManager.getBoard("arduino", "sam", "arduino_due_x"));
|
||||||
boards.add(arduinoManager.getBoard("arduino", "sam", "arduino_due_x_dbg"));
|
boards.add(arduinoManager.getBoard("arduino", "sam", "arduino_due_x_dbg"));
|
||||||
|
@ -82,6 +82,22 @@ public class FullIntegration {
|
||||||
return boards;
|
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
|
@Test
|
||||||
public void runTest() throws Exception {
|
public void runTest() throws Exception {
|
||||||
IProgressMonitor monitor = new SysoutProgressMonitor();
|
IProgressMonitor monitor = new SysoutProgressMonitor();
|
||||||
|
@ -90,11 +106,12 @@ public class FullIntegration {
|
||||||
setBoardUrls();
|
setBoardUrls();
|
||||||
loadPlatforms(monitor);
|
loadPlatforms(monitor);
|
||||||
|
|
||||||
|
Set<ArduinoBoard> skipBuild = getSkipBuild();
|
||||||
|
Set<ArduinoBoard> skipUpload = getSkipUpload();
|
||||||
IProject project = createProject(monitor);
|
IProject project = createProject(monitor);
|
||||||
Set<ArduinoBoard> skip = getSkipBoards();
|
|
||||||
for (ArduinoBoard board : arduinoManager.getInstalledBoards()) {
|
for (ArduinoBoard board : arduinoManager.getInstalledBoards()) {
|
||||||
if (!skip.contains(board)) {
|
if (!skipBuild.contains(board)) {
|
||||||
buildBoard(project, board, monitor);
|
buildBoard(project, board, !skipUpload.contains(board), monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +155,7 @@ public class FullIntegration {
|
||||||
return generator.getProject();
|
return generator.getProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildBoard(IProject project, ArduinoBoard board, IProgressMonitor monitor) throws Exception {
|
private void buildBoard(IProject project, ArduinoBoard board, boolean upload, IProgressMonitor monitor) throws Exception {
|
||||||
ArduinoRemoteConnection arduinoTarget = createTarget(board);
|
ArduinoRemoteConnection arduinoTarget = createTarget(board);
|
||||||
ArduinoBuildConfigurationProvider provider = (ArduinoBuildConfigurationProvider) buildConfigManager
|
ArduinoBuildConfigurationProvider provider = (ArduinoBuildConfigurationProvider) buildConfigManager
|
||||||
.getProvider(ArduinoBuildConfigurationProvider.ID);
|
.getProvider(ArduinoBuildConfigurationProvider.ID);
|
||||||
|
@ -156,6 +173,11 @@ public class FullIntegration {
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
throw new Exception("Build failed");
|
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 {
|
private ArduinoRemoteConnection createTarget(ArduinoBoard board) throws Exception {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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.ArduinoPreferences;
|
||||||
import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
|
import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
|
||||||
import org.eclipse.cdt.arduino.core.internal.Messages;
|
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.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
|
|
@ -225,13 +225,17 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
|
||||||
properties.put("build.variant.path", //$NON-NLS-1$
|
properties.put("build.variant.path", //$NON-NLS-1$
|
||||||
platform.getInstallPath().resolve("variants").resolve("{build.variant}").toString()); //$NON-NLS-1$ //$NON-NLS-2$
|
platform.getInstallPath().resolve("variants").resolve("{build.variant}").toString()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
// Everyone seems to want to use the avr-gcc tool.
|
// Everyone seems to want to use the avr-gcc and avrdude tools
|
||||||
ArduinoPackage arduinoPackage = manager.getPackage("arduino"); //$NON-NLS-1$
|
ArduinoPackage arduinoPackage = manager.getPackage("arduino"); //$NON-NLS-1$
|
||||||
ArduinoTool avrgcc = arduinoPackage.getLatestTool("avr-gcc"); //$NON-NLS-1$
|
ArduinoTool avrgcc = arduinoPackage.getLatestTool("avr-gcc"); //$NON-NLS-1$
|
||||||
if (avrgcc != null) {
|
if (avrgcc != null) {
|
||||||
properties.put("runtime.tools.avr-gcc.path", avrgcc.getInstallPath().toString()); //$NON-NLS-1$
|
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
|
// Super Platform
|
||||||
String core = board.getBoardProperties().getProperty("build.core"); //$NON-NLS-1$
|
String core = board.getBoardProperties().getProperty("build.core"); //$NON-NLS-1$
|
||||||
if (core.contains(":")) { //$NON-NLS-1$
|
if (core.contains(":")) { //$NON-NLS-1$
|
||||||
|
@ -471,6 +475,11 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
|
||||||
last = value;
|
last = value;
|
||||||
for (int i = value.indexOf('{'); i >= 0; i = value.indexOf('{', i)) {
|
for (int i = value.indexOf('{'); i >= 0; i = value.indexOf('{', i)) {
|
||||||
i++;
|
i++;
|
||||||
|
if (value.charAt(i) == '{') {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int n = value.indexOf('}', i);
|
int n = value.indexOf('}', i);
|
||||||
if (n >= 0) {
|
if (n >= 0) {
|
||||||
String p2 = value.substring(i, n);
|
String p2 = value.substring(i, n);
|
||||||
|
@ -485,7 +494,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
|
||||||
}
|
}
|
||||||
} while (!value.equals(last));
|
} 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) throws CoreException {
|
private String resolveProperty(String property, Properties dict) throws CoreException {
|
||||||
|
@ -531,8 +540,21 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
|
||||||
|
|
||||||
public String[] getUploadCommand(String serialPort) throws CoreException {
|
public String[] getUploadCommand(String serialPort) throws CoreException {
|
||||||
String toolName = getProperties().getProperty("upload.tool"); //$NON-NLS-1$
|
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();
|
Properties properties = getProperties();
|
||||||
|
|
||||||
|
ArduinoTool uploadTool = platform.getPackage().getLatestTool(toolName);
|
||||||
|
if (uploadTool != null) {
|
||||||
|
properties.putAll(uploadTool.getToolProperties());
|
||||||
|
}
|
||||||
|
|
||||||
properties.put("serial.port", serialPort); //$NON-NLS-1$
|
properties.put("serial.port", serialPort); //$NON-NLS-1$
|
||||||
// Little bit of weirdness needed for the bossac tool
|
// Little bit of weirdness needed for the bossac tool
|
||||||
|
@ -547,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.put("config.path", "{tools." + toolName + ".config.path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
|
||||||
// properties for the tool flattened
|
// properties for the tool flattened
|
||||||
HierarchicalProperties toolsProps = new HierarchicalProperties(getBoard().getPlatform().getPlatformProperties())
|
HierarchicalProperties toolsProps = new HierarchicalProperties(platform.getPlatformProperties())
|
||||||
.getChild("tools"); //$NON-NLS-1$
|
.getChild("tools"); //$NON-NLS-1$
|
||||||
if (toolsProps != null) {
|
if (toolsProps != null) {
|
||||||
HierarchicalProperties toolProps = toolsProps.getChild(toolName);
|
HierarchicalProperties toolProps = toolsProps.getChild(toolName);
|
||||||
|
@ -558,13 +580,14 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
|
||||||
|
|
||||||
// TODO make this a preference
|
// 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.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
|
// TODO needed this for esptool
|
||||||
properties.put("upload.resetmethod", "ck"); //$NON-NLS-1$ //$NON-NLS-2$
|
properties.put("upload.resetmethod", "ck"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
String command = resolveProperty("upload.pattern", properties); //$NON-NLS-1$
|
String command = resolveProperty("upload.pattern", properties); //$NON-NLS-1$
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
return new String[] { "command not specified" }; //$NON-NLS-1$
|
throw Activator.coreException("Upload command not specified", null);
|
||||||
}
|
}
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
return splitCommand(command);
|
return splitCommand(command);
|
||||||
|
|
Loading…
Add table
Reference in a new issue