Debian Codegraph @

Makefile-plugins.mk

raw
1 # Copyright 2022 The Kubernetes Authors.
2 # SPDX-License-Identifier: Apache-2.0
3
4 ### Kustomize plugin rules.
5 #
6 # The rules to deal with builtin plugins are a bit
7 # complicated because
8 #
9 # - Every builtin plugin is a Go plugin -
10 # meaning it gets its own module directory
11 # (outside of the api module) with Go
12 # code in a 'main' package per Go plugin rules.
13 # - kustomize locates plugins using the
14 # 'apiVersion' and 'kind' fields from the
15 # plugin config file.
16 # - k8s wants CamelCase in 'kind' fields.
17 # - The module name (the last name in the path)
18 # must be the lowercased 'kind' of the
19 # plugin because Go and related tools
20 # demand lowercase in import paths, but
21 # allow CamelCase in file names.
22 # - the generated code must live in the api
23 # module (it's linked into the api).
24
25 # Where all generated builtin plugin code should go.
26 pGen=api/internal/builtins
27 # Where the builtin Go plugin modules live.
28 pSrc=plugin/builtin
29
30 _builtinplugins = \
31 AnnotationsTransformer.go \
32 ConfigMapGenerator.go \
33 IAMPolicyGenerator.go \
34 HashTransformer.go \
35 ImageTagTransformer.go \
36 LabelTransformer.go \
37 SortOrderTransformer.go \
38 NamespaceTransformer.go \
39 PatchJson6902Transformer.go \
40 PatchStrategicMergeTransformer.go \
41 PatchTransformer.go \
42 PrefixTransformer.go \
43 SuffixTransformer.go \
44 ReplacementTransformer.go \
45 ReplicaCountTransformer.go \
46 SecretGenerator.go \
47 ValueAddTransformer.go \
48 HelmChartInflationGenerator.go
49
50 # Maintaining this explicit list of generated files, and
51 # adding it as a dependency to a few targets, to assure
52 # they get recreated if deleted. The rules below on how
53 # to make them don't, by themselves, assure they will be
54 # recreated if deleted.
55 builtinplugins = $(patsubst %,$(pGen)/%,$(_builtinplugins))
56
57 # These rules are verbose, but assure that if a source file
58 # is modified, the corresponding generated file, and only
59 # that file, will be recreated.
60 $(pGen)/AnnotationsTransformer.go: $(pSrc)/annotationstransformer/AnnotationsTransformer.go
61 $(pGen)/ConfigMapGenerator.go: $(pSrc)/configmapgenerator/ConfigMapGenerator.go
62 $(pGen)/GkeSaGenerator.go: $(pSrc)/gkesagenerator/GkeSaGenerator.go
63 $(pGen)/HashTransformer.go: $(pSrc)/hashtransformer/HashTransformer.go
64 $(pGen)/ImageTagTransformer.go: $(pSrc)/imagetagtransformer/ImageTagTransformer.go
65 $(pGen)/LabelTransformer.go: $(pSrc)/labeltransformer/LabelTransformer.go
66 $(pGen)/SortOrderTransformer.go: $(pSrc)/sortordertransformer/SortOrderTransformer.go
67 $(pGen)/NamespaceTransformer.go: $(pSrc)/namespacetransformer/NamespaceTransformer.go
68 $(pGen)/PatchJson6902Transformer.go: $(pSrc)/patchjson6902transformer/PatchJson6902Transformer.go
69 $(pGen)/PatchStrategicMergeTransformer.go: $(pSrc)/patchstrategicmergetransformer/PatchStrategicMergeTransformer.go
70 $(pGen)/PatchTransformer.go: $(pSrc)/patchtransformer/PatchTransformer.go
71 $(pGen)/PrefixTransformer.go: $(pSrc)/prefixtransformer/PrefixTransformer.go
72 $(pGen)/SuffixTransformer.go: $(pSrc)/suffixtransformer/SuffixTransformer.go
73 $(pGen)/ReplacementTransformer.go: $(pSrc)/replacementtransformer/ReplacementTransformer.go
74 $(pGen)/ReplicaCountTransformer.go: $(pSrc)/replicacounttransformer/ReplicaCountTransformer.go
75 $(pGen)/SecretGenerator.go: $(pSrc)/secretgenerator/SecretGenerator.go
76 $(pGen)/ValueAddTransformer.go: $(pSrc)/valueaddtransformer/ValueAddTransformer.go
77 $(pGen)/HelmChartInflationGenerator.go: $(pSrc)/helmchartinflationgenerator/HelmChartInflationGenerator.go
78
79 # The (verbose but portable) Makefile way to convert to lowercase.
80 toLowerCase = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
81
82 $(pGen)/%.go: $(MYGOBIN)/pluginator $(MYGOBIN)/goimports
83 @echo "generating $*"
84 ( \
85 set -e; \
86 cd $(pSrc)/$(call toLowerCase,$*); \
87 go generate .; \
88 cd ../../../$(pGen); \
89 $(MYGOBIN)/goimports -w $*.go \
90 )
91
92 # Generate builtin plugins
93 .PHONY: generate-kustomize-builtin-plugins
94 generate-kustomize-builtin-plugins: $(builtplugins)
95 for plugin in $(abspath $(wildcard $(pSrc)/*)); do \
96 echo "generating $${plugin} ..."; \
97 set -e; \
98 cd $${plugin}; \
99 go generate .; \
100 done
101
102 # Check for diff by comparing current revision of generated plugins on HEAD and newly generated plugins on local branch,
103 # If diff is found, throw error code 1
104 .PHONY: builtin-plugins-diff
105 builtin-plugins-diff: $(builtplugins)
106 for file in $(abspath $(builtinplugins)); do \
107 echo "Checking for diff... $${file}" ; \
108 set -e ; \
109 if [ "`git diff $${file} | wc -c`" -gt 0 ]; then\
110 echo "Error(1): diff found on $${file}"; \
111 git diff $${file};\
112 exit 1;\
113 fi \
114 done
115
116 .PHONY: build-kustomize-external-go-plugin
117 build-kustomize-external-go-plugin:
118 ./hack/buildExternalGoPlugins.sh ./plugin
119
120 .PHONY: clean-kustomize-external-go-plugin
121 clean-kustomize-external-go-plugin:
122 ./hack/buildExternalGoPlugins.sh ./plugin clean