Skip to content

Commit

Permalink
Merge pull request containers#2409 from saschagrunert/help
Browse files Browse the repository at this point in the history
Add support for `make help`
  • Loading branch information
openshift-merge-bot[bot] authored Sep 5, 2024
2 parents 0dffd37 + 37887ed commit f4f22d0
Showing 1 changed file with 75 additions and 34 deletions.
109 changes: 75 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,104 @@ CI_TAG ?=
GOLANGCI_LINT_VERSION := v1.60.3
ZEITGEIST_VERSION := v0.4.4

default:
COLOR:=\\033[36m
NOCOLOR:=\\033[0m
WIDTH:=25

all: default

.PHONY: help
help: ## Display this help.
@awk \
-v "col=${COLOR}" -v "nocol=${NOCOLOR}" \
' \
BEGIN { \
FS = ":.*##" ; \
printf "Usage:\n make %s<target>%s\n", col, nocol \
} \
/^[./a-zA-Z_-]+:.*?##/ { \
printf " %s%-${WIDTH}s%s %s\n", col, $$1, nocol, $$2 \
} \
/^##@/ { \
printf "\n%s\n", substr($$0, 5) \
} \
' $(MAKEFILE_LIST)

##@ Build targets:

.PHONY: default
default: ## Build in debug mode.
cargo build

release:
.PHONY: release
release: ## Build in release mode.
cargo build --release

.PHONY: release-static
release-static:
release-static: ## Build the static release binary.
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-unknown-linux-gnu
strip -s target/x86_64-unknown-linux-gnu/release/conmonrs
ldd target/x86_64-unknown-linux-gnu/release/conmonrs 2>&1 | grep -qE '(statically linked)|(not a dynamic executable)'

lint: lint-rust lint-go
##@ Test targets:
.PHONY: unit
unit: ## Run the unit tests.
cargo test --no-fail-fast

.PHONY: integration
integration: .install.ginkgo release ## Run the integration tests using the release binary.
export CONMON_BINARY="$(MAKEFILE_PATH)target/release/$(BINARY)" && \
export RUNTIME_BINARY="$(RUNTIME_PATH)" && \
export MAX_RSS_KB=10240 && \
"$(GOTOOLS_BINDIR)/ginkgo" $(TEST_FLAGS) $(GINKGO_FLAGS)

.PHONY: integration-static
integration-static: .install.ginkgo ## Run the integration tests using the static release binary.
export CONMON_BINARY="$(MAKEFILE_PATH)target/x86_64-unknown-linux-gnu/release/$(BINARY)" && \
if [ ! -f "$$CONMON_BINARY" ]; then \
$(MAKE) release-static; \
fi && \
export RUNTIME_BINARY="$(RUNTIME_PATH)" && \
export MAX_RSS_KB=9500 && \
"$(GOTOOLS_BINDIR)/ginkgo" $(TEST_FLAGS) $(GINKGO_FLAGS)

lint-rust:
##@ Verify targets:

.PHONY: lint
lint: lint-rust lint-go ## Lint Rust and Go sources.

.PHONY: lint-rust
lint-rust: ## Lint the Rust sources.
cargo fmt && git diff --exit-code
cargo clippy --all-targets --all-features -- -D warnings

lint-go: .install.golangci-lint
.PHONY: lint-go
lint-go: .install.golangci-lint ## Lint the Go sources.
$(GOTOOLS_BINDIR)/golangci-lint version
$(GOTOOLS_BINDIR)/golangci-lint linters
GL_DEBUG=gocritic $(GOTOOLS_BINDIR)/golangci-lint run

.PHONY: verify-dependencies
verify-dependencies: $(GOTOOLS_BINDIR)/zeitgeist
verify-dependencies: $(GOTOOLS_BINDIR)/zeitgeist ## Verify the local dependencies.
$(GOTOOLS_BINDIR)/zeitgeist validate --local-only --base-path . --config dependencies.yaml

.PHONY: verify-prettier
verify-prettier: prettier ## Run prettier on the project.
./hack/tree_status.sh

##@ Utility targets:

.PHONY: prettier
prettier: ## Prettify supported files.
$(CONTAINER_RUNTIME) run -it --privileged -v ${PWD}:/w -w /w --entrypoint bash node:latest -c \
'npm install -g prettier && prettier -w .'

unit:
cargo test --no-fail-fast

integration: .install.ginkgo release # It needs to be release so we correctly test the RSS usage
export CONMON_BINARY="$(MAKEFILE_PATH)target/release/$(BINARY)" && \
export RUNTIME_BINARY="$(RUNTIME_PATH)" && \
export MAX_RSS_KB=10240 && \
"$(GOTOOLS_BINDIR)/ginkgo" $(TEST_FLAGS) $(GINKGO_FLAGS)

integration-static: .install.ginkgo # It needs to be release so we correctly test the RSS usage
export CONMON_BINARY="$(MAKEFILE_PATH)target/x86_64-unknown-linux-gnu/release/$(BINARY)" && \
if [ ! -f "$$CONMON_BINARY" ]; then \
$(MAKE) release-static; \
fi && \
export RUNTIME_BINARY="$(RUNTIME_PATH)" && \
export MAX_RSS_KB=9500 && \
"$(GOTOOLS_BINDIR)/ginkgo" $(TEST_FLAGS) $(GINKGO_FLAGS)

.PHONY: .install.ginkgo
.install.ginkgo:
GOBIN=$(abspath $(GOTOOLS_BINDIR)) \
go install "github.com/onsi/ginkgo/v2/ginkgo@$$(go list -m -f {{.Version}} github.com/onsi/ginkgo/v2)"

.PHONY: .install.golangci-lint
.install.golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
BINDIR=$(abspath $(GOTOOLS_BINDIR)) sh -s $(GOLANGCI_LINT_VERSION)
Expand All @@ -82,42 +122,43 @@ $(GOTOOLS_BINDIR)/zeitgeist:
https://storage.googleapis.com/k8s-artifacts-sig-release/kubernetes-sigs/zeitgeist/$(ZEITGEIST_VERSION)/zeitgeist-amd64-linux
chmod +x $(GOTOOLS_BINDIR)/zeitgeist

clean:
.PHONY: clean
clean: ## Cleanup the project files.
rm -rf target/

.INTERMEDIATE: internal/proto/conmon.capnp
internal/proto/conmon.capnp:
cat $(PROTO_PATH)/conmon.capnp $(PROTO_PATH)/go-patch > $@

update-proto: internal/proto/conmon.capnp

.PHONY: update-proto
update-proto: internal/proto/conmon.capnp ## Update the Cap'n Proto protocol.
$(eval GO_CAPNP_VERSION ?= $(shell grep '^\s*capnproto.org/go/capnp/v3 v3\.' go.mod | grep -o 'v3\..*'))
go install capnproto.org/go/capnp/v3/capnpc-go@$(GO_CAPNP_VERSION)
capnp compile \
-I$(shell go env GOMODCACHE)/capnproto.org/go/capnp/v3@$(GO_CAPNP_VERSION)/std \
-ogo internal/proto/conmon.capnp

.PHONY: lint lint-go lint-rust clean unit integration update-proto

.PHONY: create-release-packages
create-release-packages: release
create-release-packages: release ## Create the release tarballs.
if [ "$(PACKAGE_NAME)" != "conmonrs-$(CI_TAG)" ]; then \
echo "crate version and tag mismatch" ; \
exit 1 ; \
fi
git archive --format tar --prefix=conmonrs-$(CI_TAG)/ $(CI_TAG) | gzip >$(PACKAGE_NAME).tar.gz


.PHONY: install
install:
install: ## Install the binary.
mkdir -p "${DESTDIR}$(PREFIX)/bin"
install -D -t "${DESTDIR}$(PREFIX)/bin" target/release/conmonrs

# Only meant to build the latest HEAD commit + any uncommitted changes
# Not a replacement for the distro package
.PHONY: rpm
rpm:
rpm: # Build the RPM locally
rpkg local

nixpkgs:
.PHONY: nixpkgs
nixpkgs: ## Update the NIX package dependencies.
@nix run -f channel:nixpkgs-unstable nix-prefetch-git -- \
--no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json

0 comments on commit f4f22d0

Please sign in to comment.