internal/version: move version information to internal package
Change-Id: I947876de5d290cf783d9ba798871725e77e16517
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/223277
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go
index 8905448..b582cbe 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -21,6 +21,7 @@
"google.golang.org/protobuf/internal/encoding/tag"
"google.golang.org/protobuf/internal/fieldnum"
"google.golang.org/protobuf/internal/genname"
+ "google.golang.org/protobuf/internal/version"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/runtime/protoimpl"
@@ -121,7 +122,7 @@
if GenerateVersionMarkers {
g.P("// versions:")
- protocGenGoVersion := protoimpl.VersionString()
+ protocGenGoVersion := version.String()
protocVersion := "(unknown)"
if v := gen.Request.GetCompilerVersion(); v != nil {
protocVersion = fmt.Sprintf("v%v.%v.%v", v.GetMajor(), v.GetMinor(), v.GetPatch())
diff --git a/cmd/protoc-gen-go/main.go b/cmd/protoc-gen-go/main.go
index 9ac544b..5f249be 100644
--- a/cmd/protoc-gen-go/main.go
+++ b/cmd/protoc-gen-go/main.go
@@ -18,12 +18,12 @@
gengo "google.golang.org/protobuf/cmd/protoc-gen-go/internal_gengo"
"google.golang.org/protobuf/compiler/protogen"
- "google.golang.org/protobuf/runtime/protoimpl"
+ "google.golang.org/protobuf/internal/version"
)
func main() {
if len(os.Args) == 2 && os.Args[1] == "--version" {
- fmt.Fprintf(os.Stderr, "%v %v\n", filepath.Base(os.Args[0]), protoimpl.VersionString())
+ fmt.Fprintf(os.Stderr, "%v %v\n", filepath.Base(os.Args[0]), version.String())
os.Exit(1)
}
diff --git a/integration_test.go b/integration_test.go
index e4444a4..2a9a470 100644
--- a/integration_test.go
+++ b/integration_test.go
@@ -25,7 +25,7 @@
"testing"
"time"
- "google.golang.org/protobuf/runtime/protoimpl"
+ "google.golang.org/protobuf/internal/version"
)
var (
@@ -321,7 +321,7 @@
}
if *buildRelease {
t.Run("BuildRelease", func(t *testing.T) {
- v := protoimpl.VersionString()
+ v := version.String()
for _, goos := range []string{"linux", "darwin", "windows"} {
for _, goarch := range []string{"386", "amd64"} {
binPath := filepath.Join("bin", fmt.Sprintf("protoc-gen-go.%v.%v.%v", v, goos, goarch))
diff --git a/internal/version/version.go b/internal/version/version.go
new file mode 100644
index 0000000..03f0aab
--- /dev/null
+++ b/internal/version/version.go
@@ -0,0 +1,79 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package version records versioning information about this module.
+package version
+
+import (
+ "fmt"
+ "strings"
+)
+
+// These constants determine the current version of this module.
+//
+//
+// For our release process, we enforce the following rules:
+// * Tagged releases use a tag that is identical to String.
+// * Tagged releases never reference a commit where the String
+// contains "devel".
+// * The set of all commits in this repository where String
+// does not contain "devel" must have a unique String.
+//
+//
+// Steps for tagging a new release:
+// 1. Create a new CL.
+//
+// 2. Update Minor, Patch, and/or PreRelease as necessary.
+// PreRelease must not contain the string "devel".
+//
+// 3. Since the last released minor version, have there been any changes to
+// generator that relies on new functionality in the runtime?
+// If yes, then increment RequiredGenerated.
+//
+// 4. Since the last released minor version, have there been any changes to
+// the runtime that removes support for old .pb.go source code?
+// If yes, then increment SupportMinimum.
+//
+// 5. Send out the CL for review and submit it.
+// Note that the next CL in step 8 must be submitted after this CL
+// without any other CLs in-between.
+//
+// 6. Tag a new version, where the tag is is the current String.
+//
+// 7. Write release notes for all notable changes
+// between this release and the last release.
+//
+// 8. Create a new CL.
+//
+// 9. Update PreRelease to include the string "devel".
+// For example: "" -> "devel" or "rc.1" -> "rc.1.devel"
+//
+// 10. Send out the CL for review and submit it.
+const (
+ Major = 1
+ Minor = 20
+ Patch = 1
+ PreRelease = "devel"
+)
+
+// String formats the version string for this module in semver format.
+//
+// Examples:
+// v1.20.1
+// v1.21.0-rc.1
+func String() string {
+ v := fmt.Sprintf("v%d.%d.%d", Major, Minor, Patch)
+ if PreRelease != "" {
+ v += "-" + PreRelease
+
+ // TODO: Add metadata about the commit or build hash.
+ // See https://golang.org/issue/29814
+ // See https://golang.org/issue/33533
+ var metadata string
+ if strings.Contains(PreRelease, "devel") && metadata != "" {
+ v += "+" + metadata
+ }
+ }
+ return v
+}
diff --git a/release.bash b/release.bash
index cc3d886..95049ed 100755
--- a/release.bash
+++ b/release.bash
@@ -63,9 +63,9 @@
git sync
# Create commit for actual release.
-sed -i -e "s/\(\s*versionMinor\s*=\s*\)[0-9]*/\1$VERSION_MINOR/" runtime/protoimpl/version.go
-sed -i -e "s/\(\s*versionPatch\s*=\s*\)[0-9]*/\1$VERSION_PATCH/" runtime/protoimpl/version.go
-sed -i -e "s/\(\s*versionPreRelease\s*=\s*\)\"[^\"]*\"/\1\"$VERSION_PRERELEASE\"/" runtime/protoimpl/version.go
+sed -i -e "s/\(\s*Minor\s*=\s*\)[0-9]*/\1$VERSION_MINOR/" internal/version/version.go
+sed -i -e "s/\(\s*Patch\s*=\s*\)[0-9]*/\1$VERSION_PATCH/" internal/version/version.go
+sed -i -e "s/\(\s*PreRelease\s*=\s*\)\"[^\"]*\"/\1\"$VERSION_PRERELEASE\"/" internal/version/version.go
if ! [[ -z $GEN_VERSION ]]; then
sed -i -e "s/\(\s*GenVersion\s*=\s*\)[0-9]*/\1$GEN_VERSION/" runtime/protoimpl/version.go
fi
@@ -80,7 +80,7 @@
# Create commit to start development after release.
VERSION_PRERELEASE="${VERSION_PRERELEASE}.devel" # append ".devel"
VERSION_PRERELEASE="${VERSION_PRERELEASE#"."}" # trim possible leading "."
-sed -i -e "s/\(\s*versionPreRelease\s*=\s*\)\"[^\"]*\"/\1\"$VERSION_PRERELEASE\"/" runtime/protoimpl/version.go
+sed -i -e "s/\(\s*PreRelease\s*=\s*\)\"[^\"]*\"/\1\"$VERSION_PRERELEASE\"/" internal/version/version.go
git commit -a -m "all: start $(version_string)"
echo
diff --git a/runtime/protoimpl/version.go b/runtime/protoimpl/version.go
index f98cf9d..ff094e1 100644
--- a/runtime/protoimpl/version.go
+++ b/runtime/protoimpl/version.go
@@ -5,82 +5,13 @@
package protoimpl
import (
- "fmt"
- "strings"
+ "google.golang.org/protobuf/internal/version"
)
-// These constants determine the current version of this module.
-//
-//
-// For our release process, we enforce the following rules:
-// * Tagged releases use a tag that is identical to VersionString.
-// * Tagged releases never reference a commit where the VersionString
-// contains "devel".
-// * The set of all commits in this repository where VersionString
-// does not contain "devel" must have a unique VersionString.
-//
-//
-// Steps for tagging a new release:
-// 1. Create a new CL.
-//
-// 2. Update versionMinor, versionPatch, and/or versionPreRelease as necessary.
-// versionPreRelease must not contain the string "devel".
-//
-// 3. Since the last released minor version, have there been any changes to
-// generator that relies on new functionality in the runtime?
-// If yes, then increment GenVersion.
-//
-// 4. Since the last released minor version, have there been any changes to
-// the runtime that removes support for old .pb.go source code?
-// If yes, then increment MinVersion.
-//
-// 5. Send out the CL for review and submit it.
-// Note that the next CL in step 8 must be submitted after this CL
-// without any other CLs in-between.
-//
-// 6. Tag a new version, where the tag is is the current VersionString.
-//
-// 7. Write release notes for all notable changes
-// between this release and the last release.
-//
-// 8. Create a new CL.
-//
-// 9. Update versionPreRelease to include the string "devel".
-// For example: "" -> "devel" or "rc.1" -> "rc.1.devel"
-//
-// 10. Send out the CL for review and submit it.
-const (
- versionMajor = 1
- versionMinor = 20
- versionPatch = 1
- versionPreRelease = "devel"
-)
-
-// VersionString formats the version string for this module in semver format.
-//
-// Examples:
-// v1.20.1
-// v1.21.0-rc.1
-func VersionString() string {
- v := fmt.Sprintf("v%d.%d.%d", versionMajor, versionMinor, versionPatch)
- if versionPreRelease != "" {
- v += "-" + versionPreRelease
-
- // TODO: Add metadata about the commit or build hash.
- // See https://golang.org/issue/29814
- // See https://golang.org/issue/33533
- var versionMetadata string
- if strings.Contains(versionPreRelease, "devel") && versionMetadata != "" {
- v += "+" + versionMetadata
- }
- }
- return v
-}
-
const (
// MaxVersion is the maximum supported version for generated .pb.go files.
// It is always the current version of the module.
- MaxVersion = versionMinor
+ MaxVersion = version.Minor
// GenVersion is the runtime version required by generated .pb.go files.
// This is incremented when generated code relies on new functionality