Skip to content

Commit 9635a36

Browse files
authored
refactor(internal/librarian): inline postGenerate into generateLibraries (#4729)
The postGenerate function was a separate dispatch step that ran repo-level actions after all libraries were generated. This inlines each language's post-generate call into its own case block within generateLibraries, eliminating the extra function and switch statement.
1 parent 84b2ec3 commit 9635a36

1 file changed

Lines changed: 4 additions & 19 deletions

File tree

internal/librarian/generate.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ func runGenerate(ctx context.Context, cfg *config.Config, all bool, libraryName
102102
if err := cleanLibraries(cfg.Language, libraries); err != nil {
103103
return err
104104
}
105-
if err := generateLibraries(ctx, cfg, libraries, sources); err != nil {
106-
return err
107-
}
108-
return postGenerate(ctx, cfg.Language, cfg)
105+
return generateLibraries(ctx, cfg, libraries, sources)
109106
}
110107

111108
// cleanLibraries iterates over all the given libraries sequentially,
@@ -170,6 +167,7 @@ func generateLibraries(ctx context.Context, cfg *config.Config, libraries []*con
170167
return fmt.Errorf("format library %q (%s): %w", library.Name, cfg.Language, err)
171168
}
172169
}
170+
return fakePostGenerate()
173171
case config.LanguageGo:
174172
for _, library := range libraries {
175173
// Generation cannot be parallelized because protoc writes to a
@@ -198,6 +196,7 @@ func generateLibraries(ctx context.Context, cfg *config.Config, libraries []*con
198196
return fmt.Errorf("format library %q (%s): %w", library.Name, cfg.Language, err)
199197
}
200198
}
199+
return java.PostGenerate(ctx, ".", cfg)
201200
case config.LanguageNodejs:
202201
g, gctx := errgroup.WithContext(ctx)
203202
for _, library := range libraries {
@@ -240,27 +239,13 @@ func generateLibraries(ctx context.Context, cfg *config.Config, libraries []*con
240239
return fmt.Errorf("format library %q (%s): %w", library.Name, cfg.Language, err)
241240
}
242241
}
242+
return rust.UpdateWorkspace(ctx)
243243
default:
244244
return fmt.Errorf("language %q does not support generation", cfg.Language)
245245
}
246246
return nil
247247
}
248248

249-
// postGenerate performs repository-level actions after all individual
250-
// libraries have been generated.
251-
func postGenerate(ctx context.Context, language string, cfg *config.Config) error {
252-
switch language {
253-
case config.LanguageFake:
254-
return fakePostGenerate()
255-
case config.LanguageJava:
256-
return java.PostGenerate(ctx, ".", cfg)
257-
case config.LanguageRust:
258-
return rust.UpdateWorkspace(ctx)
259-
default:
260-
return nil
261-
}
262-
}
263-
264249
func defaultOutput(language string, name, api, defaultOut string) string {
265250
switch language {
266251
case config.LanguageDart:

0 commit comments

Comments
 (0)