Skip to content

Commit 9f394e8

Browse files
committed
Disable Warnings, Remove Generated Files, and Cleanup
1 parent 3d94412 commit 9f394e8

File tree

5 files changed

+218
-174
lines changed

5 files changed

+218
-174
lines changed

Silk.NET.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ Global
178178
{BB33CC4A-EA3A-4D4F-879A-F93C617C5E63}.Release|Any CPU.ActiveCfg = Release|Any CPU
179179
{BB33CC4A-EA3A-4D4F-879A-F93C617C5E63}.Release|Any CPU.Build.0 = Release|Any CPU
180180
{C8F32825-1F93-44F0-AB88-26167C21CADF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
181-
{C8F32825-1F93-44F0-AB88-26167C21CADF}.Debug|Any CPU.Build.0 = Debug|Any CPU
182181
{C8F32825-1F93-44F0-AB88-26167C21CADF}.Release|Any CPU.ActiveCfg = Release|Any CPU
183182
{C8F32825-1F93-44F0-AB88-26167C21CADF}.Release|Any CPU.Build.0 = Release|Any CPU
184183
{49A42CE3-94C5-4239-B0FC-F1FF8D7AAADA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

generator.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@
2323
"sources/Windows/um/httpserv/IHttpResponse4.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/um/httpserv/IHttpResponse4.cs",
2424
"sources/Windows/um/httpserv/IHttpTraceContext.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/um/httpserv/IHttpTraceContext.cs",
2525
"sources/Windows/um/httpserv/CHttpModule.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/um/httpserv/CHttpModule.cs",
26-
"sources/Windows/um/icm/Windows.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/um/icm/Windows.cs",
2726
"sources/Windows/um/winioctl/TXFS_READ_BACKUP_INFORMATION_OUT.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/um/winioctl/TXFS_READ_BACKUP_INFORMATION_OUT.cs",
2827
"sources/Windows/um/winioctl/STORAGE_QUERY_DEPENDENT_VOLUME_RESPONSE.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/um/winioctl/STORAGE_QUERY_DEPENDENT_VOLUME_RESPONSE.cs",
2928
"sources/Windows/um/WinUser/Windows.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/um/WinUser/Windows.cs",
3029
"sources/Windows/shared/strsafe/Windows.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/shared/strsafe/Windows.cs",
31-
"sources/Windows/shared/hidpi/Windows.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/shared/hidpi/Windows.cs",
3230
"sources/Windows/shared/ws2ipdef/Windows.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/shared/ws2ipdef/Windows.cs",
3331
"sources/Windows/shared/Iprtrmib/MIB_OPAQUE_INFO.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/shared/Iprtrmib/MIB_OPAQUE_INFO.cs",
34-
"sources/Gdiplus/um/gdiplustypes/GpRect.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Gdiplus/um/gdiplustypes/GpRect.cs",
35-
"sources/Gdiplus/um/gdiplustypes/GpRectF.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Gdiplus/um/gdiplustypes/GpRectF.cs",
36-
"sources/Gdiplus/um/gdiplustypes/GpPathData.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Gdiplus/um/gdiplustypes/GpPathData.cs",
3732
"sources/WinRT/winrt/windows.perception.spatial/ISpatialCoordinateSystem.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/windows.perception.spatial/ISpatialCoordinateSystem.cs",
3833
"sources/WinRT/winrt/windows.security.authentication.web.core/IID.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/windows.security.authentication.web.core/IID.Manual.cs",
3934
"sources/WinRT/winrt/windows.ui.input/IID.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/windows.ui.input/IID.Manual.cs"
@@ -43,7 +38,11 @@
4338
"SkipScrapeIf": [
4439
"!win"
4540
],
46-
"CacheOutput": false
41+
"CacheOutput": false,
42+
"GeneratedToRemove": [
43+
"tests/DirectX/d3dx12/d3dx12_core/**.cs",
44+
"tests/DirectX/d3dx12/d3dx12_barriers/**.cs"
45+
]
4746
},
4847
"ChangeNamespace": {
4948
"Mappings": {
@@ -59,7 +58,8 @@
5958
"WarningCodes": [
6059
"CS1589", //XML Comments missing (due to missing docs)
6160
"CS0419", //Inheritdoc issue (due to bug)
62-
"CA1416" //Function available outside of target os (intended)
61+
"CA1416", //Function available outside of target os (intended)
62+
"CS0618" //Obsolete Warnings
6363
]
6464
}
6565
},

sources/SilkTouch/SilkTouch/Clang/ClangScraper.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.IO.Hashing;
1010
using System.Linq;
1111
using System.Runtime.InteropServices;
12+
using System.Text.RegularExpressions;
1213
using System.Threading;
1314
using System.Threading.Tasks;
1415
using ClangSharp;
@@ -91,6 +92,11 @@ public record Configuration
9192
/// </summary>
9293
// TODO document
9394
public string[]? SkipScrapeIf { get; init; }
95+
96+
/// <summary>
97+
/// Generated files to Remove
98+
/// </summary>
99+
public string[]? GeneratedToRemove { get; init; }
94100
}
95101

