Skip to content

Commit

Permalink
Make 'make clean' not depend on genfiles metadata
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thockin committed Jul 21, 2016
1 parent 5930c57 commit 5315fd6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
28 changes: 21 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,24 +29,25 @@ 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.
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.
#
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.$@ $@
34 changes: 18 additions & 16 deletions Makefile.generated_files
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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

0 comments on commit 5315fd6

Please sign in to comment.