Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: enhance kcl version info message using the vergen crate and bump kcl version to v0.4.6.3 #550

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/scripts/cli/kcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
67 changes: 65 additions & 2 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kclvm/cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion kclvm/runner/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 3 additions & 0 deletions kclvm/version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
8 changes: 8 additions & 0 deletions kclvm/version/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::error::Error;
use vergen::EmitBuilder;

fn main() -> Result<(), Box<dyn Error>> {
// Emit the instructions
EmitBuilder::builder().all_rustc().all_git().emit()?;
Ok(())
}
17 changes: 14 additions & 3 deletions kclvm/version/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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")
)
}
10 changes: 8 additions & 2 deletions scripts/build-windows/kcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down