Skip to content

Commit

Permalink
chore: ensure the Analyzer picks up additional prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Dec 20, 2024
1 parent aa376e8 commit 027ded5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,12 @@ private CodeGenHelpers.ValueType GetValueType(string value, PropertyType propert
}
}

private IDictionary<string, string> GetEnvironmentSettings()
{
var buildToolsEnvFile = GeneratorContext.AdditionalFiles.FirstOrDefault(x => Path.GetFileName(x.Path) == Constants.BuildToolsEnvironmentSettings);
if (buildToolsEnvFile is null)
return new Dictionary<string, string>();

var json = buildToolsEnvFile.GetText().ToString();
if (string.IsNullOrEmpty(json))
return new Dictionary<string, string>();

return JsonSerializer.Deserialize<BuildEnvironment>(json, new JsonSerializerOptions(JsonSerializerDefaults.General)).Environment;
}

internal IDictionary<string, string> GetMergedSecrets(SettingsConfig settingsConfig, out bool hasErrors)
{
if (string.IsNullOrEmpty(settingsConfig.Prefix))
settingsConfig.Prefix = "BuildTools_";

var env = GetEnvironmentSettings();
var env = Environment.Environment;
var secrets = new Dictionary<string, string>();
hasErrors = false;
foreach (var prop in settingsConfig.Properties)
Expand All @@ -230,11 +217,15 @@ internal IDictionary<string, string> GetMergedSecrets(SettingsConfig settingsCon

var searchKeys = new List<string>
{
prefixKey
$"{Environment.TargetPlatform}_{Environment.BuildConfiguration}_{prefixKey}",
$"{Environment.TargetPlatform}_{prefixKey}",
prefixKey,
};

if (settingsConfig.Prefix != _defaultPrefix)
{
searchKeys.Add($"{Environment.TargetPlatform}_{Environment.BuildConfiguration}_{_defaultPrefix}_{prefixKey}");
searchKeys.Add($"{Environment.TargetPlatform}_{_defaultPrefix}_{prefixKey}");
searchKeys.Add($"{_defaultPrefix}{prefixKey}");
}

Expand Down
6 changes: 6 additions & 0 deletions src/Mobile.BuildTools.AppSettings/Generators/GeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public abstract class GeneratorBase : ISourceGenerator

protected BuildToolsConfig Config { get; private set; }

protected BuildEnvironment Environment { get; private set; }

public void Execute(GeneratorExecutionContext context)
{
GeneratorContext = context;
Expand All @@ -39,6 +41,10 @@ public void Execute(GeneratorExecutionContext context)
var json = buildToolsConfig.GetText().ToString();
Config = JsonSerializer.Deserialize<BuildToolsConfig>(json, ConfigHelper.GetSerializerSettings());

var buildToolsEnvFile = GeneratorContext.AdditionalFiles.FirstOrDefault(x => Path.GetFileName(x.Path) == Constants.BuildToolsEnvironmentSettings);
json = buildToolsEnvFile.GetText().ToString();
Environment = JsonSerializer.Deserialize<BuildEnvironment>(json, new JsonSerializerOptions(JsonSerializerDefaults.General)) ?? new BuildEnvironment();

try
{
Generate();
Expand Down

0 comments on commit 027ded5

Please sign in to comment.