Makefile.generated_files 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. # Copyright 2016 The Kubernetes Authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Don't allow users to call this directly. There are too many variables this
  15. # assumes to inherit from the main Makefile. This is not a user-facing file.
  16. ifeq ($(CALLED_FROM_MAIN_MAKEFILE),)
  17. $(error Please use the main Makefile, e.g. `make generated_files`)
  18. endif
  19. # Don't allow an implicit 'all' rule. This is not a user-facing file.
  20. ifeq ($(MAKECMDGOALS),)
  21. $(error This Makefile requires an explicit rule to be specified)
  22. endif
  23. ifeq ($(DBG_MAKEFILE),1)
  24. $(warning ***** starting Makefile.generated_files for goal(s) "$(MAKECMDGOALS)")
  25. $(warning ***** $(shell date))
  26. endif
  27. # It's necessary to set this because some environments don't link sh -> bash.
  28. SHELL := /bin/bash
  29. # This rule collects all the generated file sets into a single rule. Other
  30. # rules should depend on this to ensure generated files are rebuilt.
  31. .PHONY: generated_files
  32. generated_files: gen_deepcopy gen_defaulter gen_conversion gen_openapi gen_bindata
  33. #
  34. # Helper logic to calculate Go's dependency DAG ourselves.
  35. #
  36. # This is a file that will be emitted by the go2make tool, containing a
  37. # variable for each Go package in the project (including deps) which lists all
  38. # of the transitive deps of that package. Each variable is named the same as
  39. # the package - for example the variable for `k8s.io/kubernetes/pkg/api` is
  40. # $(k8s.io/kubernetes/pkg/api). This is roughly the same DAG that the Go
  41. # compiler uses. These variables can be used to figure out if, for example,
  42. # generated code needs to be regenerated.
  43. GO_PKGDEPS_FILE = go-pkgdeps.mk
  44. # Include the Go package dependencies file. This will cause the rule of
  45. # the same name to be considered and if it is updated, make will restart and
  46. # reload the updated deps.
  47. sinclude $(META_DIR)/$(GO_PKGDEPS_FILE)
  48. # Update the set of Go deps for our project. This will let us determine if
  49. # we really need to do expensive codegen. We use FORCE because it is not a
  50. # PHONY file, but we do want it to be re-evaluated every time make is run. The
  51. # file will only be touched if it actually changes.
  52. $(META_DIR)/$(GO_PKGDEPS_FILE): FORCE
  53. if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
  54. echo "DBG: calculating Go dependencies"; \
  55. fi
  56. hack/run-in-gopath.sh go install ./hack/make-rules/helpers/go2make
  57. hack/run-in-gopath.sh go2make \
  58. k8s.io/kubernetes/... \
  59. --prune k8s.io/kubernetes/staging \
  60. --prune k8s.io/kubernetes/vendor \
  61. k8s.io/kubernetes/vendor/k8s.io/... \
  62. github.com/go-bindata/go-bindata/go-bindata/... \
  63. > $@.tmp
  64. if ! cmp -s $@.tmp $@; then \
  65. if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
  66. echo "DBG: $(GO_PKGDEPS_FILE) changed"; \
  67. fi; \
  68. cat $@.tmp > $@; \
  69. fi
  70. rm -f $@.tmp
  71. .PHONY: FORCE
  72. FORCE:
  73. #
  74. # Helper logic to find which directories need codegen as quickly as possible.
  75. #
  76. # This variable holds a list of every directory that contains Go files in this
  77. # project. Other rules and variables can use this as a starting point to
  78. # reduce filesystem accesses.
  79. ifeq ($(DBG_MAKEFILE),1)
  80. $(warning ***** finding all *.go dirs)
  81. endif
  82. ALL_GO_DIRS := $(shell \
  83. hack/make-rules/helpers/cache_go_dirs.sh $(META_DIR)/all_go_dirs.mk \
  84. )
  85. # Generate a list of all files that have a `+k8s:` comment-tag. This will be
  86. # used to derive lists of files/dirs for generation tools.
  87. ifeq ($(DBG_MAKEFILE),1)
  88. $(warning ***** finding all +k8s: tags)
  89. endif
  90. ALL_K8S_TAG_FILES := $(shell \
  91. find $(ALL_GO_DIRS) -maxdepth 1 -type f -name \*.go \
  92. | xargs grep --color=never -l '^// *+k8s:' \
  93. )
  94. #
  95. # Code generation logic.
  96. #
  97. # Deep-copy generation
  98. #
  99. # Any package that wants deep-copy functions generated must include a
  100. # comment-tag in column 0 of one file of the form:
  101. # // +k8s:deepcopy-gen=<VALUE>
  102. #
  103. # The <VALUE> may be one of:
  104. # generate: generate deep-copy functions into the package
  105. # register: generate deep-copy functions and register them with a
  106. # scheme
  107. # The result file, in each pkg, of deep-copy generation.
  108. DEEPCOPY_BASENAME := $(GENERATED_FILE_PREFIX)deepcopy
  109. DEEPCOPY_FILENAME := $(DEEPCOPY_BASENAME).go
  110. # The tool used to generate deep copies.
  111. DEEPCOPY_GEN := $(BIN_DIR)/deepcopy-gen
  112. # Find all the directories that request deep-copy generation.
  113. ifeq ($(DBG_MAKEFILE),1)
  114. $(warning ***** finding all +k8s:deepcopy-gen tags)
  115. endif
  116. DEEPCOPY_DIRS := $(shell \
  117. grep --color=never -l '+k8s:deepcopy-gen=' $(ALL_K8S_TAG_FILES) \
  118. | xargs -n1 dirname \
  119. | LC_ALL=C sort -u \
  120. )
  121. DEEPCOPY_FILES := $(addsuffix /$(DEEPCOPY_FILENAME), $(DEEPCOPY_DIRS))
  122. # Reset the list of packages that need generation.
  123. $(shell mkdir -p $$(dirname $(META_DIR)/$(DEEPCOPY_GEN)))
  124. $(shell rm -f $(META_DIR)/$(DEEPCOPY_GEN).todo)
  125. # This rule aggregates the set of files to generate and then generates them all
  126. # in a single run of the tool.
  127. .PHONY: gen_deepcopy
  128. gen_deepcopy: $(DEEPCOPY_GEN) $(META_DIR)/$(DEEPCOPY_GEN).todo
  129. if [[ -s $(META_DIR)/$(DEEPCOPY_GEN).todo ]]; then \
  130. pkgs=$$(cat $(META_DIR)/$(DEEPCOPY_GEN).todo | paste -sd, -); \
  131. if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
  132. echo "DBG: running $(DEEPCOPY_GEN) for $$pkgs"; \
  133. fi; \
  134. ./hack/run-in-gopath.sh $(DEEPCOPY_GEN) \
  135. --v $(KUBE_VERBOSE) \
  136. --logtostderr \
  137. -i "$$pkgs" \
  138. --bounding-dirs $(PRJ_SRC_PATH),"k8s.io/api" \
  139. -O $(DEEPCOPY_BASENAME) \
  140. "$$@"; \
  141. fi \
  142. # For each dir in DEEPCOPY_DIRS, this establishes a dependency between the
  143. # output file and the input files that should trigger a rebuild.
  144. #
  145. # Note that this is a deps-only statement, not a full rule (see below). This
  146. # has to be done in a distinct step because wildcards don't work in static
  147. # pattern rules.
  148. #
  149. # The '$(eval)' is needed because this has a different RHS for each LHS, and
  150. # would otherwise produce results that make can't parse.
  151. $(foreach dir, $(DEEPCOPY_DIRS), $(eval \
  152. $(dir)/$(DEEPCOPY_FILENAME): $($(PRJ_SRC_PATH)/$(dir)) \
  153. ))
  154. # How to regenerate deep-copy code. This is a little slow to run, so we batch
  155. # it up and trigger the batch from the 'generated_files' target.
  156. $(META_DIR)/$(DEEPCOPY_GEN).todo: $(DEEPCOPY_FILES)
  157. $(DEEPCOPY_FILES): $(DEEPCOPY_GEN)
  158. if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
  159. echo "DBG: deepcopy needed $(@D):"; \
  160. ls -lf --full-time $@ $? || true; \
  161. fi
  162. echo $(PRJ_SRC_PATH)/$(@D) >> $(META_DIR)/$(DEEPCOPY_GEN).todo
  163. # How to build the generator tool. The deps for this are defined in
  164. # the $(GO_PKGDEPS_FILE), above.
  165. #
  166. # A word on the need to touch: This rule might trigger if, for example, a
  167. # non-Go file was added or deleted from a directory on which this depends.
  168. # This target needs to be reconsidered, but Go realizes it doesn't actually
  169. # have to be rebuilt. In that case, make will forever see the dependency as
  170. # newer than the binary, and try to "rebuild" it over and over. So we touch
  171. # it, and make is happy.
  172. $(DEEPCOPY_GEN): $(k8s.io/kubernetes/vendor/k8s.io/code-generator/cmd/deepcopy-gen)
  173. KUBE_BUILD_PLATFORMS="" hack/make-rules/build.sh ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
  174. touch $@
  175. # Defaulter generation
  176. #
  177. # Any package that wants defaulter functions generated must include a
  178. # comment-tag in column 0 of one file of the form:
  179. # // +k8s:defaulter-gen=<VALUE>
  180. #
  181. # The <VALUE> depends on context:
  182. # on types:
  183. # true: always generate a defaulter for this type
  184. # false: never generate a defaulter for this type
  185. # on functions:
  186. # covers: if the function name matches SetDefault_NAME, instructs
  187. # the generator not to recurse
  188. # on packages:
  189. # FIELDNAME: any object with a field of this name is a candidate
  190. # for having a defaulter generated
  191. # The result file, in each pkg, of defaulter generation.
  192. DEFAULTER_BASENAME := $(GENERATED_FILE_PREFIX)defaults
  193. DEFAULTER_FILENAME := $(DEFAULTER_BASENAME).go
  194. # The tool used to generate defaulters.
  195. DEFAULTER_GEN := $(BIN_DIR)/defaulter-gen
  196. # All directories that request any form of defaulter generation.
  197. ifeq ($(DBG_MAKEFILE),1)
  198. $(warning ***** finding all +k8s:defaulter-gen tags)
  199. endif
  200. DEFAULTER_DIRS := $(shell \
  201. grep --color=never -l '+k8s:defaulter-gen=' $(ALL_K8S_TAG_FILES) \
  202. | xargs -n1 dirname \
  203. | LC_ALL=C sort -u \
  204. )
  205. DEFAULTER_FILES := $(addsuffix /$(DEFAULTER_FILENAME), $(DEFAULTER_DIRS))
  206. # Reset the list of packages that need generation.
  207. $(shell mkdir -p $$(dirname $(META_DIR)/$(DEFAULTER_GEN)))
  208. $(shell rm -f $(META_DIR)/$(DEFAULTER_GEN).todo)
  209. # This rule aggregates the set of files to generate and then generates them all
  210. # in a single run of the tool.
  211. .PHONY: gen_defaulter
  212. gen_defaulter: $(DEFAULTER_GEN) $(META_DIR)/$(DEFAULTER_GEN).todo
  213. if [[ -s $(META_DIR)/$(DEFAULTER_GEN).todo ]]; then \
  214. pkgs=$$(cat $(META_DIR)/$(DEFAULTER_GEN).todo | paste -sd, -); \
  215. if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
  216. echo "DBG: running $(DEFAULTER_GEN) for $$pkgs"; \
  217. fi; \
  218. ./hack/run-in-gopath.sh $(DEFAULTER_GEN) \
  219. --v $(KUBE_VERBOSE) \
  220. --logtostderr \
  221. -i "$$pkgs" \
  222. --extra-peer-dirs $$(echo $(addprefix $(PRJ_SRC_PATH)/, $(DEFAULTER_DIRS)) | sed 's/ /,/g') \
  223. -O $(DEFAULTER_BASENAME) \
  224. "$$@"; \
  225. fi
  226. # For each dir in DEFAULTER_DIRS, this establishes a dependency between the
  227. # output file and the input files that should trigger a rebuild.
  228. #
  229. # Note that this is a deps-only statement, not a full rule (see below for that).
  230. #
  231. # The '$(eval)' is needed because this has a different RHS for each LHS, and
  232. # would otherwise produce results that make can't parse.
  233. $(foreach dir, $(DEFAULTER_DIRS), $(eval \
  234. $(dir)/$(DEFAULTER_FILENAME): $($(PRJ_SRC_PATH)/$(dir)) \
  235. ))
  236. # How to regenerate defaulter code. This is a little slow to run, so we batch
  237. # it up and trigger the batch from the 'generated_files' target.
  238. $(META_DIR)/$(DEFAULTER_GEN).todo: $(DEFAULTER_FILES)
  239. $(DEFAULTER_FILES): $(DEFAULTER_GEN)
  240. if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
  241. echo "DBG: defaulter needed $(@D):"; \
  242. ls -lf --full-time $@ $? || true; \
  243. fi
  244. echo $(PRJ_SRC_PATH)/$(@D) >> $(META_DIR)/$(DEFAULTER_GEN).todo
  245. # How to build the generator tool. The deps for this are defined in
  246. # the $(GO_PKGDEPS_FILE), above.
  247. #
  248. # A word on the need to touch: This rule might trigger if, for example, a
  249. # non-Go file was added or deleted from a directory on which this depends.
  250. # This target needs to be reconsidered, but Go realizes it doesn't actually
  251. # have to be rebuilt. In that case, make will forever see the dependency as
  252. # newer than the binary, and try to "rebuild" it over and over. So we touch
  253. # it, and make is happy.
  254. $(DEFAULTER_GEN): $(k8s.io/kubernetes/vendor/k8s.io/code-generator/cmd/defaulter-gen)
  255. KUBE_BUILD_PLATFORMS="" hack/make-rules/build.sh ./vendor/k8s.io/code-generator/cmd/defaulter-gen
  256. touch $@
  257. # Conversion generation
  258. # Any package that wants conversion functions generated into it must
  259. # include one or more comment-tags in its `doc.go` file, of the form:
  260. # // +k8s:conversion-gen=<INTERNAL_TYPES_DIR>
  261. #
  262. # The INTERNAL_TYPES_DIR is a project-local path to another directory
  263. # which should be considered when evaluating peer types for
  264. # conversions. An optional additional comment of the form
  265. # // +k8s:conversion-gen-external-types=<EXTERNAL_TYPES_DIR>
  266. #
  267. # identifies where to find the external types; if there is no such
  268. # comment then the external types are sought in the package where the
  269. # `k8s:conversion` tag is found.
  270. #
  271. # Conversions, in both directions, are generated for every type name
  272. # that is defined in both an internal types package and the external
  273. # types package.
  274. #
  275. # TODO: it might be better in the long term to make peer-types explicit in the
  276. # IDL.
  277. # The result file, in each pkg, of conversion generation.
  278. CONVERSION_BASENAME := $(GENERATED_FILE_PREFIX)conversion
  279. CONVERSION_FILENAME := $(CONVERSION_BASENAME).go
  280. # The tool used to generate conversions.
  281. CONVERSION_GEN := $(BIN_DIR)/conversion-gen
  282. # The name of the metadata file listing conversion peers for each pkg.
  283. CONVERSIONS_META := conversions.mk
  284. # All directories that request any form of conversion generation.
  285. ifeq ($(DBG_MAKEFILE),1)
  286. $(warning ***** finding all +k8s:conversion-gen tags)
  287. endif
  288. CONVERSION_DIRS := $(shell \
  289. grep --color=never '^// *+k8s:conversion-gen=' $(ALL_K8S_TAG_FILES) \
  290. | cut -f1 -d: \
  291. | xargs -n1 dirname \
  292. | LC_ALL=C sort -u \
  293. )
  294. CONVERSION_FILES := $(addsuffix /$(CONVERSION_FILENAME), $(CONVERSION_DIRS))
  295. CONVERSION_EXTRA_PEER_DIRS := k8s.io/kubernetes/pkg/apis/core,k8s.io/kubernetes/pkg/apis/core/v1,k8s.io/api/core/v1
  296. # Reset the list of packages that need generation.
  297. $(shell mkdir -p $$(dirname $(META_DIR)/$(CONVERSION_GEN)))
  298. $(shell rm -f $(META_DIR)/$(CONVERSION_GEN).todo)
  299. # This rule aggregates the set of files to generate and then generates them all
  300. # in a single run of the tool.
  301. .PHONY: gen_conversion
  302. gen_conversion: $(CONVERSION_GEN) $(META_DIR)/$(CONVERSION_GEN).todo
  303. if [[ -s $(META_DIR)/$(CONVERSION_GEN).todo ]]; then \
  304. pkgs=$$(cat $(META_DIR)/$(CONVERSION_GEN).todo | paste -sd, -); \
  305. if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
  306. echo "DBG: running $(CONVERSION_GEN) for $$pkgs"; \
  307. fi; \
  308. ./hack/run-in-gopath.sh $(CONVERSION_GEN) \
  309. --extra-peer-dirs $(CONVERSION_EXTRA_PEER_DIRS) \
  310. --v $(KUBE_VERBOSE) \
  311. --logtostderr \
  312. -i "$$pkgs" \
  313. -O $(CONVERSION_BASENAME) \
  314. "$$@"; \
  315. fi
  316. # For each dir in CONVERSION_DIRS, this establishes a dependency between the
  317. # output file and the input files that should trigger a rebuild.
  318. #
  319. # Note that this is a deps-only statement, not a full rule (see below for that).
  320. #
  321. # The '$(eval)' is needed because this has a different RHS for each LHS, and
  322. # would otherwise produce results that make can't parse.
  323. $(foreach dir, $(CONVERSION_DIRS), $(eval \
  324. $(dir)/$(CONVERSION_FILENAME): $($(PRJ_SRC_PATH)/$(dir)) \
  325. ))
  326. # How to regenerate conversion code. This is a little slow to run, so we batch
  327. # it up and trigger the batch from the 'generated_files' target.
  328. $(META_DIR)/$(CONVERSION_GEN).todo: $(CONVERSION_FILES)
  329. $(CONVERSION_FILES): $(CONVERSION_GEN)
  330. if [[ "$(DBG_CODEGEN)" == 1 ]]; then \
  331. echo "DBG: conversion needed $(@D):"; \
  332. ls -lf --full-time $@ $? || true; \
  333. fi
  334. echo $(PRJ_SRC_PATH)/$(@D) >> $(META_DIR)/$(CONVERSION_GEN).todo
  335. # How to build the generator tool. The deps for this are defined in
  336. # the $(GO_PKGDEPS_FILE), above.
  337. #
  338. # A word on the need to touch: This rule might trigger if, for example, a
  339. # non-Go file was added or deleted from a directory on which this depends.
  340. # This target needs to be reconsidered, but Go realizes it doesn't actually
  341. # have to be rebuilt. In that case, make will forever see the dependency as
  342. # newer than the binary, and try to rebuild it over and over. So we touch it,
  343. # and make is happy.
  344. $(CONVERSION_GEN): $(k8s.io/kubernetes/vendor/k8s.io/code-generator/cmd/conversion-gen)
  345. KUBE_BUILD_PLATFORMS="" hack/make-rules/build.sh ./vendor/k8s.io/code-generator/cmd/conversion-gen
  346. touch $@
  347. # OpenAPI generation
  348. #
  349. # Any package that wants open-api functions generated must include a
  350. # comment-tag in column 0 of one file of the form:
  351. # // +k8s:openapi-gen=true
  352. #
  353. # The result file, in each pkg, of open-api generation.
  354. OPENAPI_BASENAME := $(GENERATED_FILE_PREFIX)openapi
  355. OPENAPI_FILENAME := $(OPENAPI_BASENAME).go
  356. BOILERPLATE_FILENAME := vendor/k8s.io/code-generator/hack/boilerplate.go.txt
  357. IGNORED_REPORT_FILENAME := $(OUT_DIR)/ignored_violations.report
  358. API_RULE_CHECK_FAILURE_MESSAGE = "ERROR: \n\t $(1) API rule check failed. Reported violations differ from known violations. Please read api/api-rules/README.md to resolve the failure in $(2). \n"
  359. # The tool used to generate open apis.
  360. OPENAPI_GEN := $(BIN_DIR)/openapi-gen
  361. KUBE_KNOWN_VIOLATION_FILENAME := api/api-rules/violation_exceptions.list
  362. APIEXTENSIONS_KNOWN_VIOLATION_FILENAME := api/api-rules/apiextensions_violation_exceptions.list
  363. CODEGEN_KNOWN_VIOLATION_FILENAME := api/api-rules/codegen_violation_exceptions.list
  364. SAMPLEAPISERVER_KNOWN_VIOLATION_FILENAME := api/api-rules/sample_apiserver_violation_exceptions.list
  365. APIMACHINERY_DEFAULT_TAG_FILES := vendor/k8s.io/apimachinery/pkg/apis/meta/v1/% vendor/k8s.io/apimachinery/pkg/runtime/% vendor/k8s.io/apimachinery/pkg/version/%
  366. KUBE_OPENAPI_TAG_FILES := $(filter-out vendor/k8s.io/code-generator/% vendor/k8s.io/sample-apiserver/%, $(ALL_K8S_TAG_FILES))
  367. APIEXTENSIONS_OPENAPI_TAG_FILES := $(filter $(APIMACHINERY_DEFAULT_TAG_FILES) vendor/k8s.io/apiextensions/% vendor/k8s.io/api/autoscaling/v1/%, $(ALL_K8S_TAG_FILES))
  368. CODEGEN_OPENAPI_TAG_FILES := $(filter $(APIMACHINERY_DEFAULT_TAG_FILES) vendor/k8s.io/code-generator/%, $(ALL_K8S_TAG_FILES))
  369. SAMPLEAPISERVER_OPENAPI_TAG_FILES := $(filter $(APIMACHINERY_DEFAULT_TAG_FILES) vendor/k8s.io/sample-apiserver/%, $(ALL_K8S_TAG_FILES))
  370. KUBE_OPENAPI_OUTPUT_PKG := pkg/generated/openapi
  371. APIEXTENSIONS_OPENAPI_OUTPUT_PKG := staging/src/k8s.io/apiextensions-apiserver/pkg/generated/openapi
  372. CODEGEN_OPENAPI_OUTPUT_PKG := staging/src/k8s.io/code-generator/_examples/apiserver/openapi
  373. SAMPLEAPISERVER_OPENAPI_OUTPUT_PKG := staging/src/k8s.io/sample-apiserver/pkg/generated/openapi
  374. OPENAPI_TARGETS := KUBE APIEXTENSIONS CODEGEN SAMPLEAPISERVER
  375. # Find all the directories that request openapi generation.
  376. define OPENAPI_DIR_DEF
  377. ifeq ($$(DBG_MAKEFILE),1)
  378. $$(warning ***** finding all +k8s:openapi-gen tags for $(prefix))
  379. endif
  380. $(prefix)_OPENAPI_DIRS := $(shell \
  381. grep --color=never -l '+k8s:openapi-gen=' $($(prefix)_OPENAPI_TAG_FILES) \
  382. | xargs -n1 dirname \
  383. | LC_ALL=C sort -u \
  384. )
  385. endef
  386. $(foreach prefix, $(OPENAPI_TARGETS), $(eval $(OPENAPI_DIR_DEF)))
  387. # Compute all openapi output file names
  388. $(foreach prefix, $(OPENAPI_TARGETS), $(eval \
  389. $(prefix)_OPENAPI_OUTFILE := $($(prefix)_OPENAPI_OUTPUT_PKG)/$(OPENAPI_FILENAME) \
  390. ))
  391. # For each openapi target compute the spec
  392. define OPENAPI_TARGETS_DEF
  393. # For each dir in $(prefix)_OPENAPI_DIRS, this establishes a dependency
  394. # between the output file and the input files that should trigger a rebuild.
  395. #
  396. # Note that this is a deps-only statement, not a full rule
  397. # (see below for that).
  398. #
  399. # The '$(eval)' is needed because this has a different RHS for each LHS, and
  400. # would otherwise produce results that make can't parse.
  401. $(foreach dir, $($(prefix)_OPENAPI_DIRS), $(eval \
  402. $($(prefix)_OPENAPI_OUTFILE): $($(PRJ_SRC_PATH)/$(dir)) \
  403. ))
  404. # Rebuild spec if the violation file changed.
  405. $($(prefix)_OPENAPI_OUTFILE): $($(prefix)_KNOWN_VIOLATION_FILENAME)
  406. # When UPDATE_API_KNOWN_VIOLATIONS is set to be true, let the generator to write
  407. # updated API violations to the known API violation exceptions list.
  408. ifeq ($(UPDATE_API_KNOWN_VIOLATIONS),true)
  409. $(prefix)_REPORT_FILENAME := $($(prefix)_KNOWN_VIOLATION_FILENAME)
  410. # When UPDATE_API_KNOWN_VIOLATIONS is set to be true, touch the exceptions
  411. # list so that the $(prefix)_OPENAPI_OUTFILE target re-run instead of being cached.
  412. $$(shell touch $($(prefix)_KNOWN_VIOLATION_FILENAME))
  413. else
  414. $(prefix)_REPORT_FILENAME := $(OUT_DIR)/$(prefix)_violations.report
  415. endif
  416. # How to regenerate open-api code. This emits a single file for all results.
  417. # The Make rule fails if generated API rule violation report differs from the
  418. # checked-in violation file, and prints error message to request developer to
  419. # fix either the API source code, or the known API rule violation file.
  420. $$($(prefix)_OPENAPI_OUTFILE): $(OPENAPI_GEN) $($(prefix)_KNOWN_VIOLATION_FILENAME:-)
  421. ./hack/run-in-gopath.sh $(OPENAPI_GEN) \
  422. --v $(KUBE_VERBOSE) \
  423. --logtostderr \
  424. -i $$$$(echo $(addprefix $(PRJ_SRC_PATH)/, $($(prefix)_OPENAPI_DIRS)) | sed 's/ /,/g') \
  425. -p $(PRJ_SRC_PATH)/$($(prefix)_OPENAPI_OUTPUT_PKG) \
  426. -O $(OPENAPI_BASENAME) \
  427. -h $(BOILERPLATE_FILENAME) \
  428. -r $$($(prefix)_REPORT_FILENAME) \
  429. "$$$$@"
  430. test -f $($(prefix)_KNOWN_VIOLATION_FILENAME) || touch $($(prefix)_KNOWN_VIOLATION_FILENAME)
  431. diff $$($(prefix)_REPORT_FILENAME) $($(prefix)_KNOWN_VIOLATION_FILENAME) || \
  432. (echo -e $(call API_RULE_CHECK_FAILURE_MESSAGE,$(prefix),$($(prefix)_KNOWN_VIOLATION_FILENAME)); exit 1)
  433. endef
  434. $(foreach prefix, $(OPENAPI_TARGETS), $(eval $(OPENAPI_TARGETS_DEF)))
  435. # This rule is the user-friendly entrypoint for openapi generation.
  436. .PHONY: gen_openapi
  437. gen_openapi: $(OPENAPI_GEN) $(KUBE_OPENAPI_OUTFILE) $(APIEXTENSIONS_OPENAPI_OUTFILE) $(CODEGEN_OPENAPI_OUTFILE) $(SAMPLEAPISERVER_OPENAPI_OUTFILE)
  438. # How to build the generator tool. The deps for this are defined in
  439. # the $(GO_PKGDEPS_FILE), above.
  440. #
  441. # A word on the need to touch: This rule might trigger if, for example, a
  442. # non-Go file was added or deleted from a directory on which this depends.
  443. # This target needs to be reconsidered, but Go realizes it doesn't actually
  444. # have to be rebuilt. In that case, make will forever see the dependency as
  445. # newer than the binary, and try to "rebuild" it over and over. So we touch
  446. # it, and make is happy.
  447. $(OPENAPI_GEN): $(k8s.io/kubernetes/vendor/k8s.io/kube-openapi/cmd/openapi-gen)
  448. KUBE_BUILD_PLATFORMS="" hack/make-rules/build.sh ./vendor/k8s.io/kube-openapi/cmd/openapi-gen
  449. touch $@
  450. # bindata generation
  451. #
  452. # The tool used to generate bindata files.
  453. BINDATA_GEN := $(BIN_DIR)/go-bindata
  454. # A wrapper script that generates all bindata files. It is fast enough that we
  455. # don't care.
  456. BINDATA_SCRIPT := hack/generate-bindata.sh
  457. # This rule is the user-friendly entrypoint for bindata generation.
  458. .PHONY: gen_bindata
  459. gen_bindata: $(BINDATA_GEN) FORCE
  460. ./hack/run-in-gopath.sh $(BINDATA_SCRIPT)
  461. # How to build the generator tool. The deps for this are defined in
  462. # the $(BINDATA_GEN).mk, above.
  463. #
  464. # A word on the need to touch: This rule might trigger if, for example, a
  465. # non-Go file was added or deleted from a directory on which this depends.
  466. # This target needs to be reconsidered, but Go realizes it doesn't actually
  467. # have to be rebuilt. In that case, make will forever see the dependency as
  468. # newer than the binary, and try to rebuild it over and over. So we touch it,
  469. # and make is happy.
  470. $(BINDATA_GEN): $(k8s.io/kubernetes/vendor/github.com/go-bindata/go-bindata/go-bindata)
  471. KUBE_BUILD_PLATFORMS="" hack/make-rules/build.sh ./vendor/github.com/go-bindata/go-bindata/go-bindata
  472. touch $@