versions: Add kata-ctl version entry

As we're switching to using the rust version of the kata-ctl, lets
provide with its own entry in the kata-ctl command line.

Signed-off-by: David Esparza <david.esparza.borquez@intel.com>
Commit-edited-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
David Esparza 2022-07-20 19:26:32 -05:00 committed by James O. D. Hunt
parent 002b18054d
commit d0b33e9a32
5 changed files with 58 additions and 7 deletions

View File

@ -5,7 +5,7 @@
[package]
name = "kata-ctl"
version = "0.0.0"
version = "0.0.1"
authors = ["The Kata Containers community <kata-dev@lists.katacontainers.io>"]
edition = "2021"

View File

@ -5,14 +5,44 @@
include ../../../utils.mk
PROJECT_NAME = Kata Containers
PROJECT_URL = https://github.com/kata-containers
PROJECT_COMPONENT = kata-ctl
TARGET = $(PROJECT_COMPONENT)
VERSION_FILE := ./VERSION
VERSION := $(shell grep -v ^\# $(VERSION_FILE))
COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true)
COMMIT_NO_SHORT := $(shell git rev-parse --short HEAD 2>/dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO})
# Exported to allow cargo to see it
export KATA_CTL_VERSION := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))
GENERATED_CODE = src/version.rs
GENERATED_REPLACEMENTS= \
KATA_CTL_VERSION
GENERATED_FILES := $(GENERATED_CODE)
.DEFAULT_GOAL := default
default: build
default: $(TARGET) build
$(TARGET): $(GENERATED_CODE)
build:
@RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE)
@RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) $(if $(findstring release,$(BUILD_TYPE)),--release) $(EXTRA_RUSTFEATURES)
$(GENERATED_FILES): %: %.in
@sed $(foreach r,$(GENERATED_REPLACEMENTS),-e 's|@$r@|$($r)|g') "$<" > "$@"
clean:
cargo clean
@cargo clean
@rm -f $(GENERATED_FILES)
vendor:
cargo vendor

1
src/tools/kata-ctl/VERSION Symbolic link
View File

@ -0,0 +1 @@
../../../VERSION

View File

@ -4,21 +4,25 @@
//
use anyhow::{anyhow, Result};
use clap::{crate_name, crate_version, App, Arg, SubCommand};
use clap::{crate_name, App, Arg, SubCommand};
use std::process::exit;
mod utils;
mod version;
const DESCRIPTION_TEXT: &str = r#"DESCRIPTION:
kata-ctl description placeholder."#;
const ABOUT_TEXT: &str = "Kata Containers control tool";
const NAME: &str = "kata-ctl";
fn real_main() -> Result<()> {
let name = crate_name!();
let version = version::get();
let app = App::new(name)
.version(crate_version!())
.version(&*version)
.about(ABOUT_TEXT)
.long_about(DESCRIPTION_TEXT)
.subcommand(
@ -113,7 +117,7 @@ fn real_main() -> Result<()> {
Ok(())
}
"version" => {
println!("Not implemented");
println!("{} version {} (type: rust)", NAME, version);
Ok(())
}
_ => return Err(anyhow!(format!("invalid sub-command: {:?}", subcmd))),

View File

@ -0,0 +1,16 @@
// Copyright (c) 2020 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
//
// WARNING: This file is auto-generated - DO NOT EDIT!
//
use clap::crate_version;
const KATA_CTL_VERSION: &str = "@KATA_CTL_VERSION@";
pub fn get() -> String {
format!("{}-{}", KATA_CTL_VERSION, crate_version!())
}