version.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package protoimpl
  5. import (
  6. "fmt"
  7. "strings"
  8. )
  9. // These constants determine the current version of this module.
  10. //
  11. //
  12. // For our release process, we enforce the following rules:
  13. // * Tagged releases use a tag that is identical to VersionString.
  14. // * Tagged releases never reference a commit where the VersionString
  15. // contains "devel".
  16. // * The set of all commits in this repository where VersionString
  17. // does not contain "devel" must have a unique VersionString.
  18. //
  19. //
  20. // Steps for tagging a new release:
  21. // 1. Create a new CL.
  22. //
  23. // 2. Update versionMinor, versionPatch, and/or versionPreRelease as necessary.
  24. // versionPreRelease must not contain the string "devel".
  25. //
  26. // 3. Since the last released minor version, have there been any changes to
  27. // generator that relies on new functionality in the runtime?
  28. // If yes, then increment GenVersion.
  29. //
  30. // 4. Since the last released minor version, have there been any changes to
  31. // the runtime that removes support for old .pb.go source code?
  32. // If yes, then increment MinVersion.
  33. //
  34. // 5. Send out the CL for review and submit it.
  35. // Note that the next CL in step 8 must be submitted after this CL
  36. // without any other CLs in-between.
  37. //
  38. // 6. Tag a new version, where the tag is is the current VersionString.
  39. //
  40. // 7. Write release notes for all notable changes
  41. // between this release and the last release.
  42. //
  43. // 8. Create a new CL.
  44. //
  45. // 9. Update versionPreRelease to include the string "devel".
  46. // For example: "" -> "devel" or "rc.1" -> "rc.1.devel"
  47. //
  48. // 10. Send out the CL for review and submit it.
  49. const (
  50. versionMajor = 1
  51. versionMinor = 19
  52. versionPatch = 0
  53. versionPreRelease = "devel"
  54. )
  55. // VersionString formats the version string for this module in semver format.
  56. //
  57. // Examples:
  58. // v1.20.1
  59. // v1.21.0-rc.1
  60. func VersionString() string {
  61. v := fmt.Sprintf("v%d.%d.%d", versionMajor, versionMinor, versionPatch)
  62. if versionPreRelease != "" {
  63. v += "-" + versionPreRelease
  64. // TODO: Add metadata about the commit or build hash.
  65. // See https://golang.org/issue/29814
  66. // See https://golang.org/issue/33533
  67. var versionMetadata string
  68. if strings.Contains(versionPreRelease, "devel") && versionMetadata != "" {
  69. v += "+" + versionMetadata
  70. }
  71. }
  72. return v
  73. }
  74. const (
  75. // MaxVersion is the maximum supported version for generated .pb.go files.
  76. // It is always the current version of the module.
  77. MaxVersion = versionMinor
  78. // GenVersion is the runtime version required by generated .pb.go files.
  79. // This is incremented when generated code relies on new functionality
  80. // in the runtime.
  81. GenVersion = 19
  82. // MinVersion is the minimum supported version for generated .pb.go files.
  83. // This is incremented when the runtime drops support for old code.
  84. MinVersion = 0
  85. )
  86. // EnforceVersion is used by code generated by protoc-gen-go
  87. // to statically enforce minimum and maximum versions of this package.
  88. // A compilation failure implies either that:
  89. // * the runtime package is too old and needs to be updated OR
  90. // * the generated code is too old and needs to be regenerated.
  91. //
  92. // The runtime package can be upgraded by running:
  93. // go get google.golang.org/protobuf
  94. //
  95. // The generated code can be regenerated by running:
  96. // protoc --go_out=${PROTOC_GEN_GO_ARGS} ${PROTO_FILES}
  97. //
  98. // Example usage by generated code:
  99. // const (
  100. // // Verify that this generated code is sufficiently up-to-date.
  101. // _ = protoimpl.EnforceVersion(genVersion - protoimpl.MinVersion)
  102. // // Verify that runtime/protoimpl is sufficiently up-to-date.
  103. // _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - genVersion)
  104. // )
  105. //
  106. // The genVersion is the current minor version used to generated the code.
  107. // This compile-time check relies on negative integer overflow of a uint
  108. // being a compilation failure (guaranteed by the Go specification).
  109. type EnforceVersion uint
  110. // This enforces the following invariant:
  111. // MinVersion ≤ GenVersion ≤ MaxVersion
  112. const (
  113. _ = EnforceVersion(GenVersion - MinVersion)
  114. _ = EnforceVersion(MaxVersion - GenVersion)
  115. )