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

chore(internal/gapicgen): gen googleapis-discovery compute gapic #4307

Merged
merged 5 commits into from Jun 29, 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
18 changes: 18 additions & 0 deletions internal/gapicgen/generator/config.go
Expand Up @@ -46,10 +46,28 @@ type microgenConfig struct {
// disableMetadata is used to toggle generation of the gapic_metadata.json
// file for the client library.
disableMetadata bool

// transports is a list of transports to generate a client for. Acceptable
// values are 'grpc' and 'rest'
transports []string

// googleapisDiscovery indicates if the protos reside in googleapis-discovery
// or not. Default is false, and will be looked up in googleapis.
googleapisDiscovery bool
}

var microgenGapicConfigs = []*microgenConfig{
// Cloud APIs
{
inputDirectoryPath: "google/cloud/compute/v1",
pkg: "compute",
importPath: "cloud.google.com/go/compute/apiv1",
apiServiceConfigPath: "google/cloud/compute/v1/compute_v1.yaml",
transports: []string{"rest"},
// TODO(dovs): Change to "ga" when ready.
releaseLevel: "alpha",
googleapisDiscovery: true,
},
{
inputDirectoryPath: "google/cloud/texttospeech/v1",
pkg: "texttospeech",
Expand Down
51 changes: 32 additions & 19 deletions internal/gapicgen/generator/gapics.go
Expand Up @@ -32,27 +32,29 @@ import (

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

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

Expand Down Expand Up @@ -267,13 +269,20 @@ find . -name '*.backup' -delete
// microgen runs the microgenerator on a single microgen config.
func (g *GapicGenerator) microgen(conf *microgenConfig) error {
log.Println("microgen generating", conf.pkg)
dir := g.googleapisDir
if conf.googleapisDiscovery {
dir = g.googleapisDiscoDir
}

var protoFiles []string
if err := filepath.Walk(g.googleapisDir+"/"+conf.inputDirectoryPath, func(path string, info os.FileInfo, err error) error {
if err := filepath.Walk(dir+"/"+conf.inputDirectoryPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if strings.Contains(info.Name(), ".proto") {
// Ignore compute_small.proto which is just for testing and would cause a collision if used in generation.
//
// TODO(noahdietz): Remove this when it is no longer needed.
if strings.Contains(info.Name(), ".proto") && !strings.Contains(info.Name(), "compute_small.proto") {
protoFiles = append(protoFiles, path)
}
return nil
Expand All @@ -282,6 +291,7 @@ func (g *GapicGenerator) microgen(conf *microgenConfig) error {
}

args := []string{"-I", g.googleapisDir,
"-I", g.googleapisDiscoDir,
"--experimental_allow_proto3_optional",
"-I", g.protoDir,
"--go_gapic_out", g.googleCloudDir,
Expand All @@ -297,9 +307,12 @@ func (g *GapicGenerator) microgen(conf *microgenConfig) error {
if !conf.disableMetadata {
args = append(args, "--go_gapic_opt", "metadata")
}
if len(conf.transports) > 0 {
args = append(args, "--go_gapic_opt", fmt.Sprintf("transport=%s", strings.Join(conf.transports, "+")))
}
args = append(args, protoFiles...)
c := execv.Command("protoc", args...)
c.Dir = g.googleapisDir
c.Dir = dir
return c.Run()
}

Expand Down