Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Command-line option for displaying targets #5032

Merged
merged 33 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7ee3d7a
-targets switch (based on preprocess)
szaliszali Jan 5, 2020
ebea32f
split else to two ifs
szaliszali Jan 5, 2020
587b84d
targets switch WIP (calls preprocess for now)
szaliszali Jan 6, 2020
3797c64
print targets
szaliszali Jan 6, 2020
d383686
update autogenerated localization files
szaliszali Jan 6, 2020
825069e
help for -targets
szaliszali Jan 6, 2020
fb44187
update autogenerated localization files
szaliszali Jan 6, 2020
2c9ec9e
fix PR comment: error message and number
szaliszali Jan 9, 2020
5f2bace
update autogenerated localization files
szaliszali Jan 9, 2020
ea11ce4
convert duplicated test code to parametrized test
szaliszali Jan 9, 2020
18241d5
wrap parameters
szaliszali Jan 9, 2020
e897624
fix PR comment: inline out vars
szaliszali Jan 9, 2020
85b4fe8
fix PR comment: use Shouldly
szaliszali Jan 9, 2020
4ce6130
also assert emptyParametersAllowed
szaliszali Jan 9, 2020
a7d46bc
fix PR comment: add test for failure and filename
szaliszali Jan 9, 2020
75049d6
Revert "fix PR comment: add test for failure and filename"
szaliszali Feb 2, 2020
f9d33f5
Revert "also assert emptyParametersAllowed"
szaliszali Feb 2, 2020
123897a
Revert "fix PR comment: use Shouldly"
szaliszali Feb 2, 2020
c435a1e
Revert "fix PR comment: inline out vars"
szaliszali Feb 2, 2020
1278bcb
Revert "wrap parameters"
szaliszali Feb 2, 2020
2846f5e
Revert "convert duplicated test code to parametrized test"
szaliszali Feb 2, 2020
756840f
revert test code from commit "-targets switch (based on preprocess)"
szaliszali Feb 2, 2020
e3399be
Merge remote-tracking branch 'origin/master' into 33-targets-command-…
szaliszali Feb 2, 2020
610a4f1
readd reverted targets switch tests
szaliszali Feb 2, 2020
9feb411
replace call to project.PrintTargets with a copy
szaliszali Feb 2, 2020
435ace8
remove PrintTargets from Project
szaliszali Feb 2, 2020
3a8c585
rename resource key to match message
szaliszali Feb 2, 2020
31c5b18
update autogenerated localization files
szaliszali Feb 2, 2020
26742e9
add error handling for print targets
szaliszali Feb 2, 2020
9fec2f6
extract method PrintTargets
szaliszali Feb 2, 2020
3c45f7b
Merge remote-tracking branch 'origin/master' into 33-targets-command-…
szaliszali Feb 12, 2020
a5f3a02
preserve stack trace for easier debug
szaliszali Feb 12, 2020
af52500
write targets in a loop
szaliszali Feb 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ref/Microsoft.Build/net/Microsoft.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ public Project(System.Xml.XmlReader xmlReader, System.Collections.Generic.IDicti
public string GetPropertyValue(string name) { throw null; }
public static string GetPropertyValueEscaped(Microsoft.Build.Evaluation.ProjectProperty property) { throw null; }
public void MarkDirty() { }
public void PrintTargets(System.IO.TextWriter writer) { }
public void ReevaluateIfNecessary() { }
public void ReevaluateIfNecessary(Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) { }
public bool RemoveGlobalProperty(string name) { throw null; }
Expand Down
1 change: 1 addition & 0 deletions ref/Microsoft.Build/netstandard/Microsoft.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ public Project(System.Xml.XmlReader xmlReader, System.Collections.Generic.IDicti
public string GetPropertyValue(string name) { throw null; }
public static string GetPropertyValueEscaped(Microsoft.Build.Evaluation.ProjectProperty property) { throw null; }
public void MarkDirty() { }
public void PrintTargets(System.IO.TextWriter writer) { }
public void ReevaluateIfNecessary() { }
public void ReevaluateIfNecessary(Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) { }
public bool RemoveGlobalProperty(string name) { throw null; }
Expand Down
5 changes: 5 additions & 0 deletions src/Build/Definition/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,11 @@ public void SaveLogicalProject(TextWriter writer)
implementation.SaveLogicalProject(writer);
}

public void PrintTargets(TextWriter writer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have the Project API only return targets, and not deal with the extra problem domain of printing object model things to streams.

{
writer.WriteLine(string.Join(Environment.NewLine, Targets.Keys));
}

/// <summary>
/// Starts a build using this project, building the default targets.
/// Returns true on success, false on failure.
Expand Down
26 changes: 26 additions & 0 deletions src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,31 @@ public void PreprocessSwitchIdentificationTests()
Assert.True(unquoteParameters);
}

[Fact]
Forgind marked this conversation as resolved.
Show resolved Hide resolved
public void TargetsSwitchIdentificationTests()
{
CommandLineSwitches.ParameterizedSwitch parameterizedSwitch;
string duplicateSwitchErrorMessage;
Forgind marked this conversation as resolved.
Show resolved Hide resolved
bool multipleParametersAllowed;
string missingParametersErrorMessage;
bool unquoteParameters;
bool emptyParametersAllowed;

Assert.True(CommandLineSwitches.IsParameterizedSwitch("targets", out parameterizedSwitch, out duplicateSwitchErrorMessage, out multipleParametersAllowed, out missingParametersErrorMessage, out unquoteParameters, out emptyParametersAllowed));
Forgind marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal(CommandLineSwitches.ParameterizedSwitch.Targets, parameterizedSwitch);
Assert.Null(duplicateSwitchErrorMessage);
Assert.False(multipleParametersAllowed);
Assert.Null(missingParametersErrorMessage);
Assert.True(unquoteParameters);

Assert.True(CommandLineSwitches.IsParameterizedSwitch("ts", out parameterizedSwitch, out duplicateSwitchErrorMessage, out multipleParametersAllowed, out missingParametersErrorMessage, out unquoteParameters, out emptyParametersAllowed));
Assert.Equal(CommandLineSwitches.ParameterizedSwitch.Targets, parameterizedSwitch);
Assert.Null(duplicateSwitchErrorMessage);
Assert.False(multipleParametersAllowed);
Assert.Null(missingParametersErrorMessage);
Assert.True(unquoteParameters);
}

[Fact]
public void IsolateProjectsSwitchIdentificationTests()
{
Expand Down Expand Up @@ -1243,6 +1268,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
20 changes: 20 additions & 0 deletions src/MSBuild/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,22 @@ Copyright (C) Microsoft Corporation. All rights reserved.
LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars.
</comment>
</data>
<data name="HelpMessage_37_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 @@ -1154,6 +1170,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="InvalidTargetsPath">
<value>MSBUILD : error MSB1047: File to print targets to is not valid. {0}</value>
Forgind marked this conversation as resolved.
Show resolved Hide resolved
<comment>{StrBegin="MSBUILD : error MSB1047: "}</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
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