Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for issue 8 hanging on CDATA. #3246

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions generator/ServiceClientGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ static int Main(string[] args)

if (string.IsNullOrEmpty(options.SelfServiceModel))
{
ConcurrentDictionary<string, string> generatedFiles = new ConcurrentDictionary<string, string>();
ConcurrentDictionary<string, byte> generatedFiles = new ConcurrentDictionary<string, byte>();
ConcurrentDictionary<string, byte> generatedUnitTestFiles = new ConcurrentDictionary<string, byte>();

GeneratorDriver.GenerateCoreProjects(generationManifest, options);
GeneratorDriver.GeneratePartitions(options);
Console.WriteLine($"Setting MaxDegreeOfParallelism = {Environment.ProcessorCount * 2}");
Expand All @@ -61,15 +63,20 @@ static int Main(string[] args)
driver.Execute();
foreach (var file in driver.FilesWrittenToGeneratorFolder)
{
generatedFiles.TryAdd(file, file);
generatedFiles.TryAdd(file, 0);
}
GeneratorDriver.UpdateUnitTestProjects(generationManifest, options, driver.ServiceUnitTestFilesRoot, serviceConfig);
var generatedTestFiles = GeneratorDriver.UpdateUnitTestProjects(generationManifest, options, driver.ServiceUnitTestFilesRoot, serviceConfig);
foreach (var file in generatedTestFiles)
{
generatedUnitTestFiles.TryAdd(file, 0);
}
});

var files = new HashSet<string>(generatedFiles.Values);
var files = new HashSet<string>(generatedFiles.Keys);
var testFiles = new HashSet<string>(generatedUnitTestFiles.Keys);

if (!options.SkipRemoveOrphanCleanup)
GeneratorDriver.RemoveOrphanedShapesAndServices(files, options.SdkRootFolder);
GeneratorDriver.RemoveOrphanedShapesAndServices(files, testFiles, options.SdkRootFolder);

GeneratorDriver.UpdateUnitTestProjects(generationManifest, options);
GeneratorDriver.UpdateSolutionFiles(generationManifest, options);
Expand Down Expand Up @@ -106,7 +113,7 @@ static int Main(string[] args)
// Skip orphan clean for DynamoDB because of the complex nature of DynamoDB and DynamoDB Streams
if (!serviceConfig.ClassName.StartsWith("DynamoDB") && !options.SkipRemoveOrphanCleanup)
{
GeneratorDriver.RemoveOrphanedShapes(driver.FilesWrittenToGeneratorFolder, driver.GeneratedFilesRoot);
GeneratorDriver.RemoveOrphanedShapes(driver.FilesWrittenToGeneratorFolder, null, driver.GeneratedFilesRoot);
}
}
}
Expand Down
32 changes: 25 additions & 7 deletions generator/ServiceClientGeneratorLib/GeneratorDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -830,13 +830,24 @@ public static void UpdateUnitTestProjects(GenerationManifest generationManifest,
/// <summary>
/// Adding Method to create/update service specific unit test projects
/// </summary>
public static void UpdateUnitTestProjects(GenerationManifest generationManifest, GeneratorOptions options, string serviceTestFilesRoot, ServiceConfiguration serviceConfiguration)
public static List<string> UpdateUnitTestProjects(GenerationManifest generationManifest, GeneratorOptions options, string serviceTestFilesRoot, ServiceConfiguration serviceConfiguration)
{
Console.WriteLine("Updating unit test project files.");
string unitTestRoot = Utils.PathCombineAlt(serviceTestFilesRoot, "UnitTests");
var creator = new UnitTestProjectFileCreator(options, generationManifest.UnitTestProjectFileConfigurations, serviceConfiguration.ServiceFolderName);

UpdateUnitTestProjects(new[] { serviceConfiguration }, options, unitTestRoot, creator);

List<string> generatedTestFiles = new List<string>();
foreach (var file in Directory.GetFiles(unitTestRoot, "*.cs", SearchOption.AllDirectories).OrderBy(f => f))
{
var fullPath = Utils.ConvertPathAlt(Path.GetFullPath(file));
if (fullPath.IndexOf($"/{GeneratedCodeFoldername}/", StringComparison.OrdinalIgnoreCase) < 0)
continue;
generatedTestFiles.Add(fullPath);
}

return generatedTestFiles;
}

private static void UpdateUnitTestProjects(IEnumerable<ServiceConfiguration> serviceConfigurations, GeneratorOptions options, string unitTestRoot, UnitTestProjectFileCreator creator)
Expand Down Expand Up @@ -1425,19 +1436,26 @@ void GenerateCodeAnalysisProject()
command.Execute(CodeAnalysisRoot, this.Configuration);
}

public static void RemoveOrphanedShapesAndServices(HashSet<string> generatedFiles, string sdkRootFolder)
public static void RemoveOrphanedShapesAndServices(HashSet<string> generatedFiles, HashSet<string> generatedTestFolders, string sdkRootFolder)
{
var codeGeneratedServiceList = codeGeneratedServiceNames.Distinct();

// Cleanup services within the main sdk/services folder
var srcFolder = Utils.PathCombineAlt(sdkRootFolder, SourceSubFoldername, ServicesSubFoldername);
RemoveOrphanedShapes(generatedFiles, srcFolder);
RemoveOrphanedShapes(generatedFiles, null, srcFolder);

// Cleanup services within the sdk/test folder where it is a generated test service
var testSrcFolder = Utils.PathCombineAlt(sdkRootFolder, TestsSubFoldername, ServicesSubFoldername);
RemoveOrphanedShapes(generatedFiles, generatedTestFolders, testSrcFolder);

// Cleanup orphaned Service src artifacts. This is encountered when the service identifier is modified.
RemoveOrphanedServices(srcFolder, codeGeneratedServiceList);
// Cleanup orphaned Service test artifacts. This is encountered when the service identifier is modified.
RemoveOrphanedServices(Utils.PathCombineAlt(sdkRootFolder, TestsSubFoldername, ServicesSubFoldername), codeGeneratedServiceList);
RemoveOrphanedServices(testSrcFolder, codeGeneratedServiceList);
// Cleanup orphaned Service code analysis artifacts. This is encountered when the service identifier is modified.
RemoveOrphanedServices(Utils.PathCombineAlt(sdkRootFolder, CodeAnalysisFoldername, ServicesAnalysisSubFolderName), codeGeneratedServiceList);
}
public static void RemoveOrphanedShapes(HashSet<string> generatedFiles, string srcFolder)
public static void RemoveOrphanedShapes(HashSet<string> generatedFiles, HashSet<string> generatedTestFolders, string srcFolder)
{
// Remove orphaned shapes. Most likely due to taking in a model that was still under development.
foreach (var file in Directory.GetFiles(srcFolder, "*.cs", SearchOption.AllDirectories).OrderBy(f => f))
Expand All @@ -1446,7 +1464,7 @@ public static void RemoveOrphanedShapes(HashSet<string> generatedFiles, string s
if (fullPath.IndexOf($"/{GeneratedCodeFoldername}/", StringComparison.OrdinalIgnoreCase) < 0)
continue;

if (!generatedFiles.Contains(fullPath))
if (!generatedFiles.Contains(fullPath) && generatedTestFolders?.Contains(fullPath) == false)
{
Console.Error.WriteLine("**** Warning: Removing orphaned generated code " + Path.GetFileName(file));
File.Delete(file);
Expand Down
Loading