From c77e34de33b44897a79b50c7ad59f26abccccb5d Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 22 Mar 2022 17:14:40 +1100 Subject: [PATCH] runtime: Move mock hook source src/runtime/virtcontainers/hook/mock contains a simple example hook in Go. The only thing this is used for is for some tests in src/runtime/pkg/katautils/hook_test.go. It doesn't really have anything to do with the rest of the virtcontainers package. So, move it next to the test code that uses it. Signed-off-by: David Gibson --- src/runtime/Makefile | 2 +- src/runtime/pkg/katautils/hook_test.go | 2 +- src/runtime/pkg/katautils/mockhook/.gitignore | 1 + src/runtime/pkg/katautils/mockhook/Makefile | 21 +++++++++++++++++++ .../mock => pkg/katautils/mockhook}/hook.go | 0 src/runtime/virtcontainers/Makefile | 13 ++---------- 6 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 src/runtime/pkg/katautils/mockhook/.gitignore create mode 100644 src/runtime/pkg/katautils/mockhook/Makefile rename src/runtime/{virtcontainers/hook/mock => pkg/katautils/mockhook}/hook.go (100%) diff --git a/src/runtime/Makefile b/src/runtime/Makefile index f87e72e583..8f18568218 100644 --- a/src/runtime/Makefile +++ b/src/runtime/Makefile @@ -592,7 +592,7 @@ generate-config: $(CONFIGS) test: hook go-test hook: - make -C virtcontainers hook + make -C pkg/katautils/mockhook go-test: $(GENERATED_FILES) go clean -testcache diff --git a/src/runtime/pkg/katautils/hook_test.go b/src/runtime/pkg/katautils/hook_test.go index 50452974b6..9ef48499bb 100644 --- a/src/runtime/pkg/katautils/hook_test.go +++ b/src/runtime/pkg/katautils/hook_test.go @@ -20,7 +20,7 @@ import ( var testKeyHook = "test-key" var testContainerIDHook = "test-container-id" var testControllerIDHook = "test-controller-id" -var testBinHookPath = "../../virtcontainers/hook/mock/hook" +var testBinHookPath = "mockhook/hook" var testBundlePath = "/test/bundle" func getMockHookBinPath() string { diff --git a/src/runtime/pkg/katautils/mockhook/.gitignore b/src/runtime/pkg/katautils/mockhook/.gitignore new file mode 100644 index 0000000000..6d71f66fbf --- /dev/null +++ b/src/runtime/pkg/katautils/mockhook/.gitignore @@ -0,0 +1 @@ +hook diff --git a/src/runtime/pkg/katautils/mockhook/Makefile b/src/runtime/pkg/katautils/mockhook/Makefile new file mode 100644 index 0000000000..2ca6544382 --- /dev/null +++ b/src/runtime/pkg/katautils/mockhook/Makefile @@ -0,0 +1,21 @@ +# Copyright Red Hat. +# +# SPDX-License-Identifier: Apache-2.0 +# + +BIN = hook +SRC = hook.go + +V = @ +Q = $(V:1=) +QUIET_BUILD = $(Q:@=@echo ' BUILD '$@;) + +BUILDFLAGS = + +all: $(BIN) + +$(BIN): $(SRC) + $(QUIET_BUILD)go build $(BUILDFLAGS) -o $@ $^ + +clean: + rm -f $(BIN) diff --git a/src/runtime/virtcontainers/hook/mock/hook.go b/src/runtime/pkg/katautils/mockhook/hook.go similarity index 100% rename from src/runtime/virtcontainers/hook/mock/hook.go rename to src/runtime/pkg/katautils/mockhook/hook.go diff --git a/src/runtime/virtcontainers/Makefile b/src/runtime/virtcontainers/Makefile index a255741b0b..14e9af1ab4 100644 --- a/src/runtime/virtcontainers/Makefile +++ b/src/runtime/virtcontainers/Makefile @@ -5,8 +5,6 @@ # PREFIX := /usr -HOOK_DIR := hook/mock -HOOK_BIN := hook MK_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) GOBUILD_FLAGS := -mod=vendor @@ -22,16 +20,11 @@ QUIET_GOBUILD = $(Q:@=@echo ' GOBUILD '$@;) # Build # -all: build binaries +all: build build: $(QUIET_GOBUILD)go build $(GOBUILD_FLAGS) $(go list ./... | grep -v /vendor/) -hook: - $(QUIET_GOBUILD)go build $(GOBUILD_FLAGS) -o $(HOOK_DIR)/$@ $(HOOK_DIR)/*.go - -binaries: hook - # # Tests # @@ -54,7 +47,7 @@ define FILE_SAFE_TO_REMOVE = $(shell test -e "$(1)" && test "$(1)" != "/" && echo "$(1)") endef -CLEAN_FILES += $(HOOK_DIR)/$(HOOK_BIN) +CLEAN_FILES += clean: rm -f $(foreach f,$(CLEAN_FILES),$(call FILE_SAFE_TO_REMOVE,$(f))) @@ -62,8 +55,6 @@ clean: .PHONY: \ all \ build \ - hook \ - binaries \ check \ check-go-static \ check-go-test \