Update Rust version checking logic to handle release candidates

We recently changed our version formatting so that the upcoming RC release will
look like `4.31.0-rc.1`. Some of our logic wasn't prepared for the dot after
`-rc`, so this change fixes it to be able to handle that.

PiperOrigin-RevId: 743191625
This commit is contained in:
Adam Cozzette 2025-04-02 10:29:36 -07:00 committed by Copybara-Service
parent 7afce5a0a6
commit b1986448e0
2 changed files with 5 additions and 4 deletions

View file

@ -54,7 +54,7 @@ fn protoc_version(protoc_output: &str) -> String {
// "X.Y.Z" with an optional suffix starting with a dash. We want to drop the
// major version ("X.") and only keep the suffix if it starts with "-rc".
fn expected_protoc_version(cargo_version: &str) -> String {
let mut s = cargo_version.to_string();
let mut s = cargo_version.replace("-rc.", "-rc");
let is_release_candidate = s.find("-rc") != None;
if !is_release_candidate {
if let Some(i) = s.find('-') {
@ -258,6 +258,6 @@ mod tests {
assert_that!(expected_protoc_version("4.30.0-alpha"), eq("30.0"));
assert_that!(expected_protoc_version("4.30.0-beta"), eq("30.0"));
assert_that!(expected_protoc_version("4.30.0-pre"), eq("30.0"));
assert_that!(expected_protoc_version("4.30.0-rc1"), eq("30.0-rc1"));
assert_that!(expected_protoc_version("4.30.0-rc.1"), eq("30.0-rc1"));
}
}

View file

@ -20,6 +20,7 @@
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "absl/types/span.h"
@ -177,8 +178,8 @@ bool RustGenerator::Generate(const FileDescriptor* file,
{"Option", "::std::option::Option"},
});
auto expected_runtime_version =
std::string(absl::StripSuffix(PROTOBUF_RUST_VERSION_STRING, "-dev"));
std::string expected_runtime_version = absl::StrReplaceAll(
PROTOBUF_RUST_VERSION_STRING, {{"-dev", ""}, {"-rc", "-rc."}});
if (!absl::StrContains(expected_runtime_version, "-rc")) {
expected_runtime_version.append("-release");
}