Skip to content

Commit

Permalink
fix: prevent duplicate fragment gen (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz committed Nov 3, 2023
1 parent 307491e commit b25acf0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace Google\Generator;

use Google\Generator\Collections\Map;
use Google\Generator\Collections\Set;
use Google\Generator\Collections\Vector;
use Google\Generator\Generation\SnippetGenerator;
use Google\Generator\Generation\BuildMethodFragmentGenerator;
Expand Down Expand Up @@ -281,6 +282,7 @@ private static function generateServices(
bool $generateSnippets = true
) {
$versionToNamespace = [];
$fragmentsGenerated = Set::new();
foreach ($servicesToGenerate as $service) {
$migrationMode = $service->migrationMode;

Expand Down Expand Up @@ -361,9 +363,13 @@ private static function generateServices(
$ctx = new SourceFileContext($service->gapicClientType->getNamespace(), $licenseYear);
$buildMethodFragments = BuildMethodFragmentGenerator::generate($ctx, $service);
foreach ($buildMethodFragments as [$fragmentName, $buildMethodFragment]) {
if ($fragmentsGenerated[$fragmentName]) {
continue;
}
$buildMethodFragmentCode = BuildMethodFragmentGenerator::format(
$buildMethodFragment->reduce('', fn ($v, $i) => $v . $i->toCode())
);
$fragmentsGenerated = $fragmentsGenerated->add($fragmentName);
yield ["fragments/{$fragmentName}.build.txt", $buildMethodFragmentCode];
}
}
Expand Down

0 comments on commit b25acf0

Please sign in to comment.