Skip to content

Commit

Permalink
[tools] Fix nullability for the Execution.Environment field. (#15084)
Browse files Browse the repository at this point in the history
The values for environment variables can be null (to remove said environment
variable).

Fixes this warning:

    tests/dotnet/UnitTests/TestBaseClass.cs(294,100): warning CS8620: Argument of type 'Dictionary<string, string?>' cannot be used for parameter 'environment' of type 'Dictionary<string, string>' in 'Task<Execution> Execution.RunWithStringBuildersAsync(string filename, IList<string> arguments, Dictionary<string, string>? environment = null, StringBuilder? standardOutput = null, StringBuilder? standardError = null, TextWriter? log = null, string? workingDirectory = null, TimeSpan? timeout = null, CancellationToken? cancellationToken = null)' due to differences in the nullability of reference types.
  • Loading branch information
rolfbjarne authored May 23, 2022
1 parent 6632f88 commit 02838f2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tools/common/Execution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Xamarin.Utils {
public class Execution {
public string? FileName;
public IList<string>? Arguments;
public IDictionary<string, string>? Environment;
public IDictionary<string, string?>? Environment;
public string? WorkingDirectory;
public TimeSpan? Timeout;
public CancellationToken? CancellationToken;
Expand Down Expand Up @@ -81,7 +81,7 @@ public Task<Execution> RunAsync ()

if (Environment != null) {
foreach (var kvp in Environment) {
if (kvp.Value == null) {
if (kvp.Value is null) {
p.StartInfo.EnvironmentVariables.Remove (kvp.Key);
} else {
p.StartInfo.EnvironmentVariables [kvp.Key] = kvp.Value;
Expand Down Expand Up @@ -154,7 +154,7 @@ public Task<Execution> RunAsync ()
return tcs.Task;
}

public static Task<Execution> RunWithCallbacksAsync (string filename, IList<string> arguments, Dictionary<string, string>? environment = null, Action<string>? standardOutput = null, Action<string>? standardError = null, TextWriter? log = null, string? workingDirectory = null, TimeSpan? timeout = null, CancellationToken? cancellationToken = null)
public static Task<Execution> RunWithCallbacksAsync (string filename, IList<string> arguments, Dictionary<string, string?>? environment = null, Action<string>? standardOutput = null, Action<string>? standardError = null, TextWriter? log = null, string? workingDirectory = null, TimeSpan? timeout = null, CancellationToken? cancellationToken = null)
{
CallbackWriter? outputCallback = null;
CallbackWriter? errorCallback = null;
Expand All @@ -167,7 +167,7 @@ public static Task<Execution> RunWithCallbacksAsync (string filename, IList<stri
return RunAsync (filename, arguments, environment, outputCallback, errorCallback, log, workingDirectory, timeout, cancellationToken);
}

public static Task<Execution> RunAsync (string filename, IList<string> arguments, Dictionary<string, string>? environment = null, TextWriter? standardOutput = null, TextWriter? standardError = null, TextWriter? log = null, string? workingDirectory = null, TimeSpan? timeout = null, CancellationToken? cancellationToken = null)
public static Task<Execution> RunAsync (string filename, IList<string> arguments, Dictionary<string, string?>? environment = null, TextWriter? standardOutput = null, TextWriter? standardError = null, TextWriter? log = null, string? workingDirectory = null, TimeSpan? timeout = null, CancellationToken? cancellationToken = null)
{
return new Execution {
FileName = filename,
Expand All @@ -182,14 +182,14 @@ public static Task<Execution> RunAsync (string filename, IList<string> arguments
}.RunAsync ();
}

public static Task<Execution> RunAsync (string filename, IList<string> arguments, Dictionary<string, string>? environment = null, bool mergeOutput = false, string? workingDirectory = null, TextWriter? log = null, TimeSpan? timeout = null, CancellationToken? cancellationToken = null)
public static Task<Execution> RunAsync (string filename, IList<string> arguments, Dictionary<string, string?>? environment = null, bool mergeOutput = false, string? workingDirectory = null, TextWriter? log = null, TimeSpan? timeout = null, CancellationToken? cancellationToken = null)
{
var standardOutput = new StringWriter ();
var standardError = mergeOutput ? standardOutput : new StringWriter ();
return RunAsync (filename, arguments, environment, standardOutput, standardError, log, workingDirectory, timeout, cancellationToken);
}

public static Task<Execution> RunWithStringBuildersAsync (string filename, IList<string> arguments, Dictionary<string, string>? environment = null, StringBuilder? standardOutput = null, StringBuilder? standardError = null, TextWriter? log = null, string? workingDirectory = null, TimeSpan? timeout = null, CancellationToken? cancellationToken = null)
public static Task<Execution> RunWithStringBuildersAsync (string filename, IList<string> arguments, Dictionary<string, string?>? environment = null, StringBuilder? standardOutput = null, StringBuilder? standardError = null, TextWriter? log = null, string? workingDirectory = null, TimeSpan? timeout = null, CancellationToken? cancellationToken = null)
{
var stdout = standardOutput == null ? null : new StringWriter (standardOutput);
var stderr = standardError == null ? null : (standardOutput == standardError ? stdout : new StringWriter (standardError));
Expand Down

5 comments on commit 02838f2

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

💻 [CI Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: 02838f2c296b95d1814912421c6473b3e5ad8f6d

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

💻 [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: 02838f2c296b95d1814912421c6473b3e5ad8f6d

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

📋 [CI Build] API Diff 📋

API diff (for current PR)

ℹ️ API Diff (from PR only) (please review changes)

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

API diff (vs stable)

✅ API Diff from stable

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

Generator diff

Generator Diff (no change)

Pipeline on Agent XAMMINI-071.Monterey'
Hash: 02838f2c296b95d1814912421c6473b3e5ad8f6d

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

📚 [CI Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMMINI-063.Monterey'
Hash: 02838f2c296b95d1814912421c6473b3e5ad8f6d

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

1 tests failed, 1028 tests' device not found, 227 tests passed.

Failed tests

  • mmptest/macOS/Debug: TimedOut (Execution timed out after 120 minutes.)

Pipeline on Agent XAMBOT-1030.Monterey'
[tools] Fix nullability for the Execution.Environment field. (#15084)

Please sign in to comment.