Skip to content

Commit 5593b03

Browse files
committed
Added Logging to ClangScraper
1 parent 0e2c085 commit 5593b03

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

sources/SilkTouch/SilkTouch/Clang/ClangScraper.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ public record Configuration
9797
/// Runs ClangSharp to obtain the raw bindings for the given response file.
9898
/// </summary>
9999
/// <param name="config">The ClangSharp configuration.</param>
100+
/// <param name="rspIndex">the index of the current rsp for logging</param>
101+
/// <param name="rspCount">the total number of rsps</param>
100102
private (
101103
IEnumerable<KeyValuePair<string, Stream>> Sources,
102104
IEnumerable<KeyValuePair<string, Stream>> Tests,
103105
bool HasErrors
104-
) ScrapeRawBindings(ResponseFile config)
106+
) ScrapeRawBindings(ResponseFile config, int rspIndex, int rspCount)
105107
{
106108
var files = new Dictionary<string, Stream>();
107109

@@ -121,8 +123,11 @@ Stream OutputStreamFactory(string fileName)
121123
OutputStreamFactory
122124
);
123125
var hasErrors = false;
126+
int index = 0;
127+
int count = config.Files.Count;
124128
foreach (var file in config.Files)
125129
{
130+
index++;
126131
var filePath = Path.Combine(config.FileDirectory, file);
127132
var fileName = Path.GetFileName(file);
128133
logger.LogTrace(
@@ -190,19 +195,28 @@ out var handle
190195
using var translationUnit = TranslationUnit.GetOrCreate(handle);
191196
Debug.Assert(translationUnit is not null);
192197

193-
logger.LogInformation("Generating raw bindings for '{0}'", fileName);
198+
logger.LogInformation("Generating raw bindings for '{0}' ({1}/{2}) ({3}/{4})", fileName, index, count, rspIndex, rspCount);
194199
pinvokeGenerator.GenerateBindings(
195200
translationUnit,
196201
filePath,
197202
config.ClangCommandLineArgs,
198203
config.TranslationFlags
199204
);
200205
pinvokeGenerator.Close();
201-
logger.LogDebug(
206+
207+
if (files.Count == 0)
208+
{
209+
logger.LogWarning("No files generated for {0}",
210+
filePath);
211+
}
212+
else
213+
{
214+
logger.LogDebug(
202215
"Completed generation for {0}, file count: {1}",
203216
filePath,
204217
files.Count
205-
);
218+
);
219+
}
206220
}
207221
catch (Exception e)
208222
{
@@ -266,6 +280,8 @@ private async Task ScrapeBindingsAsync(
266280
// Generate all the sources and tests.
267281
var aggregatedSources = new ConcurrentDictionary<string, SyntaxTree>();
268282
var aggregatedTests = new ConcurrentDictionary<string, SyntaxTree>();
283+
int rspIndex = 0;
284+
int rspCount = rsps.Count;
269285
try
270286
{
271287
await Parallel.ForEachAsync(
@@ -279,8 +295,9 @@ await Parallel.ForEachAsync(
279295
await Task.Run(
280296
async () =>
281297
{
298+
int index = Interlocked.Increment(ref rspIndex);
282299
// Generate the raw bindings.
283-
var (sources, tests, hasErrors) = ScrapeRawBindings(rsp);
300+
var (sources, tests, hasErrors) = ScrapeRawBindings(rsp, index, rspCount);
284301

285302
static MemoryStream Reopen(MemoryStream ms) =>
286303
ms.TryGetBuffer(out var buff) && buff.Array is not null
@@ -450,6 +467,17 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
450467
.ReadResponseFiles(ctx.ConfigurationDirectory, cfg.ClangSharpResponseFiles)
451468
.ToList();
452469

470+
if (rsps.Count == 0)
471+
{
472+
logger.LogWarning("No Response files found for {}", ctx.JobKey);
473+
}
474+
475+
var missingIncludes = rsps.SelectMany<ResponseFile, string>(rsp => rsp.ClangCommandLineArgs.Where(arg => arg.StartsWith("--include-directory=") && !Directory.Exists(arg.Substring(20)))).Select(arg => arg.Substring(20)).Distinct();
476+
if (missingIncludes.Count() > 0)
477+
{
478+
logger.LogWarning("The following includes are missing and may cause erroneous generation: \n" + string.Join("\n", missingIncludes));
479+
}
480+
453481
// Apply modifications. This is done before the cache key as modifications to the rsps result in different
454482
// outputs.
455483
foreach (var mod in responseFileMods?.SelectMany(x => x.Get(ctx.JobKey)) ?? [])

0 commit comments

Comments
 (0)