1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

Bug 498171 Propagate scanner info fix for Arduino.

Change-Id: I3ed23049f0364d8fe989f1fa0d8a9b7b47378f32
This commit is contained in:
Doug Schaefer 2017-05-16 20:57:17 -04:00
parent 4b2e1e5b41
commit 43e62924a1
2 changed files with 48 additions and 9 deletions

View file

@ -204,7 +204,7 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
// TODO optimize by dealing with multi arg options like -o // TODO optimize by dealing with multi arg options like -o
Path filePath = buildDirectory.resolve(commandLine.get(i)); Path filePath = buildDirectory.resolve(commandLine.get(i));
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(filePath.toUri()); IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(filePath.toUri());
if (files.length > 0) { if (files.length > 0 && files[0].exists()) {
// replace it with a temp file // replace it with a temp file
Path parentPath = filePath.getParent(); Path parentPath = filePath.getParent();
String extension = files[0].getFileExtension(); String extension = files[0].getFileExtension();

View file

@ -18,7 +18,6 @@ import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -129,6 +128,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration
return super.getAdapter(adapter); return super.getAdapter(adapter);
} }
@Override
public String getLaunchMode() { public String getLaunchMode() {
return launchMode; return launchMode;
} }
@ -556,7 +556,8 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration
throw Activator.coreException("Upload command not specified", null); throw Activator.coreException("Upload command not specified", null);
} }
if (isWindows) { if (isWindows) {
return splitCommand(command); List<String> args = splitCommand(command);
return args.toArray(new String[args.size()]);
} else { } else {
return new String[] { "sh", "-c", command }; //$NON-NLS-1$ //$NON-NLS-2$ return new String[] { "sh", "-c", command }; //$NON-NLS-1$ //$NON-NLS-2$
} }
@ -659,9 +660,9 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration
} }
ExtendedScannerInfo baseInfo = new ExtendedScannerInfo(null, includes); ExtendedScannerInfo baseInfo = new ExtendedScannerInfo(null, includes);
String[] command = splitCommand(commandString); List<String> command = splitCommand(commandString);
IScannerInfo info = getToolChain().getScannerInfo(getBuildConfiguration(), Paths.get(command[0]), IScannerInfo info = getToolChain().getScannerInfo(getBuildConfiguration(), command,
Arrays.copyOfRange(command, 1, command.length), baseInfo, resource, getBuildDirectoryURI()); baseInfo, resource, getBuildDirectoryURI());
// cache the results // cache the results
cachedScannerInfo = info; cachedScannerInfo = info;
@ -683,9 +684,47 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration
return str; return str;
} }
private String[] splitCommand(String command) { private List<String> splitCommand(String command) {
// TODO deal with quotes properly, for now just strip boolean inQuotes = false;
return command.replaceAll("\"", "").split("\\s+"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ boolean inDouble = false;
List<String> args = new ArrayList<>();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < command.length(); i++) {
char c = command.charAt(i);
switch (c) {
case ' ':
if (inQuotes || inDouble) {
builder.append(c);
} else if (builder.length() > 0) {
args.add(builder.toString());
builder = new StringBuilder();
}
break;
case '\'':
if (inDouble) {
builder.append(c);
} else {
inQuotes = !inQuotes;
}
break;
case '"':
if (inQuotes) {
builder.append(c);
} else {
inDouble = !inDouble;
}
break;
default:
builder.append(c);
}
}
if (builder.length() > 0) {
args.add(builder.toString());
}
return args;
} }
@Override @Override