From f71cf071812cff0ae7f23fc5f3d5322f3b36f9f3 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 23 Jun 2023 19:40:12 -0400 Subject: [PATCH] Add base rust version to the output of cargo-build-sbf --version (#32254) --- sdk/cargo-build-sbf/src/main.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sdk/cargo-build-sbf/src/main.rs b/sdk/cargo-build-sbf/src/main.rs index fab2c6fcac7da9..fcff95c98e1be3 100644 --- a/sdk/cargo-build-sbf/src/main.rs +++ b/sdk/cargo-build-sbf/src/main.rs @@ -162,6 +162,21 @@ fn get_latest_platform_tools_version() -> Result { Ok(version) } +fn get_base_rust_version(platform_tools_version: &str) -> String { + let target_path = + make_platform_tools_path_for_version("platform-tools", platform_tools_version); + let rustc = target_path.join("rust").join("bin").join("rustc"); + let args = vec!["--version"]; + let output = spawn(&rustc, args, false); + let rustc_re = Regex::new(r"(rustc [0-9]+\.[0-9]+\.[0-9]+).*").unwrap(); + if rustc_re.is_match(output.as_str()) { + let captures = rustc_re.captures(output.as_str()).unwrap(); + captures[1].to_string() + } else { + String::from("") + } +} + fn normalize_version(version: String) -> String { let dots = version.as_bytes().iter().fold( 0, @@ -894,10 +909,12 @@ fn main() { // The following line is scanned by CI configuration script to // separate cargo caches according to the version of platform-tools. let platform_tools_version = String::from("v1.37"); + let rust_base_version = get_base_rust_version(platform_tools_version.as_str()); let version = format!( - "{}\nplatform-tools {}", + "{}\nplatform-tools {}\n{}", crate_version!(), platform_tools_version, + rust_base_version, ); let matches = clap::Command::new(crate_name!()) .about(crate_description!())