From 8b0b461b07fa8a4b5550729eb87ab1ba566d2fd2 Mon Sep 17 00:00:00 2001 From: Steve Otteson Date: Tue, 16 Mar 2021 10:03:04 -0700 Subject: [PATCH] Make sure enum type names can't be the same constant names (build will fail). Resolve an existing conflict that made us realize we had a problem. Fixes #361 --- generation/scraper/manualEnums.json | 20 ++++++++++++++++++- sources/ConstantsScraper/Program.cs | 10 +++++++++- sources/PartitionUtilsLib/ConstantsScraper.cs | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/generation/scraper/manualEnums.json b/generation/scraper/manualEnums.json index 0c9ba4135..ad481b619 100644 --- a/generation/scraper/manualEnums.json +++ b/generation/scraper/manualEnums.json @@ -1596,5 +1596,23 @@ "field": "dwDialMode" } ] + }, + { + "name": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION_VALUE", + "flags": false, + "members": [ + { + "name": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION_1", + "value": 1 + }, + { + "name": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION_2", + "value": 2 + }, + { + "name": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION", + "value": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION_2" + } + ] } -] + ] diff --git a/sources/ConstantsScraper/Program.cs b/sources/ConstantsScraper/Program.cs index 52e52f5b1..ef491201b 100644 --- a/sources/ConstantsScraper/Program.cs +++ b/sources/ConstantsScraper/Program.cs @@ -82,7 +82,15 @@ public static int Run(InvocationContext context) var renames = ConvertValuePairsToDictionary(renamedNameValuePairs); var withTypes = ConvertValuePairsToDictionary(withTypeValuePairs); - PartitionUtilsLib.ConstantsScraper.ScrapeConstants(repoRoot, enumJsonFiles, exclusionNamesToPartitions, requiredNamespaces, remaps, withTypes, renames); + try + { + PartitionUtilsLib.ConstantsScraper.ScrapeConstants(repoRoot, enumJsonFiles, exclusionNamesToPartitions, requiredNamespaces, remaps, withTypes, renames); + } + catch (System.Exception e) + { + context.Console.Out.Write($"Failed to scrape constants:\r\n{e.Message}\r\n"); + return -1; + } return 0; } diff --git a/sources/PartitionUtilsLib/ConstantsScraper.cs b/sources/PartitionUtilsLib/ConstantsScraper.cs index 729cb9706..6f9259a6e 100644 --- a/sources/PartitionUtilsLib/ConstantsScraper.cs +++ b/sources/PartitionUtilsLib/ConstantsScraper.cs @@ -743,6 +743,11 @@ private void WriteEnumsAndRemaps( if (obj == objectForRemap) { + if (this.writtenConstants.ContainsKey(obj.name)) + { + throw new InvalidOperationException($"Tried to add enum {obj.name} but a constant with the same name already exists."); + } + addedEnum = enumWriter.AddEnum(obj); } }