Skip to content

Commit

Permalink
Implement Command-line option for displaying targets (#5032)
Browse files Browse the repository at this point in the history
Closes #33.
  • Loading branch information
szaliszali authored Feb 18, 2020
1 parent acd843e commit d7af217
Show file tree
Hide file tree
Showing 18 changed files with 548 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,47 @@ public void PreprocessSwitchIdentificationTests(string preprocess)
unquoteParameters.ShouldBeTrue();
}

[Theory]
[InlineData("targets")]
[InlineData("tArGeTs")]
[InlineData("ts")]
public void TargetsSwitchIdentificationTests(string @switch)
{
CommandLineSwitches.IsParameterizedSwitch(
@switch,
out var parameterizedSwitch,
out var duplicateSwitchErrorMessage,
out var multipleParametersAllowed,
out var missingParametersErrorMessage,
out var unquoteParameters,
out var emptyParametersAllowed).ShouldBeTrue();
parameterizedSwitch.ShouldBe(CommandLineSwitches.ParameterizedSwitch.Targets);
duplicateSwitchErrorMessage.ShouldBeNull();
multipleParametersAllowed.ShouldBeFalse();
missingParametersErrorMessage.ShouldBeNull();
unquoteParameters.ShouldBeTrue();
emptyParametersAllowed.ShouldBeFalse();
}

[Fact]
public void TargetsSwitchParameter()
{
CommandLineSwitches switches = new CommandLineSwitches();
MSBuildApp.GatherCommandLineSwitches(new ArrayList() { "/targets:targets.txt" }, switches);

switches.HaveErrors().ShouldBeFalse();
switches[CommandLineSwitches.ParameterizedSwitch.Targets].ShouldBe(new[] { "targets.txt" });
}

[Fact]
public void TargetsSwitchDoesNotSupportMultipleOccurrences()
{
CommandLineSwitches switches = new CommandLineSwitches();
MSBuildApp.GatherCommandLineSwitches(new ArrayList() { "/targets /targets" }, switches);

switches.HaveErrors().ShouldBeTrue();
}

[Theory]
[InlineData("isolate")]
[InlineData("ISOLATE")]
Expand Down Expand Up @@ -894,6 +935,7 @@ public void InvalidToolsVersionErrors()
1,
true,
new StringWriter(),
new StringWriter(),
false,
warningsAsErrors: null,
warningsAsMessages: null,
Expand Down
2 changes: 2 additions & 0 deletions src/MSBuild/CommandLineSwitches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ internal enum ParameterizedSwitch
FileLoggerParameters9,
NodeReuse,
Preprocess,
Targets,
WarningsAsErrors,
WarningsAsMessages,
BinaryLogger,
Expand Down Expand Up @@ -261,6 +262,7 @@ bool emptyParametersAllowed
new ParameterizedSwitchInfo( new string[] { "fileloggerparameters9", "flp9" }, ParameterizedSwitch.FileLoggerParameters9, null, false, "MissingFileLoggerParameterError", true, false ),
new ParameterizedSwitchInfo( new string[] { "nodereuse", "nr" }, ParameterizedSwitch.NodeReuse, null, false, "MissingNodeReuseParameterError", true, false ),
new ParameterizedSwitchInfo( new string[] { "preprocess", "pp" }, ParameterizedSwitch.Preprocess, null, false, null, true, false ),
new ParameterizedSwitchInfo( new string[] { "targets", "ts" }, ParameterizedSwitch.Targets, null, false, null, true, false ),
new ParameterizedSwitchInfo( new string[] { "warnaserror", "err" }, ParameterizedSwitch.WarningsAsErrors, null, true, null, true, true ),
new ParameterizedSwitchInfo( new string[] { "warnasmessage", "nowarn" }, ParameterizedSwitch.WarningsAsMessages, null, true, "MissingWarnAsMessageParameterError", true, false ),
new ParameterizedSwitchInfo( new string[] { "binarylogger", "bl" }, ParameterizedSwitch.BinaryLogger, null, false, null, true, false ),
Expand Down
22 changes: 21 additions & 1 deletion src/MSBuild/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,22 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<data name="HelpMessage_37_DocsLink" Visibility="Public">
<value>For more detailed information, see https://aka.ms/msbuild/docs</value>
</data>
<data name="HelpMessage_38_TargetsSwitch" Visibility="Public">
<value> -targets[:file]
Prints a list of available targets without executing the
actual build process. By default the output is written to
the console window. If the path to an output file
is provided that will be used instead.
(Short form: -ts)
Example:
-ts:out.txt
</value>
<comment>
LOCALIZATION: "MSBuild" should not be localized.
LOCALIZATION: "-targets" and "-ts" should not be localized.
LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars.
</comment>
</data>
<data name="InvalidConfigurationFile" Visibility="Public">
<value>MSBUILD : Configuration error MSB1043: The application could not start. {0}</value>
<comment>
Expand Down Expand Up @@ -1157,6 +1173,10 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<value>MSBUILD : error MSB1047: File to preprocess to is not valid. {0}</value>
<comment>{StrBegin="MSBUILD : error MSB1047: "}</comment>
</data>
<data name="TargetsCouldNotBePrinted">
<value>MSBUILD : error MSB1059: Targets could not be printed. {0}</value>
<comment>{StrBegin="MSBUILD : error MSB1059: "}</comment>
</data>
<!-- MSB1021 and MSB1020 are also used in the engine but their copies do not have the "MSBUILD : " prefix so we must have our own -->
<data name="LoggerCreationError" UESanitized="true" Visibility="Public">
<value>MSBUILD : error MSB1021: Cannot create an instance of the logger. {0}</value>
Expand Down Expand Up @@ -1232,7 +1252,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<!--
The command line message bucket is: MSB1001 - MSB1999
Next error code should be MSB1059.
Next error code should be MSB1060.
Don't forget to update this comment after using the new code.
-->
Expand Down
30 changes: 30 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.en.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d7af217

Please sign in to comment.