From 17ee51d7534d09e3da8494521adffb7d93cee87b Mon Sep 17 00:00:00 2001 From: Danish Prakash Date: Thu, 31 Oct 2024 10:42:25 +0900 Subject: [PATCH] Makefile: use `find` to detect source files The current list of sources doesn't list vendor sources and some other .go files, requiring manual modifications to the Makefile to build binaries. This change uses `find` (from Podman's Makefile) to detect .go files across the repo. Removes the validation script since we're no longer specifying sources manually. And removes explicit *.go files as binary sources. Signed-off-by: Danish Prakash --- Makefile | 16 ++++++++++------ hack/makefile_sources | 20 -------------------- 2 files changed, 10 insertions(+), 26 deletions(-) delete mode 100755 hack/makefile_sources diff --git a/Makefile b/Makefile index 8ca47072da0..3d7048ace27 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,12 @@ CNI_COMMIT := $(shell sed -n 's;^$(COMMENT) github.com/containernetworking/cni \ EXTRA_LDFLAGS ?= BUILDAH_LDFLAGS := $(GO_LDFLAGS) '-X main.GitCommit=$(GIT_COMMIT) -X main.buildInfo=$(SOURCE_DATE_EPOCH) -X main.cniVersion=$(CNI_COMMIT) $(EXTRA_LDFLAGS)' -SOURCES=*.go imagebuildah/*.go bind/*.go chroot/*.go copier/*.go define/*.go docker/*.go internal/config/*.go internal/mkcw/*.go internal/mkcw/types/*.go internal/parse/*.go internal/sbom/*.go internal/source/*.go internal/tmpdir/*.go internal/*.go internal/util/*.go internal/volumes/*.go manifests/*.go pkg/binfmt/*.go pkg/blobcache/*.go pkg/chrootuser/*.go pkg/cli/*.go pkg/completion/*.go pkg/formats/*.go pkg/jail/*.go pkg/overlay/*.go pkg/parse/*.go pkg/rusage/*.go pkg/sshagent/*.go pkg/umask/*.go pkg/util/*.go pkg/volumes/*.go util/*.go + +# This isn't what we actually build; it's a superset, used for target +# dependencies. Basically: all *.go and *.c files, except *_test.go, +# and except anything in a dot subdirectory. If any of these files is +# newer than our target (bin/buildah), a rebuild is triggered. +SOURCES=$(shell find . -path './.*' -prune -o \( \( -name '*.go' -o -name '*.c' \) -a ! -name '*_test.go' \) -print) LINTFLAGS ?= @@ -68,7 +73,7 @@ static: mkdir -p ./bin cp -rfp ./result/bin/* ./bin/ -bin/buildah: $(SOURCES) cmd/buildah/*.go internal/mkcw/embed/entrypoint_amd64.gz +bin/buildah: $(SOURCES) internal/mkcw/embed/entrypoint_amd64.gz $(GO_BUILD) $(BUILDAH_LDFLAGS) $(GO_GCFLAGS) "$(GOGCFLAGS)" -o $@ $(BUILDFLAGS) ./cmd/buildah test -z "${SELINUXOPT}" || chcon --verbose -t $(SELINUXTYPE) $@ @@ -98,13 +103,13 @@ bin/buildah.%: mkdir -p ./bin GOOS=$(word 2,$(subst ., ,$@)) GOARCH=$(word 3,$(subst ., ,$@)) $(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ -tags "containers_image_openpgp" ./cmd/buildah -bin/imgtype: $(SOURCES) tests/imgtype/imgtype.go +bin/imgtype: $(SOURCES) $(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/imgtype/imgtype.go -bin/copy: $(SOURCES) tests/copy/copy.go +bin/copy: $(SOURCES) $(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/copy/copy.go -bin/tutorial: $(SOURCES) tests/tutorial/tutorial.go +bin/tutorial: $(SOURCES) $(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/tutorial/tutorial.go bin/inet: tests/inet/inet.go @@ -127,7 +132,6 @@ validate: install.tools ./tests/validate/whitespace.sh ./hack/xref-helpmsgs-manpages ./tests/validate/pr-should-include-tests - ./hack/makefile_sources .PHONY: install.tools install.tools: diff --git a/hack/makefile_sources b/hack/makefile_sources deleted file mode 100755 index 24c506fa3b4..00000000000 --- a/hack/makefile_sources +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")/.." -discovered=$(mktemp -t discovered_XXXXXX) -recorded=$(mktemp -t recorded_XXXXXX) -addlist=$(mktemp -t need_to_add_XXXXXX) -# SOURCES in the top-level Makefile is more or less the dependencies of our -# "imagebuildah" package, so look for things that we depend on that aren't -# listed therein. -ls -1 $(go list -deps "${@:-./imagebuildah}" | grep ^github.com/containers/buildah | sed -r -e 's,$,/*.go,' -e 's,^github.com/containers/buildah/?,,') | sort -u > "$discovered" -ls -1 $(grep ^SOURCES Makefile | sed -e 's,.*=,,' ) | sort -u > "$recorded" -# Filter for things that are missing, since some of the platform-specific -# packages are going to be dropped on this particular platform, but we still -# want to list them as dependencies. -diff "$recorded" "$discovered" | grep '^>' | cut -c 3- | xargs -r dirname > "$addlist" -if test -s "$addlist"; then - echo The \"SOURCES\" definition in the top-level Makefile is missing these patterns: - sed -e 's,$,/*.go,' "$addlist" - exit 1 -fi -exit 0