mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 01:35:39 +02:00
Build and Launch working on Windows.
Had to convert backslashes in paths to forward slashes. Also had figure out how to call the compiler for scanner info. Had to break the command up myself into args. Change-Id: I08f1438d8c17bb92a8871d4bd6e187af4e8a49f7
This commit is contained in:
parent
086de101df
commit
3e704522ba
4 changed files with 68 additions and 28 deletions
|
@ -12,6 +12,8 @@ import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.net.URL;
|
||||||
|
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.Arrays;
|
||||||
|
@ -198,7 +200,19 @@ public class ArduinoPlatform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO on Windows install make from equations.org
|
// On Windows install make from equations.org
|
||||||
|
try {
|
||||||
|
Path makePath = ArduinoPreferences.getArduinoHome().resolve("tools/make/make.exe");
|
||||||
|
if (!makePath.toFile().exists()) {
|
||||||
|
Files.createDirectories(makePath.getParent());
|
||||||
|
URL makeUrl = new URL("ftp://ftp.equation.com/make/32/make.exe");
|
||||||
|
Files.copy(makeUrl.openStream(), makePath);
|
||||||
|
makePath.toFile().setExecutable(true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
mstatus.add(new Status(IStatus.ERROR, Activator.getId(), "downloading make.exe", e));
|
||||||
|
}
|
||||||
|
|
||||||
return mstatus != null ? mstatus : Status.OK_STATUS;
|
return mstatus != null ? mstatus : Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Properties;
|
||||||
|
|
||||||
import org.eclipse.cdt.arduino.core.internal.Activator;
|
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.build.ArduinoBuildConfiguration;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
@ -74,7 +75,7 @@ public class ArduinoTool {
|
||||||
|
|
||||||
public Properties getToolProperties() {
|
public Properties getToolProperties() {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.put("runtime.tools." + name + ".path", getInstallPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$
|
properties.put("runtime.tools." + name + ".path", ArduinoBuildConfiguration.pathString(getInstallPath())); // $NON-NLS-1$ //$NON-NLS-2$
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdapterFactory;
|
import org.eclipse.core.runtime.IAdapterFactory;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||||
import org.osgi.service.prefs.BackingStoreException;
|
import org.osgi.service.prefs.BackingStoreException;
|
||||||
|
@ -71,6 +72,8 @@ public class ArduinoBuildConfiguration {
|
||||||
private IScannerInfo cScannerInfo;
|
private IScannerInfo cScannerInfo;
|
||||||
private IScannerInfo cppScannerInfo;
|
private IScannerInfo cppScannerInfo;
|
||||||
|
|
||||||
|
private final static boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32);
|
||||||
|
|
||||||
private ArduinoBuildConfiguration(IBuildConfiguration config) {
|
private ArduinoBuildConfiguration(IBuildConfiguration config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +248,7 @@ public class ArduinoBuildConfiguration {
|
||||||
if (proxy.getType() == IResource.FILE) {
|
if (proxy.getType() == IResource.FILE) {
|
||||||
if (CoreModel.isValidSourceUnitName(project, proxy.getName())) {
|
if (CoreModel.isValidSourceUnitName(project, proxy.getName())) {
|
||||||
Path sourcePath = new File(proxy.requestResource().getLocationURI()).toPath();
|
Path sourcePath = new File(proxy.requestResource().getLocationURI()).toPath();
|
||||||
sourceFiles.add(projectPath.relativize(sourcePath).toString());
|
sourceFiles.add(pathString(projectPath.relativize(sourcePath)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -258,11 +261,11 @@ public class ArduinoBuildConfiguration {
|
||||||
List<String> librarySources = new ArrayList<>();
|
List<String> librarySources = new ArrayList<>();
|
||||||
for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
|
for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
|
||||||
for (Path path : lib.getSources(project)) {
|
for (Path path : lib.getSources(project)) {
|
||||||
librarySources.add(path.toString());
|
librarySources.add(pathString(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildModel.put("libraries_srcs", librarySources); //$NON-NLS-1$
|
buildModel.put("libraries_srcs", librarySources); //$NON-NLS-1$
|
||||||
buildModel.put("libraries_path", ArduinoPreferences.getArduinoHome().resolve("libraries")); //$NON-NLS-1$ //$NON-NLS-2$
|
buildModel.put("libraries_path", pathString(ArduinoPreferences.getArduinoHome().resolve("libraries"))); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
// the recipes
|
// the recipes
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
@ -277,17 +280,17 @@ public class ArduinoBuildConfiguration {
|
||||||
} else {
|
} else {
|
||||||
includes += " -I"; //$NON-NLS-1$
|
includes += " -I"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
includes += '"' + include.toString() + '"';
|
includes += '"' + pathString(include) + '"';
|
||||||
}
|
}
|
||||||
for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
|
for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
|
||||||
for (Path include : lib.getIncludePath()) {
|
for (Path include : lib.getIncludePath()) {
|
||||||
includes += " -I\"" + include.toString() + '"'; //$NON-NLS-1$
|
includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
properties.put("includes", includes); //$NON-NLS-1$
|
properties.put("includes", includes); //$NON-NLS-1$
|
||||||
|
|
||||||
Path platformPath = platform.getInstallPath();
|
Path platformPath = platform.getInstallPath();
|
||||||
buildModel.put("platform_path", platformPath.toString()); //$NON-NLS-1$
|
buildModel.put("platform_path", pathString(platformPath)); //$NON-NLS-1$
|
||||||
|
|
||||||
Path corePath = platformPath.resolve("cores").resolve((String) properties.get("build.core")); //$NON-NLS-1$ //$NON-NLS-2$
|
Path corePath = platformPath.resolve("cores").resolve((String) properties.get("build.core")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
File[] platformFiles = corePath.toFile().listFiles(new FilenameFilter() {
|
File[] platformFiles = corePath.toFile().listFiles(new FilenameFilter() {
|
||||||
|
@ -298,10 +301,8 @@ public class ArduinoBuildConfiguration {
|
||||||
});
|
});
|
||||||
|
|
||||||
String[] platformSource = new String[platformFiles.length];
|
String[] platformSource = new String[platformFiles.length];
|
||||||
for (int i = 0; i < platformSource.length; ++i)
|
for (int i = 0; i < platformSource.length; ++i) {
|
||||||
|
platformSource[i] = pathString(platformFiles[i].toPath());
|
||||||
{
|
|
||||||
platformSource[i] = platformFiles[i].getAbsolutePath();
|
|
||||||
}
|
}
|
||||||
buildModel.put("platform_srcs", platformSource); //$NON-NLS-1$
|
buildModel.put("platform_srcs", platformSource); //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -351,7 +352,7 @@ public class ArduinoBuildConfiguration {
|
||||||
|
|
||||||
public void setEnvironment(Map<String, String> env) throws CoreException {
|
public void setEnvironment(Map<String, String> env) throws CoreException {
|
||||||
// Arduino home to find platforms and libraries
|
// Arduino home to find platforms and libraries
|
||||||
env.put("ARDUINO_HOME", ArduinoPreferences.getArduinoHome().toString()); //$NON-NLS-1$
|
env.put("ARDUINO_HOME", pathString(ArduinoPreferences.getArduinoHome())); //$NON-NLS-1$
|
||||||
|
|
||||||
// Add tools to the path
|
// Add tools to the path
|
||||||
String pathKey = null;
|
String pathKey = null;
|
||||||
|
@ -364,7 +365,11 @@ public class ArduinoBuildConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> toolPaths = new ArrayList<>();
|
List<Path> toolPaths = new ArrayList<>();
|
||||||
|
if (isWindows) {
|
||||||
|
// Add in the tools/make directory to pick up make
|
||||||
|
toolPaths.add(ArduinoPreferences.getArduinoHome().resolve("tools/make"));
|
||||||
|
}
|
||||||
ArduinoBoard board = getBoard();
|
ArduinoBoard board = getBoard();
|
||||||
ArduinoPlatform platform = board.getPlatform();
|
ArduinoPlatform platform = board.getPlatform();
|
||||||
for (ToolDependency dep : platform.getToolsDependencies()) {
|
for (ToolDependency dep : platform.getToolsDependencies()) {
|
||||||
|
@ -372,17 +377,17 @@ public class ArduinoBuildConfiguration {
|
||||||
Path installPath = tool.getInstallPath();
|
Path installPath = tool.getInstallPath();
|
||||||
Path binPath = installPath.resolve("bin"); //$NON-NLS-1$
|
Path binPath = installPath.resolve("bin"); //$NON-NLS-1$
|
||||||
if (binPath.toFile().exists()) {
|
if (binPath.toFile().exists()) {
|
||||||
toolPaths.add(binPath.toString());
|
toolPaths.add(binPath);
|
||||||
} else {
|
} else {
|
||||||
// use the install dir by default
|
// use the install dir by default
|
||||||
toolPaths.add(installPath.toString());
|
toolPaths.add(installPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String toolPath : toolPaths) {
|
for (Path toolPath : toolPaths) {
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
path = toolPath + File.pathSeparatorChar + path;
|
path = pathString(toolPath) + File.pathSeparatorChar + path;
|
||||||
} else {
|
} else {
|
||||||
path = toolPath;
|
path = pathString(toolPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pathKey == null) {
|
if (pathKey == null) {
|
||||||
|
@ -428,7 +433,7 @@ public class ArduinoBuildConfiguration {
|
||||||
ArduinoTool tool = board.getPlatform().getTool(toolName);
|
ArduinoTool tool = board.getPlatform().getTool(toolName);
|
||||||
|
|
||||||
Properties properties = getProperties();
|
Properties properties = getProperties();
|
||||||
properties.put("runtime.tools." + toolName + ".path", tool.getInstallPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$
|
properties.put("runtime.tools." + toolName + ".path", pathString(tool.getInstallPath())); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
properties.put("serial.port", serialPort); //$NON-NLS-1$
|
properties.put("serial.port", serialPort); //$NON-NLS-1$
|
||||||
// to make up for some cheating in the platform.txt file
|
// to make up for some cheating in the platform.txt file
|
||||||
properties.put("path", "{tools." + toolName + ".path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
properties.put("path", "{tools." + toolName + ".path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
@ -438,8 +443,11 @@ public class ArduinoBuildConfiguration {
|
||||||
properties.put("upload.verbose", "{tools." + toolName + ".upload.params.quiet}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
properties.put("upload.verbose", "{tools." + toolName + ".upload.params.quiet}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
|
||||||
String command = resolveProperty("tools." + toolName + ".upload.pattern", properties); //$NON-NLS-1$ //$NON-NLS-2$
|
String command = resolveProperty("tools." + toolName + ".upload.pattern", properties); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
// TODO Windows
|
if (isWindows) {
|
||||||
return new String[] { "sh", "-c", command }; //$NON-NLS-1$ //$NON-NLS-2$
|
return splitCommand(command);
|
||||||
|
} else {
|
||||||
|
return new String[] { "sh", "-c", command }; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IScannerInfo getScannerInfo(IResource resource) throws CoreException {
|
public IScannerInfo getScannerInfo(IResource resource) throws CoreException {
|
||||||
|
@ -464,6 +472,14 @@ public class ArduinoBuildConfiguration {
|
||||||
cScannerInfo = null;
|
cScannerInfo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String pathString(Path path) {
|
||||||
|
String str = path.toString();
|
||||||
|
if (isWindows) {
|
||||||
|
str = str.replaceAll("\\\\", "/");
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
private IScannerInfo calculateScannerInfo(String recipe, IResource resource) throws CoreException {
|
private IScannerInfo calculateScannerInfo(String recipe, IResource resource) throws CoreException {
|
||||||
try {
|
try {
|
||||||
ArduinoPlatform platform = getBoard().getPlatform();
|
ArduinoPlatform platform = getBoard().getPlatform();
|
||||||
|
@ -471,23 +487,27 @@ public class ArduinoBuildConfiguration {
|
||||||
properties.putAll(getProperties());
|
properties.putAll(getProperties());
|
||||||
|
|
||||||
Path tmpFile = Files.createTempFile("cdt", ".cpp"); //$NON-NLS-1$ //$NON-NLS-2$
|
Path tmpFile = Files.createTempFile("cdt", ".cpp"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
properties.put("source_file", tmpFile.toString()); //$NON-NLS-1$
|
properties.put("source_file", pathString(tmpFile)); //$NON-NLS-1$
|
||||||
properties.put("object_file", "-"); //$NON-NLS-1$ //$NON-NLS-2$
|
properties.put("object_file", "-"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
String includes = "-E -P -v -dD"; //$NON-NLS-1$
|
String includes = "-E -P -v -dD"; //$NON-NLS-1$
|
||||||
for (Path include : platform.getIncludePath()) {
|
for (Path include : platform.getIncludePath()) {
|
||||||
includes += " -I\"" + include.toString() + '"'; //$NON-NLS-1$
|
includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
Collection<ArduinoLibrary> libs = ArduinoManager.instance.getLibraries(config.getProject());
|
Collection<ArduinoLibrary> libs = ArduinoManager.instance.getLibraries(config.getProject());
|
||||||
for (ArduinoLibrary lib : libs) {
|
for (ArduinoLibrary lib : libs) {
|
||||||
for (Path path : lib.getIncludePath()) {
|
for (Path path : lib.getIncludePath()) {
|
||||||
includes += " -I\"" + path.toString() + '"'; //$NON-NLS-1$
|
includes += " -I\"" + pathString(path) + '"'; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
properties.put("includes", includes); //$NON-NLS-1$
|
properties.put("includes", includes); //$NON-NLS-1$
|
||||||
|
|
||||||
// TODO Windows
|
String[] command;
|
||||||
String[] command = new String[] { "sh", "-c", resolveProperty(recipe, properties) }; //$NON-NLS-1$ //$NON-NLS-2$
|
if (isWindows) {
|
||||||
|
command = splitCommand(resolveProperty(recipe, properties));
|
||||||
|
} else {
|
||||||
|
command = new String[] { "sh", "-c", resolveProperty(recipe, properties) }; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(tmpFile.getParent().toFile())
|
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(tmpFile.getParent().toFile())
|
||||||
.redirectErrorStream(true);
|
.redirectErrorStream(true);
|
||||||
setEnvironment(processBuilder.environment());
|
setEnvironment(processBuilder.environment());
|
||||||
|
@ -524,6 +544,11 @@ public class ArduinoBuildConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String[] splitCommand(String command) {
|
||||||
|
// TODO deal with quotes properly, for now just strip
|
||||||
|
return command.replaceAll("\"", "").split("\\s+");
|
||||||
|
}
|
||||||
|
|
||||||
public ArduinoConsoleParser[] getBuildConsoleParsers() {
|
public ArduinoConsoleParser[] getBuildConsoleParsers() {
|
||||||
// ../src/Test.cpp:4:1: error: 'x' was not declared in this scope
|
// ../src/Test.cpp:4:1: error: 'x' was not declared in this scope
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
RMDIR = rmdir /s /q
|
RMDIR = rmdir /s /q
|
||||||
mymkdir = if not exist "$(call fixpath,$1)" mkdir $(call fixpath,$1)
|
mymkdir = if not exist "$1" mkdir "$1"
|
||||||
else
|
else
|
||||||
RMDIR = rm -fr
|
RMDIR = rm -fr
|
||||||
mymkdir = mkdir -p $1
|
mymkdir = mkdir -p $1
|
||||||
|
|
Loading…
Add table
Reference in a new issue