From 3c105249e81f057339552f2361cd288361010580 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Wed, 26 Aug 2015 21:50:14 -0400 Subject: [PATCH] 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 --- .../core/internal/board/ArduinoPlatform.java | 16 +++- .../core/internal/board/ArduinoTool.java | 3 +- .../build/ArduinoBuildConfiguration.java | 75 ++++++++++++------- .../templates/board.mk | 2 +- 4 files changed, 68 insertions(+), 28 deletions(-) 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 5d6939112ac..bd5c409dfd7 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 @@ -12,6 +12,8 @@ import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.net.URL; +import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; 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; } 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 38c93711aa6..f9e453504e0 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 @@ -13,6 +13,7 @@ import java.util.Properties; import org.eclipse.cdt.arduino.core.internal.Activator; 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.IStatus; import org.eclipse.core.runtime.Status; @@ -74,7 +75,7 @@ public class ArduinoTool { public Properties getToolProperties() { 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; } 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 68349ae4b6e..bda0b06460f 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 @@ -52,6 +52,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdapterFactory; 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.preferences.IEclipsePreferences; import org.osgi.service.prefs.BackingStoreException; @@ -71,6 +72,8 @@ public class ArduinoBuildConfiguration { private IScannerInfo cScannerInfo; private IScannerInfo cppScannerInfo; + private final static boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32); + private ArduinoBuildConfiguration(IBuildConfiguration config) { this.config = config; } @@ -245,7 +248,7 @@ public class ArduinoBuildConfiguration { if (proxy.getType() == IResource.FILE) { if (CoreModel.isValidSourceUnitName(project, proxy.getName())) { Path sourcePath = new File(proxy.requestResource().getLocationURI()).toPath(); - sourceFiles.add(projectPath.relativize(sourcePath).toString()); + sourceFiles.add(pathString(projectPath.relativize(sourcePath))); } } return true; @@ -258,11 +261,11 @@ public class ArduinoBuildConfiguration { List librarySources = new ArrayList<>(); for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(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_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 Properties properties = new Properties(); @@ -277,17 +280,17 @@ public class ArduinoBuildConfiguration { } else { includes += " -I"; //$NON-NLS-1$ } - includes += '"' + include.toString() + '"'; + includes += '"' + pathString(include) + '"'; } for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) { 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$ 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$ File[] platformFiles = corePath.toFile().listFiles(new FilenameFilter() { @@ -298,10 +301,8 @@ public class ArduinoBuildConfiguration { }); String[] platformSource = new String[platformFiles.length]; - for (int i = 0; i < platformSource.length; ++i) - - { - platformSource[i] = platformFiles[i].getAbsolutePath(); + for (int i = 0; i < platformSource.length; ++i) { + platformSource[i] = pathString(platformFiles[i].toPath()); } buildModel.put("platform_srcs", platformSource); //$NON-NLS-1$ @@ -351,7 +352,7 @@ public class ArduinoBuildConfiguration { public void setEnvironment(Map env) throws CoreException { // 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 String pathKey = null; @@ -364,7 +365,11 @@ public class ArduinoBuildConfiguration { } } - List toolPaths = new ArrayList<>(); + List 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(); ArduinoPlatform platform = board.getPlatform(); for (ToolDependency dep : platform.getToolsDependencies()) { @@ -372,17 +377,17 @@ public class ArduinoBuildConfiguration { Path installPath = tool.getInstallPath(); Path binPath = installPath.resolve("bin"); //$NON-NLS-1$ if (binPath.toFile().exists()) { - toolPaths.add(binPath.toString()); + toolPaths.add(binPath); } else { // use the install dir by default - toolPaths.add(installPath.toString()); + toolPaths.add(installPath); } } - for (String toolPath : toolPaths) { + for (Path toolPath : toolPaths) { if (path != null) { - path = toolPath + File.pathSeparatorChar + path; + path = pathString(toolPath) + File.pathSeparatorChar + path; } else { - path = toolPath; + path = pathString(toolPath); } } if (pathKey == null) { @@ -428,7 +433,7 @@ public class ArduinoBuildConfiguration { ArduinoTool tool = board.getPlatform().getTool(toolName); 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$ // 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$ @@ -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$ String command = resolveProperty("tools." + toolName + ".upload.pattern", properties); //$NON-NLS-1$ //$NON-NLS-2$ - // TODO Windows - return new String[] { "sh", "-c", command }; //$NON-NLS-1$ //$NON-NLS-2$ + if (isWindows) { + return splitCommand(command); + } else { + return new String[] { "sh", "-c", command }; //$NON-NLS-1$ //$NON-NLS-2$ + } } public IScannerInfo getScannerInfo(IResource resource) throws CoreException { @@ -464,6 +472,14 @@ public class ArduinoBuildConfiguration { 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 { try { ArduinoPlatform platform = getBoard().getPlatform(); @@ -471,23 +487,27 @@ public class ArduinoBuildConfiguration { properties.putAll(getProperties()); 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$ String includes = "-E -P -v -dD"; //$NON-NLS-1$ for (Path include : platform.getIncludePath()) { - includes += " -I\"" + include.toString() + '"'; //$NON-NLS-1$ + includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$ } Collection libs = ArduinoManager.instance.getLibraries(config.getProject()); for (ArduinoLibrary lib : libs) { 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$ - // TODO Windows - String[] command = new String[] { "sh", "-c", resolveProperty(recipe, properties) }; //$NON-NLS-1$ //$NON-NLS-2$ + String[] command; + 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()) .redirectErrorStream(true); 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() { // ../src/Test.cpp:4:1: error: 'x' was not declared in this scope diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/board.mk b/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/board.mk index 8e9e03d55a9..9eca0cce8e2 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/board.mk +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/board.mk @@ -1,6 +1,6 @@ ifeq ($(OS),Windows_NT) RMDIR = rmdir /s /q -mymkdir = if not exist "$(call fixpath,$1)" mkdir $(call fixpath,$1) +mymkdir = if not exist "$1" mkdir "$1" else RMDIR = rm -fr mymkdir = mkdir -p $1