From 4186e597af76db87b3725babadca93a663dbba95 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Fri, 1 Mar 2024 13:28:14 +0000 Subject: [PATCH] Simplify Makefile Signed-off-by: Alberto Faria --- Makefile | 91 +++++++++++++++----------------------------------- plans/main.fmf | 13 ++++---- 2 files changed, 32 insertions(+), 72 deletions(-) diff --git a/Makefile b/Makefile index e96a603..0838eaf 100644 --- a/Makefile +++ b/Makefile @@ -1,82 +1,43 @@ -# This Makefile is intended for developer convenience. For the most part -# all the targets here simply wrap calls to the `cargo` tool. Therefore, -# most targets must be marked 'PHONY' to prevent `make` getting in the way -# -#prog :=xnixperms +# SPDX-License-Identifier: GPL-2.0-or-later DESTDIR ?= -PREFIX ?= /usr/local -BINDIR ?= $(PREFIX)/bin +PREFIX ?= /usr/local +CARGO ?= cargo SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z) -# Get crate version by parsing the line that starts with version. -CRATE_VERSION ?= $(shell grep ^version Cargo.toml | awk '{print $$3}') -GIT_TAG ?= $(shell git describe --tags) -# Set this to any non-empty string to enable unoptimized -# build w/ debugging features. -debug ?= - -# Set path to cargo executable -CARGO ?= cargo - -# All complication artifacts, including dependencies and intermediates -# will be stored here, for all architectures. Use a non-default name -# since the (default) 'target' is used/referenced ambiguously in many -# places in the tool-chain (including 'make' itself). -CARGO_TARGET_DIR ?= targets -export CARGO_TARGET_DIR # 'cargo' is sensitive to this env. var. value. - -ifdef debug -$(info debug is $(debug)) - # These affect both $(CARGO_TARGET_DIR) layout and contents - # Ref: https://doc.rust-lang.org/cargo/guide/build-cache.html - release := - profile :=debug -else - release :=--release - profile :=release -endif - -.PHONY: all -all: build - -bin: - mkdir -p $@ - -$(CARGO_TARGET_DIR): - mkdir -p $@ +binpath := $(DESTDIR)/$(PREFIX)/bin/crun-vm .PHONY: build -build: bin $(CARGO_TARGET_DIR) - $(CARGO) build $(release) - cp $(CARGO_TARGET_DIR)/$(profile)/crun-vm bin/crun-vm$(if $(debug),.debug,) +build: + $(CARGO) build --release + mkdir -p bin + cp target/release/crun-vm bin/crun-vm + +.PHONY: build-debug +build-debug: + $(CARGO) build + mkdir -p bin + cp target/debug/crun-vm bin/crun-vm.debug .PHONY: clean clean: - rm -rf bin - if [ "$(CARGO_TARGET_DIR)" = "targets" ]; then rm -rf targets; fi + rm -fr bin target .PHONY: install -install: - install ${SELINUXOPT} -D -m0755 bin/crun-vm $(DESTDIR)/$(BINDIR)/crun-vm +install: install + install ${SELINUXOPT} -D -m 0755 bin/crun-vm $(binpath) .PHONY: uninstall uninstall: - rm -f $(DESTDIR)/$(BINDIR)/crun-vm - -#.PHONY: unit -unit: $(CARGO_TARGET_DIR) - $(SHELL) tests/env.sh build - $(SHELL) tests/env.sh start - $(SHELL) tests/env.sh run all all + rm -f $(binpath) -#.PHONY: code_coverage -code_coverage: $(CARGO_TARGET_DIR) - # Downloads tarpaulin only if same version is not present on local - $(CARGO) install cargo-tarpaulin - $(CARGO) tarpaulin -v +.PHONY: lint +lint: + tests/lint.sh -.PHONY: validate -validate: $(CARGO_TARGET_DIR) - $(SHELL) lint.sh +.PHONY: test +test: + tests/env.sh build + tests/env.sh start + tests/env.sh run all all diff --git a/plans/main.fmf b/plans/main.fmf index 7067e35..d9bd438 100644 --- a/plans/main.fmf +++ b/plans/main.fmf @@ -15,15 +15,14 @@ prepare: script: - sudo systemctl start virtqemud -/unit_test: - summary: Run unit tests +/test: + summary: Test execute: how: tmt - script: | - PATH=$PATH:/root/.cargo/bin make unit + script: PATH=$PATH:/root/.cargo/bin make test -/validate_test: - summary: Run validate test +/lint: + summary: Lint execute: how: tmt - script: make validate + script: make lint