From 4b3125360e7ddf0362dddf41e9a195397406252d Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 16 May 2023 15:03:05 +0800 Subject: [PATCH] refactor: enhance kcl version info message and bump kcl version to v0.4.6.3. --- internal/scripts/cli/kcl | 9 ++++- kclvm/Cargo.lock | 67 +++++++++++++++++++++++++++++++++-- kclvm/cmd/src/lib.rs | 2 +- kclvm/runner/src/assembler.rs | 2 +- kclvm/version/Cargo.toml | 3 ++ kclvm/version/build.rs | 8 +++++ kclvm/version/src/lib.rs | 17 +++++++-- scripts/build-windows/kcl.go | 10 ++++-- 8 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 kclvm/version/build.rs diff --git a/internal/scripts/cli/kcl b/internal/scripts/cli/kcl index e6467f75c..120639251 100755 --- a/internal/scripts/cli/kcl +++ b/internal/scripts/cli/kcl @@ -15,4 +15,11 @@ fi export PYTHONPATH=$kclvm_install_dir/lib/site-packages export KCLVM_CLI_BIN_PATH=$kclvm_install_dir/bin -$kclvm_cli_bin run "$@" +# Only for v0.4.x, all CLIs will be unified after v0.5.x +case $1 in + "version" | "--version" | "-v" | "-V") + $kclvm_cli_bin version + ;; + *) $kclvm_cli_bin run "$@" + ;; +esac diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index 2d5ec9d56..3df607aa4 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -1703,6 +1703,9 @@ version = "0.4.6" [[package]] name = "kclvm-version" version = "0.4.6" +dependencies = [ + "vergen", +] [[package]] name = "kclvm_runtime_internal_macros" @@ -2700,6 +2703,15 @@ dependencies = [ "semver 0.9.0", ] +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.17", +] + [[package]] name = "rustix" version = "0.37.19" @@ -2714,6 +2726,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rustversion" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" + [[package]] name = "ryu" version = "1.0.13" @@ -2794,6 +2812,12 @@ dependencies = [ "semver-parser 0.10.2", ] +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + [[package]] name = "semver-parser" version = "0.7.0" @@ -3027,7 +3051,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" dependencies = [ "discard", - "rustc_version", + "rustc_version 0.2.3", "stdweb-derive", "stdweb-internal-macros", "stdweb-internal-runtime", @@ -3212,11 +3236,29 @@ dependencies = [ "libc", "standback", "stdweb", - "time-macros", + "time-macros 0.1.1", "version_check", "winapi", ] +[[package]] +name = "time" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc" +dependencies = [ + "itoa", + "serde", + "time-core", + "time-macros 0.2.9", +] + +[[package]] +name = "time-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" + [[package]] name = "time-macros" version = "0.1.1" @@ -3227,6 +3269,15 @@ dependencies = [ "time-macros-impl", ] +[[package]] +name = "time-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +dependencies = [ + "time-core", +] + [[package]] name = "time-macros-impl" version = "0.1.2" @@ -3604,6 +3655,18 @@ dependencies = [ "serde", ] +[[package]] +name = "vergen" +version = "8.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e03272e388fb78fc79481a493424f78d77be1d55f21bcd314b5a6716e195afe" +dependencies = [ + "anyhow", + "rustc_version 0.4.0", + "rustversion", + "time 0.3.21", +] + [[package]] name = "version_check" version = "0.9.4" diff --git a/kclvm/cmd/src/lib.rs b/kclvm/cmd/src/lib.rs index a0dc6b32b..e82fb6201 100644 --- a/kclvm/cmd/src/lib.rs +++ b/kclvm/cmd/src/lib.rs @@ -36,7 +36,7 @@ pub fn main(args: &[&str]) -> Result<()> { } else if matches.subcommand_matches("server").is_some() { kclvm_api::service::jsonrpc::start_stdio_server() } else if matches.subcommand_matches("version").is_some() { - println!("{}", kclvm_version::get_full_version()); + println!("{}", kclvm_version::get_version_info()); Ok(()) } else { Ok(()) diff --git a/kclvm/runner/src/assembler.rs b/kclvm/runner/src/assembler.rs index 4fb7efb5c..6094324ee 100644 --- a/kclvm/runner/src/assembler.rs +++ b/kclvm/runner/src/assembler.rs @@ -245,7 +245,7 @@ impl KclvmAssembler { Path::new(prog_root_name) .join(".kclvm") .join("cache") - .join(kclvm_version::get_full_version()) + .join(kclvm_version::get_version_string()) .join(&self.target) } diff --git a/kclvm/version/Cargo.toml b/kclvm/version/Cargo.toml index cf61496a0..06795c646 100644 --- a/kclvm/version/Cargo.toml +++ b/kclvm/version/Cargo.toml @@ -3,6 +3,9 @@ name = "kclvm-version" version = "0.4.6" edition = "2021" +[build-dependencies] +vergen = { version = "8.1.3", features = ["git", "gitcl", "rustc"] } + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/kclvm/version/build.rs b/kclvm/version/build.rs new file mode 100644 index 000000000..c714fc12f --- /dev/null +++ b/kclvm/version/build.rs @@ -0,0 +1,8 @@ +use std::error::Error; +use vergen::EmitBuilder; + +fn main() -> Result<(), Box> { + // Emit the instructions + EmitBuilder::builder().all_rustc().all_git().emit()?; + Ok(()) +} diff --git a/kclvm/version/src/lib.rs b/kclvm/version/src/lib.rs index 0e79106f0..2ae419a8a 100644 --- a/kclvm/version/src/lib.rs +++ b/kclvm/version/src/lib.rs @@ -1,10 +1,21 @@ // Copyright 2021 The KCL Authors. All rights reserved. -pub const VERSION: &str = "0.4.6"; -pub const CHECK_SUM: &str = "c5339e572207211e46477825e8aca903"; +pub const VERSION: &str = "0.4.6.3"; +pub const CHECK_SUM: &str = "2b1bf940fc528448d982d39ec917372e"; /// Get kCL full version string with the format `{version}-{check_sum}`. #[inline] -pub fn get_full_version() -> String { +pub fn get_version_string() -> String { format!("{}-{}", VERSION, CHECK_SUM) } + +/// Get version info including version string, platform. +#[inline] +pub fn get_version_info() -> String { + format!( + "Version: {}\r\nPlatform: {}\r\nGitCommit: {}", + get_version_string(), + env!("VERGEN_RUSTC_HOST_TRIPLE"), + env!("VERGEN_GIT_SHA") + ) +} diff --git a/scripts/build-windows/kcl.go b/scripts/build-windows/kcl.go index 4b6593bcc..1f6faac82 100644 --- a/scripts/build-windows/kcl.go +++ b/scripts/build-windows/kcl.go @@ -14,8 +14,14 @@ import ( func main() { var args []string - args = append(args, "/C", "kclvm-cli", "run") - args = append(args, os.Args[1:]...) + args = append(args, "/C", "kclvm-cli") + // Check version flags. Only for v0.4.x, all CLIs will be unified after v0.5.x. + if len(os.Args) >= 1 && (os.Args[1] == "-v" || os.Args[1] == "-V" || os.Args[1] == "version" || os.Args[1] == "--version") { + args = append(args, "version") + } else { + args = append(args, "run") + args = append(args, os.Args[1:]...) + } os.Exit(KclvmCliMain(args)) }