Skip to content

Commit

Permalink
Use .NET 9 Lock via PolyShim
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Sep 6, 2024
1 parent b5a2b38 commit 68bda90
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 25 deletions.
4 changes: 2 additions & 2 deletions CliWrap.Benchmarks/PipeFromStreamBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PipeFromStreamBenchmarks
[Benchmark(Baseline = true)]
public async Task<Stream> ExecuteWithCliWrap_PipeToStream()
{
await using var stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5 });
await using var stream = new MemoryStream([1, 2, 3, 4, 5]);

var command = stream | Cli.Wrap(FilePath).WithArguments(Args);
await command.ExecuteAsync();
Expand All @@ -25,7 +25,7 @@ public async Task<Stream> ExecuteWithCliWrap_PipeToStream()
[Benchmark]
public async Task<Stream> MedallionShell()
{
await using var stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5 });
await using var stream = new MemoryStream([1, 2, 3, 4, 5]);

var command = Medallion.Shell.Command.Run(FilePath, Args.Split(' ')) < stream;
await command.Task;
Expand Down
2 changes: 1 addition & 1 deletion CliWrap.Tests.Dummy/CliWrap.Tests.Dummy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="CliFx" Version="2.3.5" />
<PackageReference Include="CSharpier.MsBuild" Version="0.29.1" PrivateAssets="all" />
<PackageReference Include="PolyShim" Version="1.12.0" PrivateAssets="all" />
<PackageReference Include="PolyShim" Version="1.13.0" PrivateAssets="all" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion CliWrap.Tests.Dummy/Commands/EnvironmentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace CliWrap.Tests.Dummy.Commands;
public class EnvironmentCommand : ICommand
{
[CommandParameter(0)]
public IReadOnlyList<string> Names { get; init; } = Array.Empty<string>();
public IReadOnlyList<string> Names { get; init; } = [];

public async ValueTask ExecuteAsync(IConsole console)
{
Expand Down
2 changes: 1 addition & 1 deletion CliWrap.Tests.Dummy/Commands/Shared/OutputTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum OutputTarget
{
StdOut = 1,
StdErr = 2,
All = StdOut | StdErr
All = StdOut | StdErr,
}

internal static class OutputTargetExtensions
Expand Down
2 changes: 1 addition & 1 deletion CliWrap.Tests/CliWrap.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="PolyShim" Version="1.12.0" PrivateAssets="all" />
<PackageReference Include="PolyShim" Version="1.13.0" PrivateAssets="all" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />
Expand Down
2 changes: 1 addition & 1 deletion CliWrap.Tests/ConfigurationSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void I_can_configure_the_environment_variables_using_a_builder()
["name"] = "value",
["key"] = "door",
["zzz"] = "yyy",
["aaa"] = "bbb"
["aaa"] = "bbb",
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion CliWrap.Tests/PipingSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public async Task I_can_execute_a_command_and_pipe_the_stdout_into_multiple_stre
"1000000",
// Buffer needs to be >= BufferSizes.Stream to fail
"--buffer",
"100000"
"100000",
]
);

Expand Down
2 changes: 1 addition & 1 deletion CliWrap/CliWrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="CSharpier.MsBuild" Version="0.29.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net462'" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="PolyShim" Version="1.12.0" PrivateAssets="all" />
<PackageReference Include="PolyShim" Version="1.13.0" PrivateAssets="all" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net462'" />
<PackageReference Include="System.Management" Version="8.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1'" />
<PackageReference Include="System.Memory" Version="4.5.5" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net462'" />
Expand Down
6 changes: 5 additions & 1 deletion CliWrap/Command.Execution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ private string GetOptimallyQualifiedTargetFilePath()
// Currently, we only need this workaround for script files on Windows, so short-circuit
// if we are on a different platform.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return TargetFilePath;
}

// Don't do anything for fully qualified paths or paths that already have an extension specified.
// System.Diagnostics.Process knows how to handle those without our help.
Expand All @@ -34,7 +36,9 @@ private string GetOptimallyQualifiedTargetFilePath()
Path.IsPathRooted(TargetFilePath)
|| !string.IsNullOrWhiteSpace(Path.GetExtension(TargetFilePath))
)
{
return TargetFilePath;
}

static IEnumerable<string> GetProbeDirectoryPaths()
{
Expand Down Expand Up @@ -86,7 +90,7 @@ private ProcessStartInfo CreateStartInfo()
// We need this in order to be able to send signals to one specific child process,
// without affecting any others that may also be running in parallel.
// https://github.com/Tyrrrz/CliWrap/issues/47
CreateNoWindow = true
CreateNoWindow = true,
};

// Set credentials
Expand Down
2 changes: 1 addition & 1 deletion CliWrap/CommandResultValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum CommandResultValidation
/// <summary>
/// Ensure that the command returned a zero exit code.
/// </summary>
ZeroExitCode = 0b1
ZeroExitCode = 0b1,
}

internal static class CommandResultValidationExtensions
Expand Down
6 changes: 2 additions & 4 deletions CliWrap/Utils/Observable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ internal static class Observable
public static IObservable<T> Create<T>(Func<IObserver<T>, IDisposable> subscribe) =>
new Observable<T>(subscribe);

public static IObservable<T> CreateSynchronized<T>(
Func<IObserver<T>, IDisposable> subscribe,
object? syncRoot = null
) => Create<T>(observer => subscribe(new SynchronizedObserver<T>(observer, syncRoot)));
public static IObservable<T> CreateSynchronized<T>(Func<IObserver<T>, IDisposable> subscribe) =>
Create<T>(observer => subscribe(new SynchronizedObserver<T>(observer)));
}
2 changes: 1 addition & 1 deletion CliWrap/Utils/SimplexStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ CancellationToken cancellationToken

public async Task ReportCompletionAsync(CancellationToken cancellationToken = default) =>
// Write an empty buffer that will make ReadAsync(...) return 0, which signifies the end of stream
await WriteAsync(Array.Empty<byte>(), 0, 0, cancellationToken).ConfigureAwait(false);
await WriteAsync([], 0, 0, cancellationToken).ConfigureAwait(false);

protected override void Dispose(bool disposing)
{
Expand Down
12 changes: 6 additions & 6 deletions CliWrap/Utils/SynchronizedObserver.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
using System;
using System.Threading;

namespace CliWrap.Utils;

internal class SynchronizedObserver<T>(IObserver<T> observer, object? syncRoot = null)
: IObserver<T>
internal class SynchronizedObserver<T>(IObserver<T> observer) : IObserver<T>
{
private readonly object _syncRoot = syncRoot ?? new object();
private readonly Lock _lock = new();

public void OnCompleted()
{
lock (_syncRoot)
using (_lock.EnterScope())
{
observer.OnCompleted();
}
}

public void OnError(Exception error)
{
lock (_syncRoot)
using (_lock.EnterScope())
{
observer.OnError(error);
}
}

public void OnNext(T value)
{
lock (_syncRoot)
using (_lock.EnterScope())
{
observer.OnNext(value);
}
Expand Down
6 changes: 3 additions & 3 deletions CliWrap/Utils/WindowsSignaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public bool TrySend(int processId, int signalId)
// This is a .NET 3.5 executable, so we need to configure framework rollover
// to allow it to also run against .NET 4.0 and higher.
// https://gist.github.com/MichalStrehovsky/d6bc5e4d459c23d0cf3bd17af9a1bcf5
["COMPLUS_OnlyUseLatestCLR"] = "1"
}
}
["COMPLUS_OnlyUseLatestCLR"] = "1",
},
},
};

if (!process.Start())
Expand Down

0 comments on commit 68bda90

Please sign in to comment.