make: add ability to silent recipe commands with chronic

Add the ability to silent recipe commands with chronic.
When OSBUILDER_USE_CHRONIC is set, the target recipe command is run
using chronic, and the output is muted unless the command fails.

Signed-off-by: Marco Vedovati <mvedovati@suse.com>
This commit is contained in:
Marco Vedovati 2019-06-18 13:36:03 +02:00
parent cbb8c01412
commit 68f2090bab

View File

@ -14,7 +14,8 @@ DISTRO ?= centos
ROOTFS_BUILD_DEST := $(PWD) ROOTFS_BUILD_DEST := $(PWD)
IMAGES_BUILD_DEST := $(PWD) IMAGES_BUILD_DEST := $(PWD)
DISTRO_ROOTFS := $(ROOTFS_BUILD_DEST)/$(DISTRO)_rootfs DISTRO_ROOTFS := $(ROOTFS_BUILD_DEST)/$(DISTRO)_rootfs
DISTRO_ROOTFS_MARKER := $(ROOTFS_BUILD_DEST)/.$(DISTRO)_rootfs.done ROOTFS_MARKER_SUFFIX := _rootfs.done
DISTRO_ROOTFS_MARKER := $(ROOTFS_BUILD_DEST)/.$(DISTRO)$(ROOTFS_MARKER_SUFFIX)
DISTRO_IMAGE := $(IMAGES_BUILD_DEST)/kata-containers.img DISTRO_IMAGE := $(IMAGES_BUILD_DEST)/kata-containers.img
DISTRO_INITRD := $(IMAGES_BUILD_DEST)/kata-containers-initrd.img DISTRO_INITRD := $(IMAGES_BUILD_DEST)/kata-containers-initrd.img
@ -24,15 +25,34 @@ COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO}) COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})
VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION)) VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))
# Set the variable to silent logs using chronic
OSBUILDER_USE_CHRONIC :=
# silent_run allows running make recipes using the chronic wrapper, so logs are
# muted if the recipe command succeeds.
# Arguments:
# - Message
# - Command to run
ifeq (,$(OSBUILDER_USE_CHRONIC))
define silent_run
@echo $(1)
$(2)
endef
else
define silent_run
@echo $(1) with command: $(2)
@chronic $(2)
endef
endif
################################################################################ ################################################################################
rootfs-%: $(ROOTFS_BUILD_DEST)/.%_rootfs.done rootfs-%: $(ROOTFS_BUILD_DEST)/.%$(ROOTFS_MARKER_SUFFIX)
@ # DONT remove. This is not cancellation rule. @ # DONT remove. This is not cancellation rule.
.PRECIOUS: $(ROOTFS_BUILD_DEST)/.%_rootfs.done .PRECIOUS: $(ROOTFS_BUILD_DEST)/.%$(ROOTFS_MARKER_SUFFIX)
$(ROOTFS_BUILD_DEST)/.%_rootfs.done:: rootfs-builder/% $(ROOTFS_BUILD_DEST)/.%$(ROOTFS_MARKER_SUFFIX):: rootfs-builder/%
@echo Creating rootfs for "$*" $(call silent_run,Creating rootfs for "$*",$(ROOTFS_BUILDER) -o $(VERSION_COMMIT) -r $(ROOTFS_BUILD_DEST)/$*_rootfs $*)
$(ROOTFS_BUILDER) -o $(VERSION_COMMIT) -r $(ROOTFS_BUILD_DEST)/$*_rootfs $*
touch $@ touch $@
image-%: $(IMAGES_BUILD_DEST)/kata-containers-image-%.img image-%: $(IMAGES_BUILD_DEST)/kata-containers-image-%.img
@ -40,16 +60,14 @@ image-%: $(IMAGES_BUILD_DEST)/kata-containers-image-%.img
.PRECIOUS: $(IMAGES_BUILD_DEST)/kata-containers-image-%.img .PRECIOUS: $(IMAGES_BUILD_DEST)/kata-containers-image-%.img
$(IMAGES_BUILD_DEST)/kata-containers-image-%.img: rootfs-% $(IMAGES_BUILD_DEST)/kata-containers-image-%.img: rootfs-%
@echo Creating image based on $^ $(call silent_run,Creating image based on $^,$(IMAGE_BUILDER) -o $@ $(ROOTFS_BUILD_DEST)/$*_rootfs)
$(IMAGE_BUILDER) -o $@ $(ROOTFS_BUILD_DEST)/$*_rootfs
initrd-%: $(IMAGES_BUILD_DEST)/kata-containers-initrd-%.img initrd-%: $(IMAGES_BUILD_DEST)/kata-containers-initrd-%.img
@ # DONT remove. This is not cancellation rule. @ # DONT remove. This is not cancellation rule.
.PRECIOUS: $(IMAGES_BUILD_DEST)/kata-containers-initrd-%.img .PRECIOUS: $(IMAGES_BUILD_DEST)/kata-containers-initrd-%.img
$(IMAGES_BUILD_DEST)/kata-containers-initrd-%.img: rootfs-% $(IMAGES_BUILD_DEST)/kata-containers-initrd-%.img: rootfs-%
@echo Creating initrd image for $* $(call silent_run,Creating initrd image for $*,$(INITRD_BUILDER) -o $@ $(ROOTFS_BUILD_DEST)/$*_rootfs)
$(INITRD_BUILDER) -o $@ $(ROOTFS_BUILD_DEST)/$*_rootfs
.PHONY: all .PHONY: all
all: image initrd all: image initrd
@ -61,15 +79,13 @@ rootfs: $(DISTRO_ROOTFS_MARKER)
image: $(DISTRO_IMAGE) image: $(DISTRO_IMAGE)
$(DISTRO_IMAGE): $(DISTRO_ROOTFS_MARKER) $(DISTRO_IMAGE): $(DISTRO_ROOTFS_MARKER)
@echo Creating image based on "$(DISTRO_ROOTFS)" $(call silent_run,Creating image based on "$(DISTRO_ROOTFS)",$(IMAGE_BUILDER) "$(DISTRO_ROOTFS)")
$(IMAGE_BUILDER) "$(DISTRO_ROOTFS)"
.PHONY: initrd .PHONY: initrd
initrd: $(DISTRO_INITRD) initrd: $(DISTRO_INITRD)
$(DISTRO_INITRD): $(DISTRO_ROOTFS_MARKER) $(DISTRO_INITRD): $(DISTRO_ROOTFS_MARKER)
@echo Creating initrd image based on "$(DISTRO_ROOTFS)" $(call silent_run,Creating initrd image based on "$(DISTRO_ROOTFS)",$(INITRD_BUILDER) "$(DISTRO_ROOTFS)")
$(INITRD_BUILDER) "$(DISTRO_ROOTFS)"
.PHONY: test .PHONY: test
test: test: