-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathResxGenerator.cs
More file actions
65 lines (57 loc) · 2.52 KB
/
Copy pathResxGenerator.cs
File metadata and controls
65 lines (57 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using Semmle.Util;
using Semmle.Util.Logging;
namespace Semmle.Extraction.CSharp.DependencyFetching
{
internal class ResxGenerator : DotnetSourceGeneratorBase<Resx>
{
private readonly string? sourceGeneratorFolder = null;
public ResxGenerator(
FileProvider fileProvider,
FileContent fileContent,
IDotNet dotnet,
ICompilationInfoContainer compilationInfoContainer,
ILogger logger,
NugetPackageRestorer nugetPackageRestorer,
TemporaryDirectory tempWorkingDirectory,
IEnumerable<string> references) : base(fileProvider, fileContent, dotnet, compilationInfoContainer, logger, tempWorkingDirectory, references)
{
if (fileProvider.Resources.Count == 0)
{
logger.LogDebug("No resources found, skipping resource extraction.");
sourceGeneratorFolder = null;
return;
}
try
{
// The package is downloaded to `missingpackages`, which is okay, we're already after the DLL collection phase.
var nugetFolder = nugetPackageRestorer.TryRestore("Microsoft.CodeAnalysis.ResxSourceGenerator");
if (nugetFolder is not null)
{
sourceGeneratorFolder = System.IO.Path.Combine(nugetFolder, "analyzers", "dotnet", "cs");
}
}
catch (Exception e)
{
logger.LogWarning($"Failed to download source generator: {e.Message}");
sourceGeneratorFolder = null;
}
}
protected override bool IsEnabled()
{
var resourceExtractionOption = Environment.GetEnvironmentVariable(EnvironmentVariableNames.ResourceGeneration);
if (bool.TryParse(resourceExtractionOption, out var shouldExtractResources) &&
shouldExtractResources)
{
compilationInfoContainer.CompilationInfos.Add(("Resource extraction enabled", "1"));
return true;
}
compilationInfoContainer.CompilationInfos.Add(("Resource extraction enabled", "0"));
return false;
}
protected override ICollection<string> AdditionalFiles => fileProvider.Resources;
protected override string FileType => "Resx";
protected override Resx GetSourceGenerator(Sdk sdk) => new Resx(sdk, dotnet, logger, sourceGeneratorFolder);
}
}