Skip to content

Commit 1c6210a

Browse files
committed
update makefile for prerelease-lifecycle
1 parent 4b0080d commit 1c6210a

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

build/root/Makefile.generated_files

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ SHELL := /bin/bash
3535
# This rule collects all the generated file sets into a single rule. Other
3636
# rules should depend on this to ensure generated files are rebuilt.
3737
.PHONY: generated_files
38-
generated_files: gen_deepcopy gen_defaulter gen_conversion gen_openapi gen_bindata
38+
generated_files: gen_prerelease_lifecycle gen_deepcopy gen_defaulter gen_conversion gen_openapi gen_bindata
3939

4040
#
4141
# Helper logic to calculate Go's dependency DAG ourselves.
@@ -112,6 +112,90 @@ ALL_K8S_TAG_FILES := $(shell \
112112
#
113113

114114

115+
# prerelease-lifecycle generation
116+
#
117+
# Any package that wants prerelease-lifecycle functions generated must include a
118+
# comment-tag in column 0 of one file of the form:
119+
# // +k8s:prerelease-lifecycle-gen=true
120+
#
121+
122+
# The result file, in each pkg, of deep-copy generation.
123+
PRERELEASE_LIFECYCLE_BASENAME := $(GENERATED_FILE_PREFIX)prerelease-lifecycle
124+
PRERELEASE_LIFECYCLE_FILENAME := $(PRERELEASE_LIFECYCLE_BASENAME).go
125+
126+
# The tool used to generate deep copies.
127+
PRERELEASE_LIFECYCLE_GEN := $(BIN_DIR)/prerelease-lifecycle-gen
128+
129+
# Find all the directories that request deep-copy generation.
130+
ifeq ($(DBG_MAKEFILE),1)
131+
$(warning ***** finding all +k8s:prerelease-lifecycle-gen tags)
132+
endif
133+
PRERELEASE_LIFECYCLE_DIRS := $(shell \
134+
grep --color=never -l '+k8s:prerelease-lifecycle-gen=' $(ALL_K8S_TAG_FILES) \
135+
| xargs -n1 dirname \
136+
| LC_ALL=C sort -u \
137+
)
138+
PRERELEASE_LIFECYCLE_FILES := $(addsuffix /$(PRERELEASE_LIFECYCLE_FILENAME), $(PRERELEASE_LIFECYCLE_DIRS))
139+
140+
# Reset the list of packages that need generation.
141+
$(shell mkdir -p $$(dirname $(META_DIR)/$(PRERELEASE_LIFECYCLE_GEN)))
142+
$(shell rm -f $(META_DIR)/$(PRERELEASE_LIFECYCLE_GEN).todo)
143+
144+
# This rule aggregates the set of files to generate and then generates them all
145+
# in a single run of the tool.
146+
.PHONY: gen_prerelease_lifecycle
147+
gen_prerelease_lifecycle: $(PRERELEASE_LIFECYCLE_GEN) $(META_DIR)/$(PRERELEASE_LIFECYCLE_GEN).todo
148+
if [[ -s $(META_DIR)/$(PRERELEASE_LIFECYCLE_GEN).todo ]]; then \
149+
pkgs=$$(cat $(META_DIR)/$(PRERELEASE_LIFECYCLE_GEN).todo | paste -sd, -); \
150+
if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
151+
echo "DBG: running $(PRERELEASE_LIFECYCLE_GEN) for $$pkgs"; \
152+
fi; \
153+
./hack/run-in-gopath.sh $(PRERELEASE_LIFECYCLE_GEN) \
154+
--v $(KUBE_VERBOSE) \
155+
--logtostderr \
156+
-i "$$pkgs" \
157+
-O $(PRERELEASE_LIFECYCLE_BASENAME) \
158+
"$$@"; \
159+
fi \
160+
161+
# For each dir in PRERELEASE_LIFECYCLE_DIRS, this establishes a dependency between the
162+
# output file and the input files that should trigger a rebuild.
163+
#
164+
# Note that this is a deps-only statement, not a full rule (see below). This
165+
# has to be done in a distinct step because wildcards don't work in static
166+
# pattern rules.
167+
#
168+
# The '$(eval)' is needed because this has a different RHS for each LHS, and
169+
# would otherwise produce results that make can't parse.
170+
$(foreach dir, $(PRERELEASE_LIFECYCLE_DIRS), $(eval \
171+
$(dir)/$(PRERELEASE_LIFECYCLE_FILENAME): $($(PRJ_SRC_PATH)/$(dir)) \
172+
))
173+
174+
# How to regenerate deep-copy code. This is a little slow to run, so we batch
175+
# it up and trigger the batch from the 'generated_files' target.
176+
$(META_DIR)/$(PRERELEASE_LIFECYCLE_GEN).todo: $(PRERELEASE_LIFECYCLE_FILES)
177+
178+
$(PRERELEASE_LIFECYCLE_FILES): $(PRERELEASE_LIFECYCLE_GEN)
179+
if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
180+
echo "DBG: prerelease-lifecycle needed $(@D):"; \
181+
ls -lf --full-time $@ $? || true; \
182+
fi
183+
echo $(PRJ_SRC_PATH)/$(@D) >> $(META_DIR)/$(PRERELEASE_LIFECYCLE_GEN).todo
184+
185+
# How to build the generator tool. The deps for this are defined in
186+
# the $(GO_PKGDEPS_FILE), above.
187+
#
188+
# A word on the need to touch: This rule might trigger if, for example, a
189+
# non-Go file was added or deleted from a directory on which this depends.
190+
# This target needs to be reconsidered, but Go realizes it doesn't actually
191+
# have to be rebuilt. In that case, make will forever see the dependency as
192+
# newer than the binary, and try to "rebuild" it over and over. So we touch
193+
# it, and make is happy.
194+
$(PRERELEASE_LIFECYCLE_GEN): $(k8s.io/kubernetes/vendor/k8s.io/code-generator/cmd/prerelease-lifecycle-gen)
195+
KUBE_BUILD_PLATFORMS="" hack/make-rules/build.sh ./vendor/k8s.io/code-generator/cmd/prerelease-lifecycle-gen
196+
touch $@
197+
198+
115199
# Deep-copy generation
116200
#
117201
# Any package that wants deep-copy functions generated must include a

0 commit comments

Comments
 (0)