Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internal): make sure formatting is run on snippets #4039

Merged
merged 2 commits into from May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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