Skip to content

Commit e93bbed

Browse files
committed
Verify generated files
1 parent bef915d commit e93bbed

File tree

2 files changed

+97
-36
lines changed

2 files changed

+97
-36
lines changed

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ginkgo:
9595
# make verify
9696
# make verify BRANCH=branch_x
9797
.PHONY: verify
98-
verify:
98+
verify: verify_generated_files
9999
KUBE_VERIFY_GIT_BRANCH=$(BRANCH) hack/make-rules/verify.sh -v
100100
hack/make-rules/vet.sh
101101

@@ -284,4 +284,12 @@ $(notdir $(abspath $(wildcard federation/cmd/*/))): generated_files
284284
# make generated_files
285285
.PHONY: generated_files
286286
generated_files:
287-
$(MAKE) -f Makefile.$@ $@ CALLED_FROM_MAIN_MAKEFILE=1
287+
$(MAKE) -f Makefile.generated_files $@ CALLED_FROM_MAIN_MAKEFILE=1
288+
289+
# Verify auto-generated files needed for the build.
290+
#
291+
# Example:
292+
# make verify_generated_files
293+
.PHONY: verify_generated_files
294+
verify_generated_files:
295+
$(MAKE) -f Makefile.generated_files $@ CALLED_FROM_MAIN_MAKEFILE=1

Makefile.generated_files

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ SHELL := /bin/bash
3737
.PHONY: generated_files
3838
generated_files: gen_deepcopy gen_defaulter gen_conversion gen_openapi
3939

40+
.PHONY: verify_generated_files
41+
verify_generated_files: verify_gen_deepcopy \
42+
verify_gen_defaulter \
43+
verify_gen_conversion \
44+
verify_gen_openapi
45+
4046
# Code-generation logic.
4147
#
4248
# This stuff can be pretty tricky, and there's probably some corner cases that
@@ -209,18 +215,30 @@ DEEPCOPY_DIRS := $(shell \
209215
)
210216
DEEPCOPY_FILES := $(addsuffix /$(DEEPCOPY_FILENAME), $(DEEPCOPY_DIRS))
211217

218+
# Shell function for reuse in rules.
219+
RUN_GEN_DEEPCOPY = \
220+
function run_gen_deepcopy() { \
221+
if [[ -f $(META_DIR)/$(DEEPCOPY_GEN).todo ]]; then \
222+
./hack/run-in-gopath.sh $(DEEPCOPY_GEN) \
223+
--v $(KUBE_VERBOSE) \
224+
--logtostderr \
225+
-i $$(cat $(META_DIR)/$(DEEPCOPY_GEN).todo | paste -sd, -) \
226+
--bounding-dirs $(PRJ_SRC_PATH) \
227+
-O $(DEEPCOPY_BASENAME) \
228+
"$$@"; \
229+
fi \
230+
}; \
231+
run_gen_deepcopy
232+
212233
# This rule aggregates the set of files to generate and then generates them all
213234
# in a single run of the tool.
214235
.PHONY: gen_deepcopy
215-
gen_deepcopy: $(DEEPCOPY_FILES)
216-
if [[ -f $(META_DIR)/$(DEEPCOPY_GEN).todo ]]; then \
217-
./hack/run-in-gopath.sh $(DEEPCOPY_GEN) \
218-
--v $(KUBE_VERBOSE) \
219-
--logtostderr \
220-
-i $$(cat $(META_DIR)/$(DEEPCOPY_GEN).todo | paste -sd, -) \
221-
--bounding-dirs $(PRJ_SRC_PATH) \
222-
-O $(DEEPCOPY_BASENAME); \
223-
fi
236+
gen_deepcopy: $(DEEPCOPY_FILES) $(DEEPCOPY_GEN)
237+
$(RUN_GEN_DEEPCOPY)
238+
239+
.PHONY: verify_gen_deepcopy
240+
verify_gen_deepcopy: $(DEEPCOPY_GEN)
241+
$(RUN_GEN_DEEPCOPY) --verify-only
224242

225243
# For each dir in DEEPCOPY_DIRS, this establishes a dependency between the
226244
# output file and the input files that should trigger a rebuild.
@@ -323,18 +341,29 @@ DEFAULTER_DIRS := $(shell \
323341

324342
DEFAULTER_FILES := $(addsuffix /$(DEFAULTER_FILENAME), $(DEFAULTER_DIRS))
325343

344+
RUN_GEN_DEFAULTER := \
345+
function run_gen_defaulter() { \
346+
if [[ -f $(META_DIR)/$(DEFAULTER_GEN).todo ]]; then \
347+
./hack/run-in-gopath.sh $(DEFAULTER_GEN) \
348+
--v $(KUBE_VERBOSE) \
349+
--logtostderr \
350+
-i $$(cat $(META_DIR)/$(DEFAULTER_GEN).todo | paste -sd, -) \
351+
--extra-peer-dirs $$(echo $(addprefix $(PRJ_SRC_PATH)/, $(DEFAULTER_DIRS)) | sed 's/ /,/g') \
352+
-O $(DEFAULTER_BASENAME) \
353+
"$$@"; \
354+
fi \
355+
}; \
356+
run_gen_defaulter
357+
326358
# This rule aggregates the set of files to generate and then generates them all
327359
# in a single run of the tool.
328360
.PHONY: gen_defaulter
329-
gen_defaulter: $(DEFAULTER_FILES)
330-
if [[ -f $(META_DIR)/$(DEFAULTER_GEN).todo ]]; then \
331-
./hack/run-in-gopath.sh $(DEFAULTER_GEN) \
332-
--v $(KUBE_VERBOSE) \
333-
--logtostderr \
334-
-i $$(cat $(META_DIR)/$(DEFAULTER_GEN).todo | paste -sd, -) \
335-
--extra-peer-dirs $$(echo $(addprefix $(PRJ_SRC_PATH)/, $(DEFAULTER_DIRS)) | sed 's/ /,/g') \
336-
-O $(DEFAULTER_BASENAME); \
337-
fi
361+
gen_defaulter: $(DEFAULTER_FILES) $(DEFAULTER_GEN)
362+
$(RUN_GEN_DEFAULTER)
363+
364+
.PHONY: verify_gen_deepcopy
365+
verify_gen_defaulter: $(DEFAULTER_GEN)
366+
$(RUN_GEN_DEFAULTER) --verify-only
338367

339368
# For each dir in DEFAULTER_DIRS, this establishes a dependency between the
340369
# output file and the input files that should trigger a rebuild.
@@ -453,9 +482,26 @@ OPENAPI_DIRS := $(shell \
453482

454483
OPENAPI_OUTFILE := $(OPENAPI_OUTPUT_PKG)/$(OPENAPI_FILENAME)
455484

485+
# Shell function for reuse in rules.
486+
RUN_GEN_OPENAPI = \
487+
function run_gen_openapi() { \
488+
./hack/run-in-gopath.sh $(OPENAPI_GEN) \
489+
--v $(KUBE_VERBOSE) \
490+
--logtostderr \
491+
-i $$(echo $(addprefix $(PRJ_SRC_PATH)/, $(OPENAPI_DIRS)) | sed 's/ /,/g') \
492+
-p $(PRJ_SRC_PATH)/$(OPENAPI_OUTPUT_PKG) \
493+
-O $(OPENAPI_BASENAME) \
494+
"$$@"; \
495+
}; \
496+
run_gen_openapi
497+
456498
# This rule is the user-friendly entrypoint for openapi generation.
457499
.PHONY: gen_openapi
458-
gen_openapi: $(OPENAPI_OUTFILE)
500+
gen_openapi: $(OPENAPI_OUTFILE) $(OPENAPI_GEN)
501+
502+
.PHONY: verify_gen_openapi
503+
verify_gen_openapi: $(OPENAPI_GEN)
504+
$(RUN_GEN_OPENAPI) --verify-only
459505

460506
# For each dir in OPENAPI_DIRS, this establishes a dependency between the
461507
# output file and the input files that should trigger a rebuild.
@@ -475,13 +521,8 @@ $(foreach dir, $(OPENAPI_DIRS), $(eval \
475521
))
476522

477523
# How to regenerate open-api code. This emits a single file for all results.
478-
$(OPENAPI_OUTFILE): $(OPENAPI_GEN)
479-
./hack/run-in-gopath.sh $(OPENAPI_GEN) \
480-
--v $(KUBE_VERBOSE) \
481-
--logtostderr \
482-
-i $$(echo $(addprefix $(PRJ_SRC_PATH)/, $(OPENAPI_DIRS)) | sed 's/ /,/g') \
483-
-p $(PRJ_SRC_PATH)/$(OPENAPI_OUTPUT_PKG) \
484-
-O $(OPENAPI_BASENAME)
524+
$(OPENAPI_OUTFILE): $(OPENAPI_GEN) $(OPENAPI_GEN)
525+
$(RUN_GEN_OPENAPI)
485526

486527
# This calculates the dependencies for the generator tool, so we only rebuild
487528
# it when needed. It is PHONY so that it always runs, but it only updates the
@@ -560,17 +601,29 @@ CONVERSION_DIRS := $(shell \
560601

561602
CONVERSION_FILES := $(addsuffix /$(CONVERSION_FILENAME), $(CONVERSION_DIRS))
562603

604+
# Shell function for reuse in rules.
605+
RUN_GEN_CONVERSION = \
606+
function run_gen_conversion() { \
607+
if [[ -f $(META_DIR)/$(CONVERSION_GEN).todo ]]; then \
608+
./hack/run-in-gopath.sh $(CONVERSION_GEN) \
609+
--v $(KUBE_VERBOSE) \
610+
--logtostderr \
611+
-i $$(cat $(META_DIR)/$(CONVERSION_GEN).todo | paste -sd, -) \
612+
-O $(CONVERSION_BASENAME) \
613+
"$$@"; \
614+
fi \
615+
}; \
616+
run_gen_conversion
617+
563618
# This rule aggregates the set of files to generate and then generates them all
564619
# in a single run of the tool.
565620
.PHONY: gen_conversion
566-
gen_conversion: $(CONVERSION_FILES)
567-
if [[ -f $(META_DIR)/$(CONVERSION_GEN).todo ]]; then \
568-
./hack/run-in-gopath.sh $(CONVERSION_GEN) \
569-
--v $(KUBE_VERBOSE) \
570-
--logtostderr \
571-
-i $$(cat $(META_DIR)/$(CONVERSION_GEN).todo | paste -sd, -) \
572-
-O $(CONVERSION_BASENAME); \
573-
fi
621+
gen_conversion: $(CONVERSION_FILES) $(CONVERSION_GEN)
622+
$(RUN_GEN_CONVERSION)
623+
624+
.PHONY: verify_gen_conversion
625+
verify_gen_conversion: $(CONVERSION_GEN)
626+
$(RUN_GEN_CONVERSION) --verify-only
574627

575628
# Establish a dependency between the deps file and the dir. Whenever a dir
576629
# changes (files added or removed) the deps file will be considered stale.

0 commit comments

Comments
 (0)