96102
/// <summary>
@@ -238,13 +244,15 @@ out var handle
238244
/// Runs ClangSharp for each of the given response files and aggregates the raw outputs.
239245
/// </summary>
240246
/// <param name="rsps">The response files.</param>
247+
/// <param name="toRemovePatterns">files to remove</param>
241248
/// <param name="job">The job context.</param>
242249
/// <param name="cfg">The configuration.</param>
243250
/// <param name="cacheKey">The cache key.</param>
244251
/// <param name="ct">The cancellation token.</param>
245252
/// <exception cref="InvalidOperationException">The scraper output wasn't as expected.</exception>
246253
private async Task ScrapeBindingsAsync(
247254
IReadOnlyList<ResponseFile> rsps,
255+
IEnumerable<string> toRemovePatterns,
248256
IModContext job,
249257
Configuration cfg,
250258
string? cacheKey = null,
@@ -325,6 +333,7 @@ static MemoryStream Reopen(MemoryStream ms) =>
325333
// Cache the output.
326334
//TODO: Refactor for better Parallelisation
327335
//Breaks with high concurrency
336+
string relativePath = $"{(isTest ? "tests" : "sources")}/{relativeKey}";
328337
if (cacheKey is not null && !hasErrors && cfg.CacheOutput)
329338
{
330339
cacheDir ??= (
@@ -338,20 +347,26 @@ static MemoryStream Reopen(MemoryStream ms) =>
338347
cacheKey,
339348
CacheIntent.StageIntermediateOutput,
340349
CacheFlags.RequireNewLocked | CacheFlags.NoHostDirectory,
341-
$"{(isTest ? "tests" : "sources")}/{relativeKey}",
350+
relativePath,
342351
stream
343352
);
344353
stream.Seek(0, SeekOrigin.Begin);
345354
}
346355

356+
if (toRemovePatterns.Any(pattern => Regex.IsMatch(relativePath, pattern)))
357+
{
358+
logger.LogTrace("ClangSharp skipped {0}", relativePath);
359+
continue;
360+
}
361+
347362
// Add it to the dictionary.
348363
if (
349364
!(isTest ? aggregatedTests : aggregatedSources).TryAdd(
350365
relativeKey,
351366
CSharpSyntaxTree.ParseText(
352367
SourceText.From(
353368
cfg.ManualOverrides?.TryGetValue(
354-
$"{(isTest ? "tests" : "sources")}/{relativeKey}",
369+
relativePath,
355370
out var @override
356371
) ?? false
357372
? File.OpenRead(
@@ -467,6 +482,8 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
467482
.ReadResponseFiles(ctx.ConfigurationDirectory, cfg.ClangSharpResponseFiles)
468483
.ToList();
469484

485+
var toRemovePatterns = cfg.GeneratedToRemove?.Select(toRemove => Regex.Escape(toRemove).Replace(@"\*\*", ".*")) ?? [];
486+
470487
if (rsps.Count == 0)
471488
{
472489
logger.LogWarning("No Response files found for {}", ctx.JobKey);
@@ -504,7 +521,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
504521
if (!skip)
505522
{
506523
// Run the scraper over the response files
507-
await ScrapeBindingsAsync(rsps, ctx, cfg, cacheKey, ct);
524+
await ScrapeBindingsAsync(rsps, toRemovePatterns, ctx, cfg, cacheKey, ct);
508525
}
509526
}
510527
catch (Exception e)

sources/SilkTouch/SilkTouch/Mods/DisableWarnings.cs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
using Microsoft.CodeAnalysis.CSharp;
66
using Microsoft.CodeAnalysis;
77
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
8-
using Microsoft.CodeAnalysis.Editing;
9-
using Microsoft.Extensions.Logging;
108
using Microsoft.Extensions.Options;
11-
using System.Reflection;
12-
using Silk.NET.SilkTouch.Utility;
13-
using Silk.NET.SilkTouch.Sources;
149

1510
namespace Silk.NET.SilkTouch.Mods
1611
{
@@ -46,8 +41,6 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
4641
return;
4742
}
4843

49-
var proj = ctx.SourceProject;
50-
5144
// Create the pragma directive trivia
5245
var pragmaDirective = Trivia(
5346
PragmaWarningDirectiveTrivia(
@@ -57,6 +50,8 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
5750
SeparatedList<ExpressionSyntax>(
5851
cfg.WarningCodes.Select(warn => IdentifierName(warn)))));
5952

53+
var proj = ctx.SourceProject;
54+
6055
foreach (var docId in proj?.DocumentIds ?? [])
6156
{
6257
var doc =
@@ -93,6 +88,45 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
9388
}
9489

9590
ctx.SourceProject = proj;
91+
92+
proj = ctx.TestProject;
93+
94+
foreach (var docId in proj?.DocumentIds ?? [])
95+
{
96+
var doc =
97+
proj?.GetDocument(docId) ?? throw new InvalidOperationException("Document missing");
98+
if (await doc.GetSyntaxRootAsync(ct) is not { } root)
99+
{
100+
continue;
101+
}
102+
103+
// Find the using directive
104+
SyntaxNode? namespaceNode = root.DescendantNodes().OfType<FileScopedNamespaceDeclarationSyntax>().FirstOrDefault();
105+
106+
if (namespaceNode == null)
107+
{
108+
// Skip the case where no using directive is found
109+
continue;
110+
}
111+
112+
// Get the leading trivia (comments) of the first using directive
113+
var leadingTrivia = namespaceNode.GetLeadingTrivia();
114+
115+
// Insert the pragma directive after the comments
116+
var newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count, pragmaDirective)
117+
.Add(CarriageReturnLineFeed);
118+
119+
// Update the using directive with the new leading trivia
120+
var newUsingDirective = namespaceNode.WithLeadingTrivia(newLeadingTrivia);
121+
122+
// Replace the old using directive with the new one in the root node
123+
root = root.ReplaceNode(namespaceNode, newUsingDirective);
124+
doc = doc.WithSyntaxRoot(root);
125+
126+
proj = doc.Project;
127+
}
128+
129+
ctx.TestProject = proj;
96130
}
97131
}
98132
}

0 commit comments

Comments
 (0)