Skip to content

Commit

Permalink
chore(internal/gapicgen): generate compute gapic
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz committed Jun 23, 2021
1 parent 773ea23 commit 2ee6006
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
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

0 comments on commit 2ee6006

Please sign in to comment.