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/gapicgen): add generation of internal/version.go for new client modules #5726

Merged
merged 1 commit into from Mar 4, 2022
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
20 changes: 20 additions & 0 deletions internal/gapicgen/generator/_internal_version.go.txt
@@ -0,0 +1,20 @@
// Copyright {{.Year}} Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Code generated by gapicgen. DO NOT EDIT.

package internal

// Version is the current tagged release of the library.
const Version = "0.1.0"
30 changes: 26 additions & 4 deletions internal/gapicgen/generator/gapics.go
Expand Up @@ -40,6 +40,8 @@ var (
readmeTmpl string
//go:embed _version.go.txt
versionTmpl string
//go:embed _internal_version.go.txt
internalVersionTmpl string
)

// GapicGenerator is used to regenerate gapic libraries.
Expand Down Expand Up @@ -102,14 +104,14 @@ func (g *GapicGenerator) Regen(ctx context.Context) error {
if err := g.microgen(c); err != nil {
return err
}
if err := g.genVersionFile(c); err != nil {
return err
}
if g.genModule {
if err := gocmd.ModTidy(modPath); err != nil {
return nil
}
}
if err := g.genVersionFile(c); err != nil {
return err
}
}

if err := g.copyMicrogenFiles(); err != nil {
Expand Down Expand Up @@ -326,7 +328,7 @@ func (g *GapicGenerator) genVersionFile(conf *microgenConfig) error {
rootPackage := strings.Split(relDir, "/")[0]
rootModInternal := fmt.Sprintf("cloud.google.com/go/%s/internal", rootPackage)

f, err := os.Create(filepath.Join(g.googleCloudDir, relDir, "version.go"))
f, err := os.Create(filepath.Join(g.googleCloudDir, conf.importPath, "version.go"))
if err != nil {
return err
}
Expand All @@ -345,6 +347,26 @@ func (g *GapicGenerator) genVersionFile(conf *microgenConfig) error {
if err := t.Execute(f, versionData); err != nil {
return err
}

if g.genModule {
os.MkdirAll(filepath.Join(g.googleCloudDir, rootModInternal), os.ModePerm)

f2, err := os.Create(filepath.Join(g.googleCloudDir, rootModInternal, "version.go"))
if err != nil {
return err
}
defer f2.Close()

t2 := template.Must(template.New("internal_version").Parse(internalVersionTmpl))
internalVersionData := struct {
Year int
}{
Year: time.Now().Year(),
}
if err := t2.Execute(f2, internalVersionData); err != nil {
return err
}
}
return nil
}

Expand Down