From c823b4cd9902033b5f9d8b4b567f237fb158004d Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Tue, 15 Sep 2020 17:00:59 +0100 Subject: [PATCH 1/3] agent: Make build remove generated files on clean Ensure that `make clean` removes generated files. Signed-off-by: James O. D. Hunt --- src/agent/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/agent/Makefile b/src/agent/Makefile index e62ef2d032..ef35cdccf4 100644 --- a/src/agent/Makefile +++ b/src/agent/Makefile @@ -108,6 +108,7 @@ install: build-service clean: @cargo clean + @rm -f $(GENERATED_FILES) test: @cargo test --all --target $(TRIPLE) From f13ca94e10eaeff3c7e9d5005cf455a457d4fdb7 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Tue, 15 Sep 2020 17:02:00 +0100 Subject: [PATCH 2/3] agent: Fix setting of version Fix the bug where the version string generated by the `Makefile` was not being passed to the agent, resulting in a "unknown" version. Fixes: #725. Signed-off-by: James O. D. Hunt --- src/agent/Makefile | 9 +++++++-- src/agent/src/generated.rs.in | 10 ++++++++++ src/agent/src/main.rs | 10 +++------- 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 src/agent/src/generated.rs.in diff --git a/src/agent/Makefile b/src/agent/Makefile index ef35cdccf4..06ce29b5e8 100644 --- a/src/agent/Makefile +++ b/src/agent/Makefile @@ -57,12 +57,16 @@ INIT := no # Path to systemd unit directory if installed as not init. UNIT_DIR := /usr/lib/systemd/system +GENERATED_CODE = src/generated.rs + GENERATED_FILES := +GENERATED_FILES += $(GENERATED_CODE) + ifeq ($(INIT),no) # Unit file to start kata agent in systemd systems UNIT_FILES = kata-agent.service - GENERATED_FILES := $(UNIT_FILES) + GENERATED_FILES += $(UNIT_FILES) # Target to be reached in systemd services UNIT_FILES += kata-containers.target endif @@ -86,7 +90,7 @@ endef default: $(TARGET) show-header -$(TARGET): $(TARGET_PATH) +$(TARGET): $(GENERATED_CODE) $(TARGET_PATH) $(TARGET_PATH): $(SOURCES) | show-summary @cargo build --target $(TRIPLE) --$(BUILD_TYPE) @@ -101,6 +105,7 @@ $(GENERATED_FILES): %: %.in @sed \ -e 's|[@]bindir[@]|$(BINDIR)|g' \ -e 's|[@]kata-agent[@]|$(TARGET)|g' \ + -e 's|[@]VERSION_COMMIT[@]|$(VERSION_COMMIT)|g' \ "$<" > "$@" install: build-service diff --git a/src/agent/src/generated.rs.in b/src/agent/src/generated.rs.in new file mode 100644 index 0000000000..bcf9a13443 --- /dev/null +++ b/src/agent/src/generated.rs.in @@ -0,0 +1,10 @@ +// 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@"; diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 01fd71f7b7..454919ec16 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -52,6 +52,7 @@ use unistd::Pid; mod config; mod device; +mod generated; mod linux_abi; mod metrics; mod mount; @@ -83,13 +84,8 @@ lazy_static! { } fn announce(logger: &Logger, config: &agentConfig) { - let commit = match env::var("VERSION_COMMIT") { - Ok(s) => s, - Err(_) => String::from(""), - }; - info!(logger, "announce"; - "agent-commit" => commit.as_str(), + "agent-commit" => generated::VERSION_COMMIT, // Avoid any possibility of confusion with the old agent "agent-type" => "rust", @@ -109,7 +105,7 @@ fn main() -> Result<()> { NAME, version::AGENT_VERSION, version::API_VERSION, - env::var("VERSION_COMMIT").unwrap_or("unknown".to_string()) + generated::VERSION_COMMIT, ); exit(0); From 615ffb93e5585d45b6a70100e4d1b88e5e11430f Mon Sep 17 00:00:00 2001 From: Christophe de Dinechin Date: Wed, 16 Sep 2020 19:33:01 +0200 Subject: [PATCH 3/3] 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 --- src/agent/Makefile | 19 +++++++++++++------ src/agent/kata-agent.service.in | 2 +- src/agent/src/generated.rs.in | 10 ---------- src/agent/src/main.rs | 5 ++--- src/agent/src/version.rs | 7 ------- src/agent/src/version.rs.in | 16 ++++++++++++++++ 6 files changed, 32 insertions(+), 27 deletions(-) delete mode 100644 src/agent/src/generated.rs.in delete mode 100644 src/agent/src/version.rs create mode 100644 src/agent/src/version.rs.in diff --git a/src/agent/Makefile b/src/agent/Makefile index 06ce29b5e8..929469313c 100644 --- a/src/agent/Makefile +++ b/src/agent/Makefile @@ -57,8 +57,19 @@ INIT := no # Path to systemd unit directory if installed as not init. 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_CODE) @@ -102,11 +113,7 @@ show-header: @printf "%s - version %s (commit %s)\n\n" "$(TARGET)" "$(VERSION)" "$(COMMIT_MSG)" $(GENERATED_FILES): %: %.in - @sed \ - -e 's|[@]bindir[@]|$(BINDIR)|g' \ - -e 's|[@]kata-agent[@]|$(TARGET)|g' \ - -e 's|[@]VERSION_COMMIT[@]|$(VERSION_COMMIT)|g' \ - "$<" > "$@" + @sed $(foreach r,$(GENERATED_REPLACEMENTS),-e 's|@$r@|$($r)|g') "$<" > "$@" install: build-service @install -D $(TARGET_PATH) $(DESTDIR)/$(BINDIR)/$(TARGET) diff --git a/src/agent/kata-agent.service.in b/src/agent/kata-agent.service.in index b4f7d870b5..c0541b440d 100644 --- a/src/agent/kata-agent.service.in +++ b/src/agent/kata-agent.service.in @@ -14,7 +14,7 @@ Wants=kata-containers.target # from a VM vsock port StandardOutput=tty Type=simple -ExecStart=@bindir@/@kata-agent@ +ExecStart=@BINDIR@/@AGENT_NAME@ LimitNOFILE=infinity # ExecStop is required for static agent tracing; in all other scenarios # the runtime handles shutting down the VM. diff --git a/src/agent/src/generated.rs.in b/src/agent/src/generated.rs.in deleted file mode 100644 index bcf9a13443..0000000000 --- a/src/agent/src/generated.rs.in +++ /dev/null @@ -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@"; diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 454919ec16..49f0934c33 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -52,7 +52,6 @@ use unistd::Pid; mod config; mod device; -mod generated; mod linux_abi; mod metrics; mod mount; @@ -85,7 +84,7 @@ lazy_static! { fn announce(logger: &Logger, config: &agentConfig) { info!(logger, "announce"; - "agent-commit" => generated::VERSION_COMMIT, + "agent-commit" => version::VERSION_COMMIT, // Avoid any possibility of confusion with the old agent "agent-type" => "rust", @@ -105,7 +104,7 @@ fn main() -> Result<()> { NAME, version::AGENT_VERSION, version::API_VERSION, - generated::VERSION_COMMIT, + version::VERSION_COMMIT, ); exit(0); diff --git a/src/agent/src/version.rs b/src/agent/src/version.rs deleted file mode 100644 index 4902438661..0000000000 --- a/src/agent/src/version.rs +++ /dev/null @@ -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"; diff --git a/src/agent/src/version.rs.in b/src/agent/src/version.rs.in new file mode 100644 index 0000000000..07132fad94 --- /dev/null +++ b/src/agent/src/version.rs.in @@ -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@";