Description
The current Go tag parser supports only final releases, not betas and not RCs. It would become more useful if it supported all release types. There are some places in x/build where we've wanted to use it, but couldn't do so because of this limitation.
Historically, we've worked around not having a parser by using string manipulation to analyze and modify Go versions, but that can be error prone and won't detect all problems a complete parser would. It's hard to compare or manipulate versions (e.g., get a previous minor release).
Examples
if strings.HasPrefix(goVer, "go1.13") || strings.HasPrefix(goVer, "go1.14") {
// ...
}
func nextVersion(version string) (string, error) {
parts := strings.Split(version, ".")
n, err := strconv.Atoi(parts[len(parts)-1])
if err != nil {
return "", err
}
parts[len(parts)-1] = strconv.Itoa(n + 1)
return strings.Join(parts, "."), nil
}
if strings.Contains(release, "beta") {
// ...
} else if strings.Contains(release, "rc") {
// ...
} else if strings.Count(w.Version, ".") == 1 {
// ...
} else if strings.Count(w.Version, ".") == 2 {
// ...
}
Additionally, the ParseTag
function currently makes allocations, which can be avoided. That would be nice to make it less expensive to use in various loops in the build infrastructure.
CL 245277 implements this.
In the future, if more places in x/build start using this, we may consider moving it to a shorter import path. It doesn't have to happen right away.