Skip to content

Commit

Permalink
fix(internal): make sure formatting is run on snippets (#4039)
Browse files Browse the repository at this point in the history
Fixes: #4037
  • Loading branch information
codyoss committed May 3, 2021
1 parent d089dda commit 130dfc5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
36 changes: 22 additions & 14 deletions internal/gapicgen/generator/gapics.go
Expand Up @@ -30,23 +30,25 @@ import (

// GapicGenerator is used to regenerate gapic libraries.
type GapicGenerator struct {
googleapisDir string
protoDir string
googleCloudDir string
genprotoDir string
gapicToGenerate string
regenOnly bool
googleapisDir string
protoDir string
googleCloudDir string
genprotoDir string
gapicToGenerate string
regenOnly bool
onlyGenerateGapic bool
}

// NewGapicGenerator creates a GapicGenerator.
func NewGapicGenerator(googleapisDir, protoDir, googleCloudDir, genprotoDir string, gapicToGenerate string, regenOnly bool) *GapicGenerator {
func NewGapicGenerator(c *Config) *GapicGenerator {
return &GapicGenerator{
googleapisDir: googleapisDir,
protoDir: protoDir,
googleCloudDir: googleCloudDir,
genprotoDir: genprotoDir,
gapicToGenerate: gapicToGenerate,
regenOnly: regenOnly,
googleapisDir: c.GoogleapisDir,
protoDir: c.ProtoDir,
googleCloudDir: c.GapicDir,
genprotoDir: c.GenprotoDir,
gapicToGenerate: c.GapicToGenerate,
regenOnly: c.RegenOnly,
onlyGenerateGapic: c.OnlyGenerateGapic,
}
}

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

if !g.onlyGenerateGapic {
if err := g.regenSnippets(ctx); err != nil {
return err
}
}

if err := execv.ForEachMod(g.googleCloudDir, g.addModReplaceGenproto); err != nil {
return err
}
Expand All @@ -102,7 +110,7 @@ func (g *GapicGenerator) Regen(ctx context.Context) error {
}

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

snippetDir := filepath.Join(g.googleCloudDir, "internal", "generated", "snippets")
Expand Down
9 changes: 2 additions & 7 deletions internal/gapicgen/generator/generator.go
Expand Up @@ -44,20 +44,15 @@ type Config struct {
// Generate generates genproto and gapics.
func Generate(ctx context.Context, conf *Config) ([]*git.ChangeInfo, error) {
if !conf.OnlyGenerateGapic {
protoGenerator := NewGenprotoGenerator(conf.GenprotoDir, conf.GoogleapisDir, conf.ProtoDir)
protoGenerator := NewGenprotoGenerator(conf)
if err := protoGenerator.Regen(ctx); err != nil {
return nil, fmt.Errorf("error generating genproto (may need to check logs for more errors): %v", err)
}
}
gapicGenerator := NewGapicGenerator(conf.GoogleapisDir, conf.ProtoDir, conf.GapicDir, conf.GenprotoDir, conf.GapicToGenerate, conf.RegenOnly)
gapicGenerator := NewGapicGenerator(conf)
if err := gapicGenerator.Regen(ctx); err != nil {
return nil, fmt.Errorf("error generating gapics (may need to check logs for more errors): %v", err)
}
if !conf.OnlyGenerateGapic {
if err := gapicGenerator.RegenSnippets(ctx); err != nil {
return nil, fmt.Errorf("error generating snippets (may need to check logs for more errors): %v", err)
}
}

var changes []*git.ChangeInfo
if !conf.LocalMode {
Expand Down
8 changes: 4 additions & 4 deletions internal/gapicgen/generator/genproto.go
Expand Up @@ -51,11 +51,11 @@ type GenprotoGenerator struct {
}

// NewGenprotoGenerator creates a new GenprotoGenerator.
func NewGenprotoGenerator(genprotoDir, googleapisDir, protoDir string) *GenprotoGenerator {
func NewGenprotoGenerator(c *Config) *GenprotoGenerator {
return &GenprotoGenerator{
genprotoDir: genprotoDir,
googleapisDir: googleapisDir,
protoSrcDir: filepath.Join(protoDir, "/src"),
genprotoDir: c.GenprotoDir,
googleapisDir: c.GoogleapisDir,
protoSrcDir: filepath.Join(c.ProtoDir, "/src"),
}
}

Expand Down

0 comments on commit 130dfc5

Please sign in to comment.