aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Costa <miguel.costa@qt.io>2017-12-11 16:28:29 +0100
committerMiguel Costa <miguel.costa@qt.io>2017-12-12 14:36:42 +0000
commitb182e1e8dd3f00bd00927897ea0b32e65e08b662 (patch)
treeb034fa4b7fa60b4bf7a0c55480f447ce3a1f97d9
parent34f18d8347177d4233056999de0b007043f87ff2 (diff)
Convert custom build command strings with multiple lines2.1
When converting custom build steps to Qt/MSBuild target items, the conversion procedure will now be able to handle command strings with multiple lines. In these cases, only the sub-string with the relevant command will be considered. Custom build steps with multiple lines are potentially problematic, e.g. if empty lines are present in the command string (see associated issue for example of this problem). Task-number: QTVSADDINBUG-414 Change-Id: I93ae2f233ee35d27462b9087ada58b1134102e87 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r--src/qtprojectlib/CommandLineParser.cs27
-rw-r--r--src/qtprojectlib/QtMsBuild.cs2
2 files changed, 22 insertions, 7 deletions
diff --git a/src/qtprojectlib/CommandLineParser.cs b/src/qtprojectlib/CommandLineParser.cs
index f6f435d4..7c74e9a2 100644
--- a/src/qtprojectlib/CommandLineParser.cs
+++ b/src/qtprojectlib/CommandLineParser.cs
@@ -234,12 +234,26 @@ namespace QtProjectLib.CommandLine
Trace.TraceWarning("CommandLineParser: Parse() before {0}", method);
}
- public bool Parse(string commandLine)
+ public bool Parse(string commandLine, string execName)
{
List<string> arguments = new List<string>();
StringBuilder arg = new StringBuilder();
+ bool foundExec = false;
foreach (Match token in Lexer.Tokenize(commandLine)) {
- if (token.TokenType() == Token.Whitespace) {
+ if (!foundExec) {
+ if (!token.TokenText()
+ .EndsWith(execName,
+ StringComparison.InvariantCultureIgnoreCase)) {
+ continue;
+ }
+
+ foundExec = true;
+ }
+
+ var tokenType = token.TokenType();
+ if (tokenType == Token.Newline) {
+ break;
+ } else if (tokenType == Token.Whitespace) {
if (arg.Length > 0) {
arguments.Add(arg.ToString());
arg.Clear();
@@ -506,14 +520,15 @@ namespace QtProjectLib.CommandLine
enum Token
{
Unknown = 0,
- Unquoted = 1,
- Quoted = 2,
- Whitespace = 3
+ Newline = 1,
+ Unquoted = 2,
+ Quoted = 3,
+ Whitespace = 4
};
static class Lexer
{
- static Regex lexer = new Regex(@"([^\s\""]+)|(?:\""([^\""]+)\"")|(\s+)");
+ static Regex lexer = new Regex(@"(\n)|([^\s\""]+)|(?:\""([^\""]+)\"")|(\s+)");
public static Token TokenType(this Match token)
{
diff --git a/src/qtprojectlib/QtMsBuild.cs b/src/qtprojectlib/QtMsBuild.cs
index 08f4bcb4..f85b4562 100644
--- a/src/qtprojectlib/QtMsBuild.cs
+++ b/src/qtprojectlib/QtMsBuild.cs
@@ -488,7 +488,7 @@ namespace QtProjectLib.QtMsBuild
out string outputPath)
{
qtDir = inputPath = outputPath = "";
- if (!parser.Parse(commandLine))
+ if (!parser.Parse(commandLine, toolExecName))
return false;
string execPath = parser.PositionalArguments.Where(