Skip to content
Permalink
Browse files
fix(internal): make sure formatting is run on snippets (#4039)
Fixes: #4037
  • Loading branch information
codyoss committed May 3, 2021
1 parent d089dda commit 130dfc535396e98fc009585b0457e3bc48ead941
Showing with 28 additions and 25 deletions.
  1. +22 −14 internal/gapicgen/generator/gapics.go
  2. +2 −7 internal/gapicgen/generator/generator.go
  3. +4 −4 internal/gapicgen/generator/genproto.go
@@ -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,
}
}

@@ -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
}
@@ -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")
@@ -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 {
@@ -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"),
}
}

0 comments on commit 130dfc5

Please sign in to comment.