Skip to content

Commit

Permalink
Replace resx with a statically generated cs file (#3025)
Browse files Browse the repository at this point in the history
* Replace resx with a statically generated cs file

* upgrade regex to remove need for System.Buffers

* Really remove need for System.Buffers

* don't modify the throughput tests and fix build constants

* import vendored improvements

* Re-apply Anna's fix

* remove annoying json file and add .gitignore to avoid these errors in the future

* actually add the .gitignore mentioned earlier

* don't null out array before it's used
  • Loading branch information
robertpi authored Aug 2, 2022
1 parent 1711980 commit 98667ed
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 991 deletions.
21 changes: 5 additions & 16 deletions tracer/build/_build/UpdateVendors/VendoredDependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ static VendoredDependency()

Add(
libraryName: "IndieSystem.Text.RegularExpressions",
version: "0.1",
downloadUrl: "https://github.com/robertpi/IndieRegex/archive/refs/tags/v0.3.zip",
pathToSrc: new[] { "IndieRegex-0.3", "src" },
version: "0.6",
downloadUrl: "https://github.com/robertpi/IndieRegex/archive/refs/tags/v0.6.zip",
pathToSrc: new[] { "IndieRegex-0.6", "src" },
// Perform standard CS file transform with additional '#nullable enable' directive at the beginning of the files, since the vendored project was built with <Nullable>enable</Nullable>
transform: filePath => RewriteCsFileWithStandardTransform(filePath, originalNamespace: "IndieSystem.Text.RegularExpressions",
AddIfNetcoreapp31OrGreater, AddNullableDirectiveTransform, AddIgnoreNullabilityWarningDisablePragma, FixupResources),
relativePathsToExclude: new[] { "additional/HashCode.cs" });
AddIfNetcoreapp31OrGreater, AddNullableDirectiveTransform, AddIgnoreNullabilityWarningDisablePragma),
relativePathsToExclude: new[] { "additional/HashCode.cs", "SR.resx" });
}

public static List<VendoredDependency> All { get; set; } = new List<VendoredDependency>();
Expand Down Expand Up @@ -265,17 +265,6 @@ static string AddIgnoreNullabilityWarningDisablePragma(string filePath, string c
"CS8774" + // Member 'x' must have a non-null value when exiting.
Environment.NewLine + content;

static string FixupResources(string filePath, string content)
{
if (content.Contains("new global::System.Resources.ResourceManager(\"IndieSystem.Text.RegularExpressions.SR\""))
{
return content.Replace("new global::System.Resources.ResourceManager(\"IndieSystem.Text.RegularExpressions.SR\"",
"new global::System.Resources.ResourceManager(\"Datadog.Trace.Vendors.IndieSystem.Text.RegularExpressions.SR\"");
}

return content;
}

private static void RewriteFileWithTransform(string filePath, Func<string, string> transform)
{
var fileContent = File.ReadAllText(filePath);
Expand Down
1 change: 1 addition & 0 deletions tracer/build/crank/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json
4 changes: 2 additions & 2 deletions tracer/dependabot/Datadog.Dependabot.Vendors.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<!-- https://www.nuget.org/packages/Datadog.Sketches/1.0.0 -->
<PackageReference Include="Datadog.Sketches" Version="1.0.0" />

<!-- https://www.nuget.org/packages/IndieSystem.Text.RegularExpressions/0.1 -->
<PackageReference Include="IndieSystem.Text.RegularExpressions" Version="0.1" />
<!-- https://www.nuget.org/packages/IndieSystem.Text.RegularExpressions/0.6 -->
<PackageReference Include="IndieSystem.Text.RegularExpressions" Version="0.6" />

</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions tracer/src/Datadog.Trace/Datadog.Trace.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
<DefineConstants>$(DefineConstants);ASYNCLOCAL;HASHTABLE;FEATURE_DEFAULT_INTERFACE;FEATURE_SPAN</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<DefineConstants>$(DefineConstants);REGEXGENERATOR</DefineConstants>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<DefineConstants>$(DefineConstants);NO_ARRAY_POOL</DefineConstants>
</PropertyGroup>

<!-- Remove System.Collections.NonGeneric. This was defined in Serilog but it is unnecessary -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
<Nullable>enable</Nullable>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>

<!-- nuget stuff -->
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>regex;regular-expression;non-backtracking</PackageTags>
<Authors>Robert Pickering</Authors>
<Copyright>Robert Pickering, .NET Foundation and Contributors</Copyright>
<Description>IndieRegex or IndieSystem.Text.RegularExpressions is a drop-in replacement for .NET's Regex class. It is built using the source of Regex from .NET 7.0, modified and patched to run on .NET Framework 4.6.1, .NET Standard 2.0, .NET Core 3.1, .NET 5.0 and .NET 6.0.</Description>
</PropertyGroup>

<ItemGroup>
<Compile Include="additional\BitOperations.cs" />
<Compile Include="System\Collections\HashtableExtensions.cs" />
Expand Down Expand Up @@ -35,7 +43,6 @@
<Compile Include="System\Text\RegularExpressions\RegexCharClass.cs" />
<Compile Include="System\Text\RegularExpressions\RegexCompilationInfo.cs" />
<Compile Include="System\Text\RegularExpressions\RegexFindOptimizations.cs" />
<Compile Include="System\Text\RegularExpressions\RegexGeneratorAttribute.cs" />
<Compile Include="System\Text\RegularExpressions\RegexInterpreter.cs" />
<Compile Include="System\Text\RegularExpressions\RegexInterpreterCode.cs" />
<Compile Include="System\Text\RegularExpressions\RegexMatchTimeoutException.cs" />
Expand Down Expand Up @@ -99,9 +106,8 @@
<Compile Include="common\ValueListBuilder.Pop.cs" />

<!-- our additional files -->
<Compile Include="AssemblyInfo.cs" />
<Compile Include="SR.cs" />
<Compile Include="SR.Designer.cs" />
<Compile Include="SR.g.cs" />
<Compile Include="additional\HashCode.cs" />
<Compile Include="additional\RequiresDynamicCodeAttribute.cs" />
<Compile Include="additional\StringSyntaxAttribute.cs" />
Expand All @@ -119,18 +125,13 @@
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
</ItemGroup>

<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Remove="SR.resx" />
</ItemGroup>
</Project>

<PropertyGroup>
<DefineConstants>$(DefineConstants);NO_ARRAY_POOL</DefineConstants>
</PropertyGroup>

</Project>
Loading

0 comments on commit 98667ed

Please sign in to comment.