Skip to content

Commit 1155ee2

Browse files
committed
C#: Write overlay metadata at end of extraction.
1 parent 7ab4331 commit 1155ee2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Extractor.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5+
using System.IO;
56
using System.Linq;
67
using Microsoft.CodeAnalysis;
78
using Microsoft.CodeAnalysis.CSharp;
@@ -53,6 +54,20 @@ private static void AnalyseStandalone(
5354
}
5455

5556
progressMonitor.MissingSummary(analyser.ExtractionContext!.MissingTypes.Count(), analyser.ExtractionContext!.MissingNamespaces.Count());
57+
58+
// If extracting a base database, we need to create an empty metadata file.
59+
if (EnvironmentVariables.GetBaseMetaDataOutPath() is string baseMetaDataOutPath)
60+
{
61+
try
62+
{
63+
analyser.Logger.LogInfo($"Creating base metadata file at {baseMetaDataOutPath}");
64+
File.WriteAllText(baseMetaDataOutPath, string.Empty);
65+
}
66+
catch (Exception ex)
67+
{
68+
analyser.Logger.LogError($"Failed to create base metadata file: {ex.Message}");
69+
}
70+
}
5671
});
5772
}
5873
finally

csharp/extractor/Semmle.Util/EnvironmentVariables.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,14 @@ public static IEnumerable<string> GetURLs(string name)
6767
{
6868
return Environment.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_OVERLAY_CHANGES");
6969
}
70+
71+
/// <summary>
72+
/// If the environment variable is set, the extractor is being called to extract a base database.
73+
/// Its value will be a path, and the extractor must create either a file or directory at that location.
74+
/// </summary>
75+
public static string? GetBaseMetaDataOutPath()
76+
{
77+
return Environment.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_OVERLAY_BASE_METADATA_OUT");
78+
}
7079
}
7180
}

0 commit comments

Comments
 (0)