Make 'make clean' not depend on genfiles metadata

Previously even 'make clean' would first produce dependency information (slow)
and sinclude all the metadata, possibly restarting the make, before removing
the things it just did.

Now dependencies are only processed when something explicitly depends on them,
by calling 'make' on the rules around generated files, rather than sincluding
them.

Net result: make clean is faster and safer.  Additionally, bash tab-completion
for 'make' does not run the slow 'find' any more.
This commit is contained in:
Tim Hockin 2016-07-19 20:47:36 -07:00
parent 5930c57378
commit 5315fd6786
2 changed files with 39 additions and 23 deletions

View File

@ -14,7 +14,7 @@
DBG_MAKEFILE ?=
ifeq ($(DBG_MAKEFILE),1)
$(warning ***** starting makefile for goal(s) "$(MAKECMDGOALS)")
$(warning ***** starting Makefile for goal(s) "$(MAKECMDGOALS)")
$(warning ***** $(shell date))
else
# If we're not debugging the Makefile, don't echo recipes.
@ -29,7 +29,7 @@ endif
# test: Run tests.
# clean: Clean up.
# It's necessary to set this because some docker images don't make sh -> bash.
# It's necessary to set this because some environments don't link sh -> bash.
SHELL := /bin/bash
# We don't need make's built-in rules.
@ -37,16 +37,17 @@ MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
# Constants used throughout.
.EXPORT_ALL_VARIABLES:
OUT_DIR ?= _output
BIN_DIR := $(OUT_DIR)/bin
PRJ_SRC_PATH := k8s.io/kubernetes
GENERATED_FILE_PREFIX := zz_generated.
# Metadata for driving the build lives here.
META_DIR := .make
export KUBE_GOFLAGS := $(GOFLAGS)
export KUBE_GOLDFLAGS := $(GOLDFLAGS)
KUBE_GOFLAGS := $(GOFLAGS)
KUBE_GOLDFLAGS := $(GOLDFLAGS)
# Build code.
#
@ -184,6 +185,14 @@ clean: clean_meta
clean_meta:
rm -rf $(META_DIR)
# Remove all auto-generated artifacts.
#
# Example:
# make clean_generated
.PHONY: clean_generated
clean_generated:
find . -type f -name $(GENERATED_FILE_PREFIX)\* | xargs rm -f
# Run 'go vet'.
#
# Args:
@ -230,5 +239,10 @@ cross:
$(notdir $(abspath $(wildcard cmd/*/))): generated_files
hack/make-rules/build.sh cmd/$@
# Include logic for generated files.
include Makefile.generated_files
# Produce auto-generated files needed for the build.
#
# Example:
# make generated_files
.PHONY: generated_files
generated_files:
$(MAKE) -f Makefile.$@ $@

View File

@ -12,8 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Constants used throughout.
GENERATED_FILE_PREFIX := zz_generated.
# Don't allow an implicit 'all' rule. This is not a user-facing file.
ifeq ($(MAKECMDGOALS),)
$(error This Makefile requires an explicit rule to be specified)
endif
ifeq ($(DBG_MAKEFILE),1)
$(warning ***** starting Makefile.generated_files for goal(s) "$(MAKECMDGOALS)")
$(warning ***** $(shell date))
endif
# It's necessary to set this because some environments don't link sh -> bash.
SHELL := /bin/bash
# This rule collects all the generated file sets into a single rule. Other
# rules should depend on this to ensure generated files are rebuilt.
.PHONY: generated_files
generated_files: gen_deepcopy gen_conversion
# Code-generation logic.
#
@ -455,17 +471,3 @@ sinclude $(META_DIR)/$(CONVERSION_GEN).mk
$(CONVERSION_GEN):
hack/make-rules/build.sh cmd/libs/go2idl/conversion-gen
touch $@
# This rule collects all the generated file sets into a single dep, which is
# defined BELOW the *_FILES variables and leaves higher-level rules clean.
# Top-level rules should depend on this to ensure generated files are rebuilt.
.PHONY: generated_files
generated_files: gen_deepcopy gen_conversion
# Remove all auto-generated artifacts.
#
# Example:
# make clean_generated
.PHONY: clean_generated
clean_generated:
find . -type f -name $(GENERATED_FILE_PREFIX)\* | xargs rm -f