Skip to content

Commit 0707e77

Browse files
authored
[msbuild] Fix parsing bundler verbosity. (#23845)
This will avoid setting the _BundlerVerbosity property if the AppBundleExtraOptions property doesn't specify any verbosity options.
1 parent 8218a1e commit 0707e77

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

msbuild/Xamarin.MacDev.Tasks/Tasks/ParseBundlerArguments.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class ParseBundlerArguments : XamarinTask {
6464
public string? SkipMarkingNSObjectsInUserAssemblies { get; set; }
6565

6666
[Output]
67-
public int Verbosity { get; set; }
67+
public string? Verbosity { get; set; }
6868

6969
[Output]
7070
public string? Warn { get; set; }
@@ -102,6 +102,7 @@ public override bool Execute ()
102102
var aot = new List<ITaskItem> ();
103103
var envVariables = new List<ITaskItem> ();
104104
var dlsyms = new List<ITaskItem> ();
105+
int? verbosity = null;
105106

106107
for (int i = 0; i < args.Length; i++) {
107108
var arg = args [i];
@@ -153,11 +154,15 @@ public override bool Execute ()
153154
break;
154155
case "verbose":
155156
case "v":
156-
Verbosity++;
157+
if (!verbosity.HasValue)
158+
verbosity = 0;
159+
verbosity++;
157160
break;
158161
case "quiet":
159162
case "q":
160-
Verbosity--;
163+
if (!verbosity.HasValue)
164+
verbosity = 0;
165+
verbosity--;
161166
break;
162167
case "marshal-managed-exceptions":
163168
value = hasValue ? value : nextValue; // requires a value, which might be the next option
@@ -249,10 +254,14 @@ public override bool Execute ()
249254
if (value.Length == 0 && name.Length > 1 && name.All (ch => ch == name [0])) {
250255
switch (name [0]) {
251256
case 'v':
252-
Verbosity += name.Length;
257+
if (!verbosity.HasValue)
258+
verbosity = 0;
259+
verbosity += name.Length;
253260
continue;
254261
case 'q':
255-
Verbosity -= name.Length;
262+
if (!verbosity.HasValue)
263+
verbosity = 0;
264+
verbosity -= name.Length;
256265
continue;
257266
}
258267
}
@@ -296,6 +305,9 @@ public override bool Execute ()
296305
aot.AddRange (Aot);
297306
Aot = aot.ToArray ();
298307
}
308+
309+
if (verbosity.HasValue)
310+
Verbosity = verbosity.Value.ToString ();
299311
}
300312

301313
return !Log.HasLoggedErrors;

tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ParseBundlerArgumentsTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,18 @@ public void CustomLinkFlags (string input, string [] output)
239239
CollectionAssert.AreEquivalent (output, task.CustomLinkFlags.Select (v => v.ItemSpec).ToArray (), string.Join (" ", output));
240240
}
241241

242-
[TestCase ("-v", 1)]
243-
[TestCase ("/v", 1)]
244-
[TestCase ("/q", -1)]
245-
[TestCase ("-vvvv", 4)]
246-
[TestCase ("-qqq", -3)]
247-
public void Verbosity (string input, int output)
242+
[TestCase ("-v", "1")]
243+
[TestCase ("/v", "1")]
244+
[TestCase ("/q", "-1")]
245+
[TestCase ("-vvvv", "4")]
246+
[TestCase ("-qqq", "-3")]
247+
[TestCase ("", null)]
248+
public void Verbosity (string input, string output)
248249
{
249250
var task = CreateTask<CustomParseBundlerArguments> ();
250251
task.ExtraArgs = input;
251252
Assert.IsTrue (task.Execute (), input);
252-
Assert.AreEqual (output, task.Verbosity, output.ToString ());
253+
Assert.AreEqual (output, task.Verbosity, "Equality");
253254
}
254255

255256
[TestCase ("--nowarn", "-1")]

0 commit comments

Comments
 (0)