mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-03 23:25:26 +02:00
Bug 531071 - CBuildConfiguration doesn't handle quoted arguments
- fix CBuildConfiguration processLine() to call new stripArgs() method to parse the command arguments into separate argument strings and recognize quotes Change-Id: Ifd0e1c1204b1b5d04498fdee202253f26283a2f5
This commit is contained in:
parent
651a5af560
commit
03e190164e
1 changed files with 59 additions and 4 deletions
|
@ -23,12 +23,13 @@ import java.nio.file.InvalidPathException;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
|
@ -747,12 +748,65 @@ public abstract class CBuildConfiguration extends PlatformObject
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string containing compile options into individual argument strings.
|
||||
*
|
||||
* @param argString - String to parse
|
||||
* @return List of arg Strings
|
||||
*/
|
||||
private List<String> stripArgs(String argString) {
|
||||
Pattern p0 = Pattern.compile("('(.*?)').*"); //$NON-NLS-1$
|
||||
Pattern p1 = Pattern.compile("([\\-](\\w|[\\-])+[=]\\\".*?\\\").*"); //$NON-NLS-1$
|
||||
Pattern p2 = Pattern.compile("([\\-](\\w|[\\-])+[=]'.*?').*"); //$NON-NLS-1$
|
||||
Pattern p3 = Pattern.compile("([\\-](\\w|[\\-])+[=][^\\s]+).*"); //$NON-NLS-1$
|
||||
Pattern p4 = Pattern.compile("([^\\s]+).*"); //$NON-NLS-1$
|
||||
boolean finished = false;
|
||||
List<String> args = new ArrayList<>();
|
||||
while (!finished) {
|
||||
Matcher m0 = p0.matcher(argString);
|
||||
if (m0.matches()) {
|
||||
argString = argString.replaceFirst("'.*?'", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String s = m0.group(2).trim(); // strip single quotes
|
||||
args.add(s);
|
||||
} else {
|
||||
Matcher m1 = p1.matcher(argString);
|
||||
if (m1.matches()) {
|
||||
argString = argString.replaceFirst("[\\-](\\w|[\\-])+[=]\\\".*?\\\"","").trim(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String s = m1.group(1).trim();
|
||||
args.add(s);
|
||||
} else {
|
||||
Matcher m2 = p2.matcher(argString);
|
||||
if (m2.matches()) {
|
||||
argString = argString.replaceFirst("[\\-](\\w|[\\-])+[=]'.*?'", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String s = m2.group(1).trim();
|
||||
args.add(s);
|
||||
} else {
|
||||
Matcher m3 = p3.matcher(argString);
|
||||
if (m3.matches()) {
|
||||
argString = argString.replaceFirst("[\\-](\\w|[\\-])+[=][^\\s]+", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
args.add(m3.group(1).trim());
|
||||
} else {
|
||||
Matcher m4 = p4.matcher(argString);
|
||||
if (m4.matches()) {
|
||||
argString = argString.replaceFirst("[^\\s]+", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
args.add(m4.group(1).trim());
|
||||
} else {
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
private boolean infoChanged = false;
|
||||
|
||||
@Override
|
||||
public boolean processLine(String line) {
|
||||
// TODO smarter line parsing to deal with quoted arguments
|
||||
List<String> command = Arrays.asList(line.split("\\s+")); //$NON-NLS-1$
|
||||
// Split line into args, taking into account quotes
|
||||
List<String> command = stripArgs(line);
|
||||
|
||||
// Make sure it's a compile command
|
||||
String[] compileCommands = toolChain.getCompileCommands();
|
||||
|
@ -773,6 +827,7 @@ public abstract class CBuildConfiguration extends PlatformObject
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (Platform.getOS().equals(Platform.OS_WIN32) && !arg.endsWith(".exe")) { //$NON-NLS-1$
|
||||
// Try with exe
|
||||
arg = arg + ".exe"; //$NON-NLS-1$
|
||||
|
|
Loading…
Add table
Reference in a new issue