Skip to content

Commit dc1b98c

Browse files
authored
Use NonBlockingFileSystem fs wrapper (#162)
* Bump * Add NonBlockingFileSystem * Fix CS
1 parent 13d245e commit dc1b98c

File tree

4 files changed

+191
-138
lines changed

4 files changed

+191
-138
lines changed
Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
5-
<LangVersion>13.0</LangVersion>
6-
<Nullable>enable</Nullable>
7-
<IsPackable>false</IsPackable>
8-
</PropertyGroup>
9-
10-
<Import Project="..\WarningConfiguration.targets" />
11-
12-
<ItemGroup>
13-
<PackageReference Include="H.Generators.Tests.Extensions" Version="1.24.1" />
14-
<PackageReference Include="Microsoft.Bcl.TimeProvider" Version="8.0.1" />
15-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
16-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" PrivateAssets="all" />
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
18-
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
19-
<PackageReference Include="Verify.XUnit" Version="28.9.0" />
20-
<PackageReference Include="Verify.SourceGenerators" Version="2.5.0" />
21-
<PackageReference Include="xunit" Version="2.9.3" />
22-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
23-
<PrivateAssets>all</PrivateAssets>
24-
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
25-
</PackageReference>
26-
</ItemGroup>
27-
28-
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
29-
<PackageReference Include="System.Text.Json" Version="8.0.5" />
30-
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.10.0" />
31-
</ItemGroup>
32-
33-
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
34-
<PackageReference Include="System.Text.Json" Version="9.0.1" />
35-
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.1.0" />
36-
</ItemGroup>
37-
38-
<ItemGroup>
39-
<ProjectReference Include="..\GitReader.SourceGenerator\GitReader.SourceGenerator.csproj" />
40-
</ItemGroup>
41-
42-
<ItemGroup>
43-
<None Update="GitReaderSnapshotTests.*.g.verified.cs">
44-
<DependentUpon>GitReaderSnapshotTests.cs</DependentUpon>
45-
</None>
46-
</ItemGroup>
47-
48-
<Target Name="ExtractSnapshots" BeforeTargets="Restore;_GenerateRestoreProjectSpec">
49-
<Message Importance="High" Text="Extracting $(MSBuildProjectDirectory)/../../v-tag-repository.zip to the $(MSBuildProjectDirectory)/../../repository-snapshots" />
50-
<Message Importance="High" Text="Extracting $(MSBuildProjectDirectory)/../../tag-repository.zip to the $(MSBuildProjectDirectory)/../../repository-snapshots" />
51-
<Message Importance="High" Text="Extracting $(MSBuildProjectDirectory)/../../no-tag-repository.zip to the $(MSBuildProjectDirectory)/../../repository-snapshots" />
52-
53-
<Unzip SourceFiles="$(MSBuildProjectDirectory)/../../repository-snapshots/v-tag-repository.zip"
54-
DestinationFolder="$(MSBuildProjectDirectory)/../../repository-snapshots"
55-
Condition="!Exists('$(MSBuildProjectDirectory)/../../repository-snapshots/v-tag-repository')"
56-
OverwriteReadOnlyFiles="true" />
57-
58-
<Unzip SourceFiles="$(MSBuildProjectDirectory)/../../repository-snapshots/tag-repository.zip"
59-
DestinationFolder="$(MSBuildProjectDirectory)/../../repository-snapshots"
60-
Condition="!Exists('$(MSBuildProjectDirectory)/../../repository-snapshots/tag-repository')"
61-
OverwriteReadOnlyFiles="true" />
62-
63-
<Unzip SourceFiles="$(MSBuildProjectDirectory)/../../repository-snapshots/no-tag-repository.zip"
64-
DestinationFolder="$(MSBuildProjectDirectory)/../../repository-snapshots"
65-
Condition="!Exists('$(MSBuildProjectDirectory)/../../repository-snapshots/no-tag-repository')"
66-
OverwriteReadOnlyFiles="true" />
67-
</Target>
68-
69-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
5+
<LangVersion>13.0</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<Import Project="..\WarningConfiguration.targets" />
11+
12+
<ItemGroup>
13+
<PackageReference Include="H.Generators.Tests.Extensions" Version="1.24.1" />
14+
<PackageReference Include="Microsoft.Bcl.TimeProvider" Version="8.0.1" />
15+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" PrivateAssets="all" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
18+
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
19+
<PackageReference Include="Verify.XUnit" Version="28.9.0" />
20+
<PackageReference Include="Verify.SourceGenerators" Version="2.5.0" />
21+
<PackageReference Include="xunit" Version="2.9.3" />
22+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
23+
<PrivateAssets>all</PrivateAssets>
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
25+
</PackageReference>
26+
</ItemGroup>
27+
28+
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
29+
<PackageReference Include="System.Text.Json" Version="8.0.5" />
30+
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.10.0" />
31+
</ItemGroup>
32+
33+
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
34+
<PackageReference Include="System.Text.Json" Version="9.0.1" />
35+
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.1.0" />
36+
</ItemGroup>
37+
38+
<ItemGroup>
39+
<ProjectReference Include="..\GitReader.SourceGenerator\GitReader.SourceGenerator.csproj" />
40+
</ItemGroup>
41+
42+
<ItemGroup>
43+
<None Update="GitReaderSnapshotTests.*.g.verified.cs">
44+
<DependentUpon>GitReaderSnapshotTests.cs</DependentUpon>
45+
</None>
46+
</ItemGroup>
47+
48+
<Target Name="ExtractSnapshots" BeforeTargets="Restore;_GenerateRestoreProjectSpec">
49+
<Message Importance="High" Text="Extracting $(MSBuildProjectDirectory)/../../v-tag-repository.zip to the $(MSBuildProjectDirectory)/../../repository-snapshots" />
50+
<Message Importance="High" Text="Extracting $(MSBuildProjectDirectory)/../../tag-repository.zip to the $(MSBuildProjectDirectory)/../../repository-snapshots" />
51+
<Message Importance="High" Text="Extracting $(MSBuildProjectDirectory)/../../no-tag-repository.zip to the $(MSBuildProjectDirectory)/../../repository-snapshots" />
52+
53+
<Unzip SourceFiles="$(MSBuildProjectDirectory)/../../repository-snapshots/v-tag-repository.zip"
54+
DestinationFolder="$(MSBuildProjectDirectory)/../../repository-snapshots"
55+
Condition="!Exists('$(MSBuildProjectDirectory)/../../repository-snapshots/v-tag-repository')"
56+
OverwriteReadOnlyFiles="true" />
57+
58+
<Unzip SourceFiles="$(MSBuildProjectDirectory)/../../repository-snapshots/tag-repository.zip"
59+
DestinationFolder="$(MSBuildProjectDirectory)/../../repository-snapshots"
60+
Condition="!Exists('$(MSBuildProjectDirectory)/../../repository-snapshots/tag-repository')"
61+
OverwriteReadOnlyFiles="true" />
62+
63+
<Unzip SourceFiles="$(MSBuildProjectDirectory)/../../repository-snapshots/no-tag-repository.zip"
64+
DestinationFolder="$(MSBuildProjectDirectory)/../../repository-snapshots"
65+
Condition="!Exists('$(MSBuildProjectDirectory)/../../repository-snapshots/no-tag-repository')"
66+
OverwriteReadOnlyFiles="true" />
67+
</Target>
68+
69+
</Project>

src/GitReader.SourceGenerator/GitInfoGenerator.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using GitReader.Structures;
2-
using H.Generators;
32
using H.Generators.Extensions;
43
using Microsoft.CodeAnalysis;
54
using System;
@@ -10,21 +9,16 @@
109
namespace GitReader.SourceGenerator;
1110

1211
[Generator]
13-
public class GitInfoGenerator : IIncrementalGenerator
12+
public class GitInfoGenerator(
13+
TimeProvider timeProvider
14+
) : IIncrementalGenerator
1415
{
1516
public const string Id = "GI";
1617

17-
private readonly TimeProvider _timeProvider;
18-
1918
public GitInfoGenerator() : this(TimeProvider.System)
2019
{
2120
}
2221

23-
public GitInfoGenerator(TimeProvider timeProvider)
24-
{
25-
_timeProvider = timeProvider;
26-
}
27-
2822
public static GitInfoGenerator Create(TimeProvider timeProvider) => new(
2923
timeProvider
3024
);
@@ -107,6 +101,7 @@ CancellationToken cancellationToken
107101

108102
using var repository = await Repository.Factory.OpenStructureAsync(
109103
configuration.RootDirectory,
104+
new NonBlockingFileSystem(65536),
110105
cancellationToken
111106
);
112107

@@ -161,7 +156,7 @@ repository.Head is { } head
161156
}
162157

163158
gitInfoCache = new GitInfo(
164-
_timeProvider.GetUtcNow(),
159+
timeProvider.GetUtcNow(),
165160
configuration.TargetNamespace,
166161
head.Name,
167162
commitAbbreviatedHash,
Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>13.0</LangVersion>
6-
<Nullable>enable</Nullable>
7-
<ProjectName>GitReader.Generator</ProjectName>
8-
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
9-
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
10-
<IsPackable>true</IsPackable>
11-
</PropertyGroup>
12-
13-
<Import Project="..\WarningConfiguration.targets" />
14-
15-
<PropertyGroup Label="NuGet">
16-
<PackageLicense>MIT</PackageLicense>
17-
<RepositoryUrl>https://github.com/aviationexam/git-reader-source-generator</RepositoryUrl>
18-
<RepositoryType>git</RepositoryType>
19-
<IncludeSymbols>true</IncludeSymbols>
20-
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
21-
<DevelopmentDependency>true</DevelopmentDependency>
22-
<PackageReadmeFile>README.md</PackageReadmeFile>
23-
</PropertyGroup>
24-
25-
<ItemGroup>
26-
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
27-
<None Include="$(AssemblyName).props" Pack="true" PackagePath="build" />
28-
<None Include="..\..\README.md" Pack="true" PackagePath="\" Visible="false"/>
29-
</ItemGroup>
30-
31-
<ItemGroup>
32-
<PackageReference Include="Microsoft.Bcl.TimeProvider" Version="8.0.1" PrivateAssets="all" GeneratePathProperty="true" />
33-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all" />
34-
<PackageReference Include="GitReader" Version="1.8.0" PrivateAssets="all" GeneratePathProperty="true" />
35-
<PackageReference Include="GitReader.Core" Version="1.8.0" PrivateAssets="all" GeneratePathProperty="true" />
36-
<PackageReference Include="H.Generators.Extensions" Version="1.24.0" PrivateAssets="all" GeneratePathProperty="true" />
37-
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="all" />
38-
</ItemGroup>
39-
40-
<PropertyGroup>
41-
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_AddAnalyzersToOutput</TargetsForTfmSpecificContentInPackage>
42-
</PropertyGroup>
43-
44-
<Target Name="_AddAnalyzersToOutput">
45-
<Message Importance="High" Text="$(MSBuildProjectDirectory)\$(OutputPath)" />
46-
<Message Importance="High" Text="$(PkgMicrosoft_Bcl_TimeProvider)\lib\netstandard2.0\Microsoft.Bcl.TimeProvider.dll" />
47-
<Message Importance="High" Text="$(PkgGitReader)\lib\netstandard2.0\GitReader.dll" />
48-
<Message Importance="High" Text="$(PkgGitReader_Core)\lib\netstandard2.0\GitReader.Core.dll" />
49-
<Message Importance="High" Text="$(PkgH_Generators_Extensions)\lib\netstandard2.0\H.Generators.Extensions.dll" />
50-
51-
<ItemGroup>
52-
<TfmSpecificPackageFile Include="$(PkgMicrosoft_Bcl_TimeProvider)\lib\netstandard2.0\Microsoft.Bcl.TimeProvider.dll" PackagePath="analyzers/dotnet/cs" />
53-
<TfmSpecificPackageFile Include="$(PkgGitReader)\lib\netstandard2.0\GitReader.dll" PackagePath="analyzers/dotnet/cs" />
54-
<TfmSpecificPackageFile Include="$(PkgGitReader_Core)\lib\netstandard2.0\GitReader.Core.dll" PackagePath="analyzers/dotnet/cs" />
55-
<TfmSpecificPackageFile Include="$(PkgH_Generators_Extensions)\lib\netstandard2.0\H.Generators.Extensions.dll" PackagePath="analyzers/dotnet/cs" />
56-
</ItemGroup>
57-
</Target>
58-
59-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<LangVersion>13.0</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<ProjectName>GitReader.Generator</ProjectName>
8+
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
9+
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
10+
<IsPackable>true</IsPackable>
11+
</PropertyGroup>
12+
13+
<Import Project="..\WarningConfiguration.targets" />
14+
15+
<PropertyGroup Label="NuGet">
16+
<PackageLicense>MIT</PackageLicense>
17+
<RepositoryUrl>https://github.com/aviationexam/git-reader-source-generator</RepositoryUrl>
18+
<RepositoryType>git</RepositoryType>
19+
<IncludeSymbols>true</IncludeSymbols>
20+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
21+
<DevelopmentDependency>true</DevelopmentDependency>
22+
<PackageReadmeFile>README.md</PackageReadmeFile>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
27+
<None Include="$(AssemblyName).props" Pack="true" PackagePath="build" />
28+
<None Include="..\..\README.md" Pack="true" PackagePath="\" Visible="false"/>
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<PackageReference Include="Microsoft.Bcl.TimeProvider" Version="8.0.1" PrivateAssets="all" GeneratePathProperty="true" />
33+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all" />
34+
<PackageReference Include="GitReader" Version="1.8.0" PrivateAssets="all" GeneratePathProperty="true" />
35+
<PackageReference Include="GitReader.Core" Version="1.8.0" PrivateAssets="all" GeneratePathProperty="true" />
36+
<PackageReference Include="H.Generators.Extensions" Version="1.24.0" PrivateAssets="all" GeneratePathProperty="true" />
37+
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="all" />
38+
</ItemGroup>
39+
40+
<PropertyGroup>
41+
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_AddAnalyzersToOutput</TargetsForTfmSpecificContentInPackage>
42+
</PropertyGroup>
43+
44+
<Target Name="_AddAnalyzersToOutput">
45+
<Message Importance="High" Text="$(MSBuildProjectDirectory)\$(OutputPath)" />
46+
<Message Importance="High" Text="$(PkgMicrosoft_Bcl_TimeProvider)\lib\netstandard2.0\Microsoft.Bcl.TimeProvider.dll" />
47+
<Message Importance="High" Text="$(PkgGitReader)\lib\netstandard2.0\GitReader.dll" />
48+
<Message Importance="High" Text="$(PkgGitReader_Core)\lib\netstandard2.0\GitReader.Core.dll" />
49+
<Message Importance="High" Text="$(PkgH_Generators_Extensions)\lib\netstandard2.0\H.Generators.Extensions.dll" />
50+
51+
<ItemGroup>
52+
<TfmSpecificPackageFile Include="$(PkgMicrosoft_Bcl_TimeProvider)\lib\netstandard2.0\Microsoft.Bcl.TimeProvider.dll" PackagePath="analyzers/dotnet/cs" />
53+
<TfmSpecificPackageFile Include="$(PkgGitReader)\lib\netstandard2.0\GitReader.dll" PackagePath="analyzers/dotnet/cs" />
54+
<TfmSpecificPackageFile Include="$(PkgGitReader_Core)\lib\netstandard2.0\GitReader.Core.dll" PackagePath="analyzers/dotnet/cs" />
55+
<TfmSpecificPackageFile Include="$(PkgH_Generators_Extensions)\lib\netstandard2.0\H.Generators.Extensions.dll" PackagePath="analyzers/dotnet/cs" />
56+
</ItemGroup>
57+
</Target>
58+
59+
</Project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using GitReader.IO;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.IO;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace GitReader.SourceGenerator;
8+
9+
[SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1035:Do not use APIs banned for analyzers")]
10+
internal sealed class NonBlockingFileSystem(
11+
int bufferSize
12+
) : IFileSystem
13+
{
14+
private readonly IFileSystem _fileSystem = new StandardFileSystem(bufferSize);
15+
16+
public string Combine(
17+
params string[] paths
18+
) => _fileSystem.Combine(paths);
19+
20+
public string GetDirectoryPath(
21+
string path
22+
) => _fileSystem.GetDirectoryPath(path);
23+
24+
public string GetFullPath(
25+
string path
26+
) => _fileSystem.GetFullPath(path);
27+
28+
public bool IsPathRooted(
29+
string path
30+
) => _fileSystem.IsPathRooted(path);
31+
32+
public string ResolveRelativePath(
33+
string basePath, string path
34+
) => _fileSystem.ResolveRelativePath(basePath, path);
35+
36+
public Task<bool> IsFileExistsAsync(
37+
string path, CancellationToken ct
38+
) => _fileSystem.IsFileExistsAsync(path, ct);
39+
40+
public Task<string[]> GetFilesAsync(
41+
string basePath, string match, CancellationToken ct
42+
) => _fileSystem.GetFilesAsync(basePath, match, ct);
43+
44+
public Task<Stream> OpenAsync(
45+
string path, bool isSeekable, CancellationToken ct
46+
) => Task.FromResult<Stream>(new FileStream(
47+
path,
48+
FileMode.Open,
49+
FileAccess.Read,
50+
FileShare.ReadWrite,
51+
65536,
52+
true
53+
));
54+
55+
public Task<TemporaryFileDescriptor> CreateTemporaryAsync(
56+
CancellationToken ct
57+
) => _fileSystem.CreateTemporaryAsync(ct);
58+
}

0 commit comments

Comments
 (0)