From d04bdf684f8cb37dd0faddbe098fb11a28d6ed5f Mon Sep 17 00:00:00 2001 From: Adrian Stanciu Date: Sat, 9 Oct 2021 17:53:08 +0300 Subject: [PATCH 1/6] Update XMake.cs --- src/MSBuild/XMake.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index b3cf4561a15..c4408477cfa 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -1704,8 +1704,8 @@ internal static void GatherCommandLineSwitches(List commandLineArgs, Com } else { - switchName = unquotedCommandLineArg.Substring(switchIndicatorsLength, switchParameterIndicator - 1); - switchParameters = ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, switchName, switchParameterIndicator); + switchName = unquotedCommandLineArg.Substring(switchIndicatorsLength, switchParameterIndicator - switchIndicatorsLength); + switchParameters = ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, switchName, switchParameterIndicator, switchIndicatorsLength); } } @@ -1764,6 +1764,7 @@ internal static void GatherCommandLineSwitches(List commandLineArgs, Com /// /// /// + /// /// The given switch's parameters (with interesting quoting preserved). internal static string ExtractSwitchParameters ( @@ -1771,7 +1772,8 @@ internal static string ExtractSwitchParameters string unquotedCommandLineArg, int doubleQuotesRemovedFromArg, string switchName, - int switchParameterIndicator + int switchParameterIndicator, + int switchIndicatorsLength ) { @@ -1783,7 +1785,7 @@ int switchParameterIndicator // check if there is any quoting in the name portion of the switch string unquotedSwitchIndicatorAndName = QuotingUtilities.Unquote(commandLineArg.Substring(0, quotedSwitchParameterIndicator), out var doubleQuotesRemovedFromSwitchIndicatorAndName); - ErrorUtilities.VerifyThrow(switchName == unquotedSwitchIndicatorAndName.Substring(1), + ErrorUtilities.VerifyThrow(switchName == unquotedSwitchIndicatorAndName.Substring(switchIndicatorsLength), "The switch name extracted from either the partially or completely unquoted arg should be the same."); ErrorUtilities.VerifyThrow(doubleQuotesRemovedFromArg >= doubleQuotesRemovedFromSwitchIndicatorAndName, From a14404d0f81e7389838c28995532dfe8db2f2ed9 Mon Sep 17 00:00:00 2001 From: Adrian Stanciu Date: Sat, 9 Oct 2021 18:24:02 +0300 Subject: [PATCH 2/6] Update XMake_Tests.cs --- src/MSBuild.UnitTests/XMake_Tests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index c9dbd905e72..8b5eb50ae78 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -392,44 +392,44 @@ public void ExtractSwitchParametersTest() { string commandLineArg = "\"/p:foo=\"bar"; string unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out var doubleQuotesRemovedFromArg); - MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':')).ShouldBe(":\"foo=\"bar"); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 1).ShouldBe(":\"foo=\"bar"); doubleQuotesRemovedFromArg.ShouldBe(2); commandLineArg = "\"/p:foo=bar\""; unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); - MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':')).ShouldBe(":foo=bar"); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 1).ShouldBe(":foo=bar"); doubleQuotesRemovedFromArg.ShouldBe(2); commandLineArg = "/p:foo=bar"; unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); - MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':')).ShouldBe(":foo=bar"); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 1).ShouldBe(":foo=bar"); doubleQuotesRemovedFromArg.ShouldBe(0); commandLineArg = "\"\"/p:foo=bar\""; unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); - MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':')).ShouldBe(":foo=bar\""); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 1).ShouldBe(":foo=bar\""); doubleQuotesRemovedFromArg.ShouldBe(3); // this test is totally unreal -- we'd never attempt to extract switch parameters if the leading character is not a // switch indicator (either '-' or '/') -- here the leading character is a double-quote commandLineArg = "\"\"\"/p:foo=bar\""; unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); - MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "/p", unquotedCommandLineArg.IndexOf(':')).ShouldBe(":foo=bar\""); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "/p", unquotedCommandLineArg.IndexOf(':'), 1).ShouldBe(":foo=bar\""); doubleQuotesRemovedFromArg.ShouldBe(3); commandLineArg = "\"/pr\"operty\":foo=bar"; unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); - MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "property", unquotedCommandLineArg.IndexOf(':')).ShouldBe(":foo=bar"); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "property", unquotedCommandLineArg.IndexOf(':'), 1).ShouldBe(":foo=bar"); doubleQuotesRemovedFromArg.ShouldBe(3); commandLineArg = "\"/pr\"op\"\"erty\":foo=bar\""; unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); - MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "property", unquotedCommandLineArg.IndexOf(':')).ShouldBe(":foo=bar"); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "property", unquotedCommandLineArg.IndexOf(':'), 1).ShouldBe(":foo=bar"); doubleQuotesRemovedFromArg.ShouldBe(6); commandLineArg = "/p:\"foo foo\"=\"bar bar\";\"baz=onga\""; unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); - MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':')).ShouldBe(":\"foo foo\"=\"bar bar\";\"baz=onga\""); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 1).ShouldBe(":\"foo foo\"=\"bar bar\";\"baz=onga\""); doubleQuotesRemovedFromArg.ShouldBe(6); } From 085b2a9d19f907aad62b92ebdda3398741d91b9d Mon Sep 17 00:00:00 2001 From: Adrian Stanciu Date: Tue, 12 Oct 2021 00:48:23 +0300 Subject: [PATCH 3/6] added ExtractSwitchParameters unit tests --- src/MSBuild.UnitTests/XMake_Tests.cs | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index 8b5eb50ae78..e85600e5d30 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -432,6 +432,45 @@ public void ExtractSwitchParametersTest() MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 1).ShouldBe(":\"foo foo\"=\"bar bar\";\"baz=onga\""); doubleQuotesRemovedFromArg.ShouldBe(6); } + + [Fact] + public void ExtractSwitchParametersTestDoubleDash() + { + var commandLineArg = "\"--p:foo=\"bar"; + var unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out var doubleQuotesRemovedFromArg); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 2).ShouldBe(":\"foo=\"bar"); + doubleQuotesRemovedFromArg.ShouldBe(2); + + commandLineArg = "\"--p:foo=bar\""; + unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 2).ShouldBe(":foo=bar"); + doubleQuotesRemovedFromArg.ShouldBe(2); + + commandLineArg = "--p:foo=bar"; + unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 2).ShouldBe(":foo=bar"); + doubleQuotesRemovedFromArg.ShouldBe(0); + + commandLineArg = "\"\"--p:foo=bar\""; + unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 2).ShouldBe(":foo=bar\""); + doubleQuotesRemovedFromArg.ShouldBe(3); + + commandLineArg = "\"--pr\"operty\":foo=bar"; + unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "property", unquotedCommandLineArg.IndexOf(':'), 2).ShouldBe(":foo=bar"); + doubleQuotesRemovedFromArg.ShouldBe(3); + + commandLineArg = "\"--pr\"op\"\"erty\":foo=bar\""; + unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "property", unquotedCommandLineArg.IndexOf(':'), 2).ShouldBe(":foo=bar"); + doubleQuotesRemovedFromArg.ShouldBe(6); + + commandLineArg = "--p:\"foo foo\"=\"bar bar\";\"baz=onga\""; + unquotedCommandLineArg = QuotingUtilities.Unquote(commandLineArg, out doubleQuotesRemovedFromArg); + MSBuildApp.ExtractSwitchParameters(commandLineArg, unquotedCommandLineArg, doubleQuotesRemovedFromArg, "p", unquotedCommandLineArg.IndexOf(':'), 2).ShouldBe(":\"foo foo\"=\"bar bar\";\"baz=onga\""); + doubleQuotesRemovedFromArg.ShouldBe(6); + } [Fact] public void GetLengthOfSwitchIndicatorTest() From c08c58a9042e2d90116a918e9181f2893b5ef749 Mon Sep 17 00:00:00 2001 From: Adrian Stanciu Date: Tue, 12 Oct 2021 00:53:25 +0300 Subject: [PATCH 4/6] added GatherCommandLineSwitches tests --- src/MSBuild.UnitTests/XMake_Tests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index e85600e5d30..f6e5cc906fc 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -57,6 +57,23 @@ public void GatherCommandLineSwitchesTwoProperties() parameters[1].ShouldBe("c=d"); } + [Fact] + public void GatherCommandLineSwitchesAnyDash() + { + var switches = new CommandLineSwitches(); + + var arguments = new List { + "-p:c=d", + "--p:a=b" + }; + + MSBuildApp.GatherCommandLineSwitches(arguments, switches); + + string[] parameters = switches[CommandLineSwitches.ParameterizedSwitch.Property]; + parameters[0].ShouldBe("a=b"); + parameters[1].ShouldBe("c=d"); + } + [Fact] public void GatherCommandLineSwitchesMaxCpuCountWithArgument() { From 78db5736f56128da0f465c4ca461cb7ae767c0e9 Mon Sep 17 00:00:00 2001 From: Adrian Stanciu Date: Tue, 12 Oct 2021 01:09:16 +0300 Subject: [PATCH 5/6] Fixed parameter order --- src/MSBuild.UnitTests/XMake_Tests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index f6e5cc906fc..67efa2f6c78 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -63,8 +63,8 @@ public void GatherCommandLineSwitchesAnyDash() var switches = new CommandLineSwitches(); var arguments = new List { - "-p:c=d", - "--p:a=b" + "-p:a=b", + "--p:c=d" }; MSBuildApp.GatherCommandLineSwitches(arguments, switches); From f33fb8e7e35da50f921537e25df2cd06142d46ea Mon Sep 17 00:00:00 2001 From: Adrian Stanciu Date: Fri, 15 Oct 2021 19:56:47 +0300 Subject: [PATCH 6/6] --maxcpucount unit test --- src/MSBuild.UnitTests/XMake_Tests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index 67efa2f6c78..c6909ccceb1 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -64,14 +64,14 @@ public void GatherCommandLineSwitchesAnyDash() var arguments = new List { "-p:a=b", - "--p:c=d" + "--p:maxcpucount=8" }; MSBuildApp.GatherCommandLineSwitches(arguments, switches); string[] parameters = switches[CommandLineSwitches.ParameterizedSwitch.Property]; parameters[0].ShouldBe("a=b"); - parameters[1].ShouldBe("c=d"); + parameters[1].ShouldBe("maxcpucount=8"); } [Fact]