Fix release tags generation.

PiperOrigin-RevId: 424151576
This commit is contained in:
Adin Scannell
2022-01-25 12:35:46 -08:00
committed by gVisor bot
parent 434e58d261
commit b92bb28e6a
2 changed files with 3 additions and 38 deletions
+3 -2
View File
@@ -16,6 +16,7 @@ package check
import (
"fmt"
"go/build"
"io"
"os"
@@ -39,7 +40,7 @@ var findStdPkg = func(path string) (io.ReadCloser, error) {
return os.Open(fmt.Sprintf("%s/pkg/%s_%s/%s.a", root, flags.GOOS, flags.GOARCH, path))
}
// releaseTags returns nil, indicating that the defaults should be used.
// releaseTags returns the default release tags.
var releaseTags = func() ([]string, error) {
return nil, nil
return build.Default.ReleaseTags, nil
}
-36
View File
@@ -33,8 +33,6 @@ import (
"path/filepath"
"reflect"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
@@ -69,46 +67,12 @@ var (
releaseTagsErr error
)
// versionTags generates all version tags.
//
// This function will panic if passed an invalid version.
func versionTags(v string) (tags []string) {
if len(v) < 2 || string(v[:2]) != "go" {
panic(fmt.Errorf("version %q is not valid", v))
}
v = v[2:] // Strip go prefix.
v = strings.Split(v, " ")[0]
v = strings.Split(v, "-")[0]
parts := strings.Split(v, ".")
if len(parts) < 2 {
panic(fmt.Errorf("version %q lacks major and minor number", v))
}
major, err := strconv.ParseInt(parts[0], 10, 64)
if err != nil {
panic(fmt.Errorf("version %q contains invalid major: %w", v, err))
}
minor, err := strconv.ParseInt(parts[1], 10, 64)
if err != nil {
panic(fmt.Errorf("version %q contains invalid minor: %w", v, err))
}
// Generate all compliant tags.
for i := int64(0); i <= minor; i++ {
tags = append(tags, fmt.Sprintf("go%d.%d", major, i))
}
return tags
}
// shouldInclude indicates whether the file should be included.
func shouldInclude(path string) (bool, error) {
tagsOnce.Do(func() {
if len(flags.BuildTags) > 0 {
buildTags = strings.Split(flags.BuildTags, ",")
}
if v, err := flags.Env("GOVERSION"); err == nil {
buildTags = append(buildTags, versionTags(v)...)
} else {
buildTags = append(buildTags, versionTags(runtime.Version())...)
}
releaseTagsVal, releaseTagsErr = releaseTags()
})
if releaseTagsErr != nil {