agent: Generate version file with more adequate information in it.

The version.rs file is now generated to contain up-to-date information
from the makefile, including git commit and the full binary path.

The makefile has also been modified to make it easier to add changes
in generated files based on makefile variables.

Fixes: #740

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
This commit is contained in:
Christophe de Dinechin 2020-09-16 19:33:01 +02:00
parent f13ca94e10
commit 615ffb93e5
6 changed files with 32 additions and 27 deletions

View File

@ -57,8 +57,19 @@ INIT := no
# Path to systemd unit directory if installed as not init. # Path to systemd unit directory if installed as not init.
UNIT_DIR := /usr/lib/systemd/system UNIT_DIR := /usr/lib/systemd/system
GENERATED_CODE = src/generated.rs GENERATED_CODE = src/version.rs
AGENT_NAME=$(TARGET)
API_VERSION=0.0.1
AGENT_VERSION=$(VERSION)
GENERATED_REPLACEMENTS= \
AGENT_NAME \
AGENT_VERSION \
API_VERSION \
BINDIR \
COMMIT \
VERSION_COMMIT
GENERATED_FILES := GENERATED_FILES :=
GENERATED_FILES += $(GENERATED_CODE) GENERATED_FILES += $(GENERATED_CODE)
@ -102,11 +113,7 @@ show-header:
@printf "%s - version %s (commit %s)\n\n" "$(TARGET)" "$(VERSION)" "$(COMMIT_MSG)" @printf "%s - version %s (commit %s)\n\n" "$(TARGET)" "$(VERSION)" "$(COMMIT_MSG)"
$(GENERATED_FILES): %: %.in $(GENERATED_FILES): %: %.in
@sed \ @sed $(foreach r,$(GENERATED_REPLACEMENTS),-e 's|@$r@|$($r)|g') "$<" > "$@"
-e 's|[@]bindir[@]|$(BINDIR)|g' \
-e 's|[@]kata-agent[@]|$(TARGET)|g' \
-e 's|[@]VERSION_COMMIT[@]|$(VERSION_COMMIT)|g' \
"$<" > "$@"
install: build-service install: build-service
@install -D $(TARGET_PATH) $(DESTDIR)/$(BINDIR)/$(TARGET) @install -D $(TARGET_PATH) $(DESTDIR)/$(BINDIR)/$(TARGET)

View File

@ -14,7 +14,7 @@ Wants=kata-containers.target
# from a VM vsock port # from a VM vsock port
StandardOutput=tty StandardOutput=tty
Type=simple Type=simple
ExecStart=@bindir@/@kata-agent@ ExecStart=@BINDIR@/@AGENT_NAME@
LimitNOFILE=infinity LimitNOFILE=infinity
# ExecStop is required for static agent tracing; in all other scenarios # ExecStop is required for static agent tracing; in all other scenarios
# the runtime handles shutting down the VM. # the runtime handles shutting down the VM.

View File

@ -1,10 +0,0 @@
// Copyright (c) 2020 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
//
// WARNING: This file is auto-generated - DO NOT EDIT!
//
pub const VERSION_COMMIT: &str = "@VERSION_COMMIT@";

View File

@ -52,7 +52,6 @@ use unistd::Pid;
mod config; mod config;
mod device; mod device;
mod generated;
mod linux_abi; mod linux_abi;
mod metrics; mod metrics;
mod mount; mod mount;
@ -85,7 +84,7 @@ lazy_static! {
fn announce(logger: &Logger, config: &agentConfig) { fn announce(logger: &Logger, config: &agentConfig) {
info!(logger, "announce"; info!(logger, "announce";
"agent-commit" => generated::VERSION_COMMIT, "agent-commit" => version::VERSION_COMMIT,
// Avoid any possibility of confusion with the old agent // Avoid any possibility of confusion with the old agent
"agent-type" => "rust", "agent-type" => "rust",
@ -105,7 +104,7 @@ fn main() -> Result<()> {
NAME, NAME,
version::AGENT_VERSION, version::AGENT_VERSION,
version::API_VERSION, version::API_VERSION,
generated::VERSION_COMMIT, version::VERSION_COMMIT,
); );
exit(0); exit(0);

View File

@ -1,7 +0,0 @@
// Copyright (c) 2019 Ant Financial
//
// SPDX-License-Identifier: Apache-2.0
//
pub const AGENT_VERSION: &str = "1.4.5";
pub const API_VERSION: &str = "0.0.1";

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!
//
pub const AGENT_VERSION: &str = "@AGENT_VERSION@";
pub const API_VERSION: &str = "@API_VERSION@";
pub const VERSION_COMMIT: &str = "@VERSION_COMMIT@";
pub const GIT_COMMIT: &str = "@COMMIT@";
pub const AGENT_NAME: &str = "@AGENT_NAME@";
pub const AGENT_DIR: &str = "@BINDIR@";
pub const AGENT_PATH: &str = "@BINDIR@/@AGENT_NAME@";