...

Text file src/github.com/datawire/ambassador/v2/build-aux/generate.mk

Documentation: github.com/datawire/ambassador/v2/build-aux

     1# -*- fill-column: 102 -*-
     2
     3# This file deals with creating files that get checked in to Git.  This is all grouped together in to
     4# one file, rather than being closer to the "subject matter" because this is a heinous thing.  Output
     5# files should not get checked in to Git -- every entry added to to this file is an affront to all
     6# that is good and proper.  As an exception, some of the Envoy-related stuff is allowed to live in
     7# envoy.mk, because that's a whole other bag of gross.
     8
     9#
    10# The main `make generate` entrypoints and listings
    11
    12# - Let $(generate/files) be a listing of all files or directories that `make generate` will create.
    13#
    14# - Let $(generate-fast/files) be the subset of $(generate/files) that can be generated "quickly".  A
    15#   file may NOT be considered fast if it uses the builder container, if it uses the network, or if it
    16#   needs to access the filesystem to evaluate the list of files (as the lines using `$(shell find
    17#   ...)` do).
    18#
    19# - Let $(generate/precious) be the subset of $(generate/files) that should not be deleted prior to
    20#   re-generation.
    21
    22# Initialize
    23generate-fast/files  =
    24generate/files       = $(generate-fast/files)
    25generate/precious    =
    26# Whole directories with rules for each individual file in it
    27generate/files      += $(patsubst $(OSS_HOME)/api/%.proto,                   $(OSS_HOME)/pkg/api/%.pb.go                         , $(shell find $(OSS_HOME)/api/kat/              -name '*.proto')) $(OSS_HOME)/pkg/api/kat/
    28generate/files      += $(patsubst $(OSS_HOME)/api/%.proto,                   $(OSS_HOME)/pkg/api/%_grpc.pb.go                    , $(shell find $(OSS_HOME)/api/kat/              -name '*.proto'))
    29generate/files      += $(patsubst $(OSS_HOME)/api/%.proto,                   $(OSS_HOME)/pkg/api/%.pb.go                         , $(shell find $(OSS_HOME)/api/agent/            -name '*.proto')) $(OSS_HOME)/pkg/api/agent/
    30generate/files      += $(patsubst $(OSS_HOME)/api/%.proto,                   $(OSS_HOME)/pkg/api/%_grpc.pb.go                    , $(shell find $(OSS_HOME)/api/agent/            -name '*.proto'))
    31# Whole directories with one rule for the whole directory
    32generate/files      += $(OSS_HOME)/api/envoy/                # recipe in _cxx/envoy.mk
    33generate/files      += $(OSS_HOME)/api/pb/                   # recipe in _cxx/envoy.mk
    34generate/files      += $(OSS_HOME)/pkg/api/envoy/            # recipe in _cxx/envoy.mk
    35generate/files      += $(OSS_HOME)/pkg/api/pb/               # recipe in _cxx/envoy.mk
    36generate/files      += $(OSS_HOME)/pkg/envoy-control-plane/  # recipe in _cxx/envoy.mk
    37# Individual files: Misc
    38generate/files      += $(OSS_HOME)/DEPENDENCIES.md
    39generate/files      += $(OSS_HOME)/DEPENDENCY_LICENSES.md
    40generate-fast/files += $(OSS_HOME)/CHANGELOG.md
    41generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v1/zz_generated.conversion.go
    42generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v1/zz_generated.conversion-spoke.go
    43generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v2/zz_generated.conversion.go
    44generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v2/zz_generated.conversion-spoke.go
    45generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v3alpha1/zz_generated.conversion-hub.go
    46# Individual files: YAML
    47generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-crds.yaml.in
    48generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-emissaryns.yaml.in
    49generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-defaultns.yaml.in
    50generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-emissaryns-agent.yaml.in
    51generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-defaultns-agent.yaml.in
    52generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-emissaryns-migration.yaml.in
    53generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-defaultns-migration.yaml.in
    54generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/crds.yaml
    55generate-fast/files += $(OSS_HOME)/python/tests/integration/manifests/ambassador.yaml
    56generate-fast/files += $(OSS_HOME)/python/tests/integration/manifests/crds.yaml
    57generate-fast/files += $(OSS_HOME)/python/tests/integration/manifests/rbac_cluster_scope.yaml
    58generate-fast/files += $(OSS_HOME)/python/tests/integration/manifests/rbac_namespace_scope.yaml
    59# Individual files: Test TLS Certificates
    60generate-fast/files += $(OSS_HOME)/docker/test-auth/authsvc.crt
    61generate-fast/files += $(OSS_HOME)/docker/test-auth/authsvc.key
    62generate-fast/files += $(OSS_HOME)/docker/test-shadow/shadowsvc.crt
    63generate-fast/files += $(OSS_HOME)/docker/test-shadow/shadowsvc.key
    64generate-fast/files += $(OSS_HOME)/python/tests/selfsigned.py
    65
    66generate: ## Update generated sources that get committed to Git
    67generate:
    68	$(MAKE) generate-clean
    69# This (generating specific targets early, then having a separate `_generate`) is a hack.  Because the
    70# full value of $(generate/files) is based on the listing of files in $(OSS_HOME)/api/, we need to
    71# make sure that those directories are fully populated before we evaluate the full $(generate/files).
    72	$(MAKE) $(OSS_HOME)/api/envoy $(OSS_HOME)/api/pb
    73	$(MAKE) _generate
    74_generate:
    75	@echo '$(MAKE) $$(generate/files)'; $(MAKE) $(patsubst %/,%,$(generate/files))
    76.PHONY: generate _generate
    77
    78generate-clean: ## Delete generated sources that get committed to Git
    79	rm -rf $(filter-out $(generate/precious),$(generate/files))
    80	find $(OSS_HOME)/pkg/api/getambassador.io -name 'zz_generated.*.go' -print -delete # generated as a side-effect of other files
    81.PHONY: generate-clean
    82
    83generate-fast: ## Update the subset of generated-sources-that-get-committed-to-Git that can be updated quickly
    84generate-fast:
    85	$(MAKE) generate-fast-clean
    86	$(MAKE) $(patsubst %/,%,$(generate-fast/files))
    87.PHONY: generate-fast
    88
    89generate-fast-clean: ## Delete the subset of generated-sources-that-get-committed-to-Git that can be updated quickly
    90	rm -rf $(filter-out $(generate/precious),$(generate-fast/files))
    91	find $(OSS_HOME)/pkg/api/getambassador.io -name 'zz_generated.*.go' -print -delete # generated as a side-effect of other files
    92.PHONY: generate-fast-clean
    93
    94#
    95# Helper Make functions and variables
    96
    97# Usage: $(call joinlist,SEPARATOR,LIST)
    98# Example: $(call joinlist,/,foo bar baz) => foo/bar/baz
    99joinlist=$(if $(word 2,$2),$(firstword $2)$1$(call joinlist,$1,$(wordlist 2,$(words $2),$2)),$2)
   100
   101comma=,
   102
   103gomoddir = $(shell cd $(OSS_HOME); go list -mod=readonly $1/... >/dev/null 2>/dev/null; go list -mod=readonly -m -f='{{.Dir}}' $1)
   104
   105#
   106# `make generate` certificate generation
   107
   108$(OSS_HOME)/docker/test-auth/authsvc.crt: $(tools/testcert-gen)
   109	$(tools/testcert-gen) --out-cert=$@ --out-key=/dev/null --hosts=authsvc.datawire.io
   110$(OSS_HOME)/docker/test-auth/authsvc.key: $(tools/testcert-gen)
   111	$(tools/testcert-gen) --out-cert=/dev/null --out-key=$@ --hosts=authsvc.datawire.io
   112
   113$(OSS_HOME)/docker/test-shadow/shadowsvc.crt: $(tools/testcert-gen)
   114	$(tools/testcert-gen) --out-cert=$@ --out-key=/dev/null --hosts=demosvc.datawire.io
   115$(OSS_HOME)/docker/test-shadow/shadowsvc.key: $(tools/testcert-gen)
   116	$(tools/testcert-gen) --out-cert=/dev/null --out-key=$@ --hosts=demosvc.datawire.io
   117
   118$(OSS_HOME)/python/tests/selfsigned.py: %: %.gen $(tools/testcert-gen)
   119	$@.gen $(tools/testcert-gen) >$@
   120
   121#
   122# `make generate` protobuf rules
   123
   124# proto_path is a list of where to look for .proto files.
   125proto_path += $(OSS_HOME)/api # input files must be within the path
   126
   127# The "M{FOO}={BAR}" options map from .proto files to Go package names.
   128proto_options/go ?=
   129#proto_options/go += Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration
   130
   131proto_options/go-grpc ?=
   132
   133$(OSS_HOME)/pkg/api/%.pb.go: $(OSS_HOME)/api/%.proto $(tools/protoc) $(tools/protoc-gen-go)
   134	$(tools/protoc) \
   135	  $(addprefix --proto_path=,$(proto_path)) \
   136	  --plugin=$(tools/protoc-gen-go) --go_out=$(OSS_HOME)/pkg/api $(addprefix --go_opt=,$(proto_options/go)) \
   137	  $<
   138$(OSS_HOME)/pkg/api/%_grpc.pb.go: $(OSS_HOME)/api/%.proto $(tools/protoc) $(tools/protoc-gen-go-grpc)
   139	$(tools/protoc) \
   140	  $(addprefix --proto_path=,$(proto_path)) \
   141	  --plugin=$(tools/protoc-gen-go-grpc) --go-grpc_out=$(OSS_HOME)/pkg/api $(addprefix --go-grpc_opt=,$(proto_options/go-grpc)) \
   142	  $<
   143
   144clean: _generate_clean
   145_generate_clean:
   146	rm -rf $(OSS_HOME)/_generate.tmp
   147.PHONY: _generate_clean
   148
   149#
   150# `make generate` rules to update generated YAML files (and `zz_generated.*.go` Go files)
   151
   152# Use `controller-gen` to generate Go & YAML
   153#
   154# - Enable a generator by setting the
   155#   `controller-gen/options/GENERATOR_NAME` variable (even to an empty
   156#   value).
   157# - Setting `controller-gen/output/GENERATOR_NAME` for an enabled
   158#   generator is optional; the default output for each enabled
   159#   generator is `dir=config/GENERATOR_NAME`.
   160# - It is invalid to set `controller-gen/output/GENERATOR_NAME` for a
   161#   generator that is not enabled.
   162#
   163#controller-gen/options/webhook     +=
   164#controller-gen/options/schemapatch += manifests=foo
   165#controller-gen/options/rbac        += roleName=ambassador
   166controller-gen/options/object      += headerFile=build-aux/copyright-boilerplate.go.txt
   167controller-gen/options/crd         += trivialVersions=false # Requires Kubernetes 1.13+
   168controller-gen/options/crd         += crdVersions=v1        # Requires Kubernetes 1.16+
   169controller-gen/output/crd           = dir=$@
   170$(OSS_HOME)/_generate.tmp/crds: $(tools/controller-gen) build-aux/copyright-boilerplate.go.txt FORCE
   171	@printf '  $(CYN)Running controller-gen$(END)\n'
   172	rm -rf $@
   173	mkdir -p $@
   174	cd $(OSS_HOME) && $(tools/controller-gen) \
   175	  $(foreach varname,$(sort $(filter controller-gen/options/%,$(.VARIABLES))), $(patsubst controller-gen/options/%,%,$(varname))$(if $(strip $($(varname))),:$(call joinlist,$(comma),$($(varname)))) ) \
   176	  $(foreach varname,$(sort $(filter controller-gen/output/%,$(.VARIABLES))), $(call joinlist,:,output $(patsubst controller-gen/output/%,%,$(varname)) $($(varname))) ) \
   177	  $(foreach p,$(wildcard ./pkg/api/getambassador.io/v*/),paths=$p...)
   178
   179$(OSS_HOME)/%/zz_generated.conversion.go: $(tools/conversion-gen) build-aux/copyright-boilerplate.go.txt FORCE
   180	rm -f $@ $(@D)/*.scaffold.go
   181	GOPATH= GOFLAGS=-mod=mod $(tools/conversion-gen) \
   182	  --skip-unsafe \
   183	  --go-header-file=build-aux/copyright-boilerplate.go.txt \
   184	  --input-dirs=./$* \
   185	  --output-file-base=zz_generated.conversion
   186# Because v1 just aliases v2, conversion-gen will need to be able to see the v2 conversion functions
   187# when generating code for v1.
   188$(OSS_HOME)/pkg/api/getambassador.io/v1/zz_generated.conversion.go: $(OSS_HOME)/pkg/api/getambassador.io/v2/zz_generated.conversion.go
   189
   190$(OSS_HOME)/%/handwritten.conversion.scaffold.go: $(OSS_HOME)/%/zz_generated.conversion.go build-aux/conversion-scaffold.go.awk
   191	gawk -v pkgname=$(notdir $*) -f build-aux/conversion-scaffold.go.awk <$< | gofmt >$@
   192
   193$(OSS_HOME)/%/zz_generated.conversion-hub.go: build-aux/conversion-hub.go.awk FORCE
   194	rm -f $@
   195	gawk -v pkgname=$(notdir $*) -f build-aux/conversion-hub.go.awk $(sort $(wildcard $(@D)/*.go)) | gofmt >$@
   196
   197$(OSS_HOME)/%/zz_generated.conversion-spoke.go: build-aux/conversion-spoke.go.awk FORCE
   198	rm -f $@
   199	gawk -v pkgname=$(notdir $*) -f build-aux/conversion-spoke.go.awk $(sort $(wildcard $(@D)/*.go)) | gofmt >$@
   200
   201$(OSS_HOME)/manifests/emissary/emissary-crds.yaml.in: $(OSS_HOME)/_generate.tmp/crds $(tools/fix-crds)
   202	$(tools/fix-crds) --target=apiserver-kubectl $(sort $(wildcard $</*.yaml)) >$@
   203
   204$(OSS_HOME)/python/tests/integration/manifests/crds.yaml: $(OSS_HOME)/_generate.tmp/crds $(tools/fix-crds)
   205	$(tools/fix-crds) --target=apiserver-kat $(sort $(wildcard $</*.yaml)) >$@
   206
   207$(OSS_HOME)/pkg/api/getambassador.io/crds.yaml: $(OSS_HOME)/_generate.tmp/crds $(tools/fix-crds)
   208	$(tools/fix-crds) --target=internal-validator $(sort $(wildcard $</*.yaml)) >$@
   209
   210# Names for all the helm-expanded.yaml files (and thence output.yaml and *.yaml.in files)
   211helm.name.emissary-emissaryns = emissary-ingress
   212helm.name.emissary-defaultns = emissary-ingress
   213helm.namespace.emissary-emissaryns = emissary
   214helm.namespace.emissary-defaultns = default
   215helm.name.emissary-emissaryns-agent = emissary-ingress
   216helm.namespace.emissary-emissaryns-agent = emissary
   217helm.name.emissary-defaultns-agent = emissary-ingress
   218helm.namespace.emissary-defaultns-agent = default
   219helm.name.emissary-emissaryns-migration = emissary-ingress
   220helm.namespace.emissary-emissaryns-migration = emissary
   221helm.name.emissary-defaultns-migration = emissary-ingress
   222helm.namespace.emissary-defaultns-migration = default
   223
   224# IF YOU'RE LOOKING FOR *.yaml: recipes, look in main.mk.
   225
   226$(OSS_HOME)/k8s-config/%/helm-expanded.yaml: \
   227  $(OSS_HOME)/k8s-config/%/values.yaml \
   228  $(boguschart_dir)
   229	helm template --namespace=$(helm.namespace.$*) --values=$(@D)/values.yaml $(or $(helm.name.$*),$*) $(boguschart_dir) >$@
   230$(OSS_HOME)/k8s-config/%/output.yaml: \
   231  $(OSS_HOME)/k8s-config/%/helm-expanded.yaml \
   232  $(OSS_HOME)/k8s-config/%/require.yaml \
   233  $(tools/filter-yaml)
   234	$(tools/filter-yaml) $(filter %/helm-expanded.yaml,$^) $(filter %/require.yaml,$^) >$@
   235k8s-config.clean:
   236	rm -f k8s-config/*/helm-expanded.yaml k8s-config/*/output.yaml
   237clean: k8s-config.clean
   238
   239$(OSS_HOME)/manifests/emissary/%.yaml.in: $(OSS_HOME)/k8s-config/%/output.yaml
   240	cp $< $@
   241
   242$(OSS_HOME)/python/tests/integration/manifests/%.yaml: $(OSS_HOME)/k8s-config/kat-%/output.yaml
   243	sed -e 's/«/{/g' -e 's/»/}/g' -e 's/♯.*//g' -e 's/- ←//g' <$< >$@
   244
   245$(OSS_HOME)/python/tests/integration/manifests/rbac_cluster_scope.yaml: $(OSS_HOME)/k8s-config/kat-rbac-multinamespace/output.yaml
   246	sed -e 's/«/{/g' -e 's/»/}/g' -e 's/♯.*//g' -e 's/- ←//g' <$< >$@
   247
   248$(OSS_HOME)/python/tests/integration/manifests/rbac_namespace_scope.yaml: $(OSS_HOME)/k8s-config/kat-rbac-singlenamespace/output.yaml
   249	sed -e 's/«/{/g' -e 's/»/}/g' -e 's/♯.*//g' -e 's/- ←//g' <$< >$@
   250
   251#
   252# Generate report on dependencies
   253
   254$(OSS_HOME)/DEPENDENCIES.md: $(tools/go-mkopensource) $(tools/py-mkopensource) $(OSS_HOME)/build-aux/go-version.txt $(OSS_HOME)/build-aux/pip-show.txt
   255	$(MAKE) $(OSS_HOME)/build-aux/go$$(cat $(OSS_HOME)/build-aux/go-version.txt).src.tar.gz
   256	set -e; { \
   257		cd $(OSS_HOME); \
   258		$(tools/go-mkopensource) --output-format=txt --package=mod --application-type=external --gotar=build-aux/go$$(cat $(OSS_HOME)/build-aux/go-version.txt).src.tar.gz; \
   259		echo; \
   260		{ sed 's/^---$$//' $(OSS_HOME)/build-aux/pip-show.txt; echo; } | $(tools/py-mkopensource); \
   261	} > $@
   262
   263$(OSS_HOME)/DEPENDENCY_LICENSES.md: $(tools/go-mkopensource) $(tools/py-mkopensource) $(OSS_HOME)/build-aux/go-version.txt $(OSS_HOME)/build-aux/pip-show.txt
   264	$(MAKE) $(OSS_HOME)/build-aux/go$$(cat $(OSS_HOME)/build-aux/go-version.txt).src.tar.gz
   265	echo -e "Emissary-ingress incorporates Free and Open Source software under the following licenses:\n" > $@
   266	set -e; { \
   267		cd $(OSS_HOME); \
   268		$(tools/go-mkopensource) --output-format=txt --package=mod --output-type=json --application-type=external --gotar=build-aux/go$$(cat $(OSS_HOME)/build-aux/go-version.txt).src.tar.gz | jq -r '.licenseInfo | to_entries | .[] | "* [" + .key + "](" + .value + ")"' ; \
   269		{ sed 's/^---$$//' $(OSS_HOME)/build-aux/pip-show.txt; echo; } | $(tools/py-mkopensource) --output-type=json | jq -r '.licenseInfo | to_entries | .[] | "* [" + .key + "](" + .value + ")"'; \
   270	} | sort | uniq | sed -e 's/\[\([^]]*\)]()/\1/' >> $@
   271
   272#
   273# Misc. other `make generate` rules
   274
   275$(OSS_HOME)/CHANGELOG.md: $(OSS_HOME)/docs/CHANGELOG.tpl $(OSS_HOME)/docs/releaseNotes.yml
   276	docker run --rm \
   277	  -v $(OSS_HOME)/docs/CHANGELOG.tpl:/tmp/CHANGELOG.tpl \
   278	  -v $(OSS_HOME)/docs/releaseNotes.yml:/tmp/releaseNotes.yml \
   279	  hairyhenderson/gomplate --verbose --file /tmp/CHANGELOG.tpl --datasource relnotes=/tmp/releaseNotes.yml > CHANGELOG.md

View as plain text