Skip to content

Commit 130dfc5

Browse files
authored
fix(internal): make sure formatting is run on snippets (#4039)
Fixes: #4037
1 parent d089dda commit 130dfc5

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

internal/gapicgen/generator/gapics.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ import (
3030

3131
// GapicGenerator is used to regenerate gapic libraries.
3232
type GapicGenerator struct {
33-
googleapisDir string
34-
protoDir string
35-
googleCloudDir string
36-
genprotoDir string
37-
gapicToGenerate string
38-
regenOnly bool
33+
googleapisDir string
34+
protoDir string
35+
googleCloudDir string
36+
genprotoDir string
37+
gapicToGenerate string
38+
regenOnly bool
39+
onlyGenerateGapic bool
3940
}
4041

4142
// NewGapicGenerator creates a GapicGenerator.
42-
func NewGapicGenerator(googleapisDir, protoDir, googleCloudDir, genprotoDir string, gapicToGenerate string, regenOnly bool) *GapicGenerator {
43+
func NewGapicGenerator(c *Config) *GapicGenerator {
4344
return &GapicGenerator{
44-
googleapisDir: googleapisDir,
45-
protoDir: protoDir,
46-
googleCloudDir: googleCloudDir,
47-
genprotoDir: genprotoDir,
48-
gapicToGenerate: gapicToGenerate,
49-
regenOnly: regenOnly,
45+
googleapisDir: c.GoogleapisDir,
46+
protoDir: c.ProtoDir,
47+
googleCloudDir: c.GapicDir,
48+
genprotoDir: c.GenprotoDir,
49+
gapicToGenerate: c.GapicToGenerate,
50+
regenOnly: c.RegenOnly,
51+
onlyGenerateGapic: c.OnlyGenerateGapic,
5052
}
5153
}
5254

@@ -82,6 +84,12 @@ func (g *GapicGenerator) Regen(ctx context.Context) error {
8284
return err
8385
}
8486

87+
if !g.onlyGenerateGapic {
88+
if err := g.regenSnippets(ctx); err != nil {
89+
return err
90+
}
91+
}
92+
8593
if err := execv.ForEachMod(g.googleCloudDir, g.addModReplaceGenproto); err != nil {
8694
return err
8795
}
@@ -102,7 +110,7 @@ func (g *GapicGenerator) Regen(ctx context.Context) error {
102110
}
103111

104112
// RegenSnippets regenerates the snippets for all GAPICs configured to be generated.
105-
func (g *GapicGenerator) RegenSnippets(ctx context.Context) error {
113+
func (g *GapicGenerator) regenSnippets(ctx context.Context) error {
106114
log.Println("regenerating snippets")
107115

108116
snippetDir := filepath.Join(g.googleCloudDir, "internal", "generated", "snippets")

internal/gapicgen/generator/generator.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,15 @@ type Config struct {
4444
// Generate generates genproto and gapics.
4545
func Generate(ctx context.Context, conf *Config) ([]*git.ChangeInfo, error) {
4646
if !conf.OnlyGenerateGapic {
47-
protoGenerator := NewGenprotoGenerator(conf.GenprotoDir, conf.GoogleapisDir, conf.ProtoDir)
47+
protoGenerator := NewGenprotoGenerator(conf)
4848
if err := protoGenerator.Regen(ctx); err != nil {
4949
return nil, fmt.Errorf("error generating genproto (may need to check logs for more errors): %v", err)
5050
}
5151
}
52-
gapicGenerator := NewGapicGenerator(conf.GoogleapisDir, conf.ProtoDir, conf.GapicDir, conf.GenprotoDir, conf.GapicToGenerate, conf.RegenOnly)
52+
gapicGenerator := NewGapicGenerator(conf)
5353
if err := gapicGenerator.Regen(ctx); err != nil {
5454
return nil, fmt.Errorf("error generating gapics (may need to check logs for more errors): %v", err)
5555
}
56-
if !conf.OnlyGenerateGapic {
57-
if err := gapicGenerator.RegenSnippets(ctx); err != nil {
58-
return nil, fmt.Errorf("error generating snippets (may need to check logs for more errors): %v", err)
59-
}
60-
}
6156

6257
var changes []*git.ChangeInfo
6358
if !conf.LocalMode {

internal/gapicgen/generator/genproto.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ type GenprotoGenerator struct {
5151
}
5252

5353
// NewGenprotoGenerator creates a new GenprotoGenerator.
54-
func NewGenprotoGenerator(genprotoDir, googleapisDir, protoDir string) *GenprotoGenerator {
54+
func NewGenprotoGenerator(c *Config) *GenprotoGenerator {
5555
return &GenprotoGenerator{
56-
genprotoDir: genprotoDir,
57-
googleapisDir: googleapisDir,
58-
protoSrcDir: filepath.Join(protoDir, "/src"),
56+
genprotoDir: c.GenprotoDir,
57+
googleapisDir: c.GoogleapisDir,
58+
protoSrcDir: filepath.Join(c.ProtoDir, "/src"),
5959
}
6060
}
6161

0 commit comments

Comments
 (0)