...

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

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

     1# This file deals with installing programs used by the build.
     2#
     3# It depends on:
     4#  - The `go` binary being installed in PATH.
     5#  - OSS_HOME being set.
     6# That should be it.
     7
     8ifeq ($(words $(filter $(abspath $(lastword $(MAKEFILE_LIST))),$(abspath $(MAKEFILE_LIST)))),1)
     9
    10tools.mk    := $(lastword $(MAKEFILE_LIST))
    11tools.dir    = tools
    12tools.bindir = $(tools.dir)/bin
    13tools.srcdir = $(tools.dir)/src
    14
    15GOHOSTOS   := $(shell go env GOHOSTOS)
    16GOHOSTARCH := $(shell go env GOHOSTARCH)
    17
    18clobber: clobber-tools
    19
    20.PHONY: clobber-tools
    21clobber-tools:
    22	rm -rf $(tools.bindir) $(tools.dir)/include $(tools.dir)/downloads
    23
    24go-mod-tidy: $(patsubst $(tools.srcdir)/%/go.mod,go-mod-tidy/tools/%,$(wildcard $(tools.srcdir)/*/go.mod))
    25
    26.PHONY: go-mod-tidy/tools/%
    27go-mod-tidy/tools/%: $(OSS_HOME)/build-aux/go-version.txt
    28	rm -f $(tools.srcdir)/$*/go.sum
    29	cd $(tools.srcdir)/$* && GOFLAGS=-mod=mod go mod tidy -compat=$$(cut -d. -f1,2 < $<) -go=$$(cut -d. -f1,2 < $<)
    30
    31# Shell scripts
    32# =============
    33#
    34tools/copy-ifchanged      = $(tools.bindir)/copy-ifchanged
    35tools/devversion          = $(tools.bindir)/devversion
    36tools/docker-promote      = $(tools.bindir)/docker-promote
    37tools/move-ifchanged      = $(tools.bindir)/move-ifchanged
    38tools/tap-driver          = $(tools.bindir)/tap-driver
    39tools/write-dockertagfile = $(tools.bindir)/write-dockertagfile
    40tools/write-ifchanged     = $(tools.bindir)/write-ifchanged
    41$(tools.bindir)/%: $(tools.srcdir)/%.sh
    42	mkdir -p $(@D)
    43	install $< $@
    44
    45# Python scripts
    46# ==============
    47#
    48tools/py-list-deps = $(tools.bindir)/py-list-deps
    49$(tools.bindir)/%: $(tools.srcdir)/%.py
    50	mkdir -p $(@D)
    51	install $< $@
    52
    53# `go get`-able things
    54# ====================
    55#
    56tools/chart-doc-gen      = $(tools.bindir)/chart-doc-gen
    57tools/controller-gen     = $(tools.bindir)/controller-gen
    58tools/conversion-gen     = $(tools.bindir)/conversion-gen
    59tools/crane              = $(tools.bindir)/crane
    60tools/go-mkopensource    = $(tools.bindir)/go-mkopensource
    61tools/golangci-lint      = $(tools.bindir)/golangci-lint
    62tools/kubestatus         = $(tools.bindir)/kubestatus
    63tools/ocibuild           = $(tools.bindir)/ocibuild
    64tools/protoc-gen-go      = $(tools.bindir)/protoc-gen-go
    65tools/protoc-gen-go-grpc = $(tools.bindir)/protoc-gen-go-grpc
    66tools/yq                 = $(tools.bindir)/yq
    67$(tools.bindir)/%: $(tools.srcdir)/%/pin.go $(tools.srcdir)/%/go.mod
    68	cd $(<D) && GOOS= GOARCH= go build -o $(abspath $@) $$(sed -En 's,^import "(.*)".*,\1,p' pin.go)
    69# Let these use the main Emissary go.mod instead of having their own go.mod.
    70tools.main-gomod += $(tools/controller-gen)     # ensure runtime libraries are consistent
    71tools.main-gomod += $(tools/conversion-gen)     # ensure runtime libraries are consistent
    72tools.main-gomod += $(tools/protoc-gen-go)      # ensure runtime libraries are consistent
    73tools.main-gomod += $(tools/protoc-gen-go-grpc) # ensure runtime libraries are consistent
    74tools.main-gomod += $(tools/go-mkopensource)    # ensure it is consistent with py-mkopensource
    75tools.main-gomod += $(tools/kubestatus)         # is actually part of Emissary
    76$(tools.main-gomod): $(tools.bindir)/%: $(tools.srcdir)/%/pin.go $(OSS_HOME)/go.mod
    77	cd $(<D) && GOOS= GOARCH= go build -o $(abspath $@) $$(sed -En 's,^import "(.*)".*,\1,p' pin.go)
    78
    79# Local Go sources
    80# ================
    81#
    82tools/dsum            = $(tools.bindir)/dsum
    83tools/filter-yaml     = $(tools.bindir)/filter-yaml
    84tools/fix-crds        = $(tools.bindir)/fix-crds
    85tools/flock           = $(tools.bindir)/flock
    86tools/gotest2tap      = $(tools.bindir)/gotest2tap
    87tools/goversion       = $(tools.bindir)/goversion
    88tools/py-mkopensource = $(tools.bindir)/py-mkopensource
    89tools/py-split-tests  = $(tools.bindir)/py-split-tests
    90tools/testcert-gen    = $(tools.bindir)/testcert-gen
    91$(tools.bindir)/.%.stamp: $(tools.srcdir)/%/main.go FORCE
    92# If we build with `-mod=vendor` (which is the default if
    93# `vendor/modules.txt` exists), *and* our deps don't exist in $(go env
    94# GOMODCACHE), then the binary ends up with empty hashes for those
    95# packages.  In CI, (as long as `vendor/` is checked in to git) this
    96# means that they would be empty for the first `make generate` and
    97# non-empty for the second `make generate`, which would (rightfully)
    98# trip copy-ifchanged's "this should not happen in CI" checks.  I
    99# don't have the time to kill off `vendor/` yet, so for now this is
   100# addressed by explicitly setting `-mod=mod`.
   101	cd $(<D) && GOOS= GOARCH= go build -mod=mod -o $(abspath $@) .
   102$(tools.bindir)/%: $(tools.bindir)/.%.stamp $(tools/copy-ifchanged)
   103	$(tools/copy-ifchanged) $< $@
   104
   105# Snowflakes
   106# ==========
   107#
   108
   109# Telepresence would be `go get`-able, but it requires a few
   110# `replace`s that keeping in-sync would be more trouble than it's
   111# worth.
   112tools/telepresence   = $(tools.bindir)/telepresence
   113TELEPRESENCE_VERSION = 2.6.6
   114$(tools.bindir)/telepresence: $(tools.mk)
   115	mkdir -p $(@D)
   116	curl -s --fail -L https://app.getambassador.io/download/tel2/$(GOHOSTOS)/$(GOHOSTARCH)/$(TELEPRESENCE_VERSION)/telepresence -o $@
   117	chmod a+x $@
   118
   119# k3d is in theory `go get`-able, but... the tests fail when I do
   120# that.  IDK.  --lukeshu
   121tools/k3d   = $(tools.bindir)/k3d
   122K3D_VERSION = 4.4.8
   123$(tools.bindir)/k3d: $(tools.mk)
   124	mkdir -p $(@D)
   125	curl -s --fail -L https://github.com/rancher/k3d/releases/download/v$(K3D_VERSION)/k3d-$(GOHOSTOS)-$(GOHOSTARCH) -o $@
   126	chmod a+x $@
   127
   128# PROTOC_VERSION must be at least 3.8.0 in order to contain the fix so that it doesn't generate
   129# invalid Python if you name an Enum member the same as a Python keyword.
   130tools/protoc    = $(tools.bindir)/protoc
   131PROTOC_VERSION  = 21.5
   132PROTOC_ZIP     := protoc-$(PROTOC_VERSION)-$(patsubst darwin,osx,$(GOHOSTOS))-$(patsubst arm64,aarch_64,$(shell uname -m)).zip
   133$(tools.dir)/downloads/$(PROTOC_ZIP):
   134	mkdir -p $(@D)
   135	curl --fail -L https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/$(PROTOC_ZIP) -o $@
   136$(tools.dir)/bin/protoc $(tools.dir)/include: $(tools.dir)/%: $(tools.dir)/downloads/$(PROTOC_ZIP) $(tools.mk)
   137	bsdtar -C $(tools.dir) -x -m -f $< $*
   138$(tools.dir)/bin/protoc: $(tools.dir)/include
   139
   140tools/protoc-gen-grpc-web  = $(tools.bindir)/protoc-gen-grpc-web
   141GRPC_WEB_VERSION           = 1.0.3
   142GRPC_WEB_PLATFORM         := $(GOHOSTOS)-$(shell uname -m)
   143$(tools.bindir)/protoc-gen-grpc-web: $(tools.mk)
   144	mkdir -p $(@D)
   145	curl -o $@ -L --fail https://github.com/grpc/grpc-web/releases/download/$(GRPC_WEB_VERSION)/protoc-gen-grpc-web-$(GRPC_WEB_VERSION)-$(GRPC_WEB_PLATFORM)
   146	chmod 755 $@
   147
   148tools/kubectl = $(tools.bindir)/kubectl
   149KUBECTL_VERSION = 1.21.6
   150$(tools.bindir)/kubectl: $(tools.mk)
   151	mkdir -p $(@D)
   152	curl -o $@ -L --fail https://storage.googleapis.com/kubernetes-release/release/v$(KUBECTL_VERSION)/bin/$(GOHOSTOS)/$(GOHOSTARCH)/kubectl
   153	chmod 755 $@
   154
   155tools/ct = $(tools.bindir)/ct
   156$(tools/ct): $(tools.bindir)/%: $(tools.srcdir)/%/wrap.sh $(tools/ct).d/bin/ct $(tools/ct).d/bin/kubectl $(tools/ct).d/venv $(tools/ct).d/home
   157	install $< $@
   158$(tools/ct).d/bin/ct: $(tools.srcdir)/ct/pin.go $(tools.srcdir)/ct/go.mod
   159	@PS4=; set -ex; {\
   160	  cd $(<D); \
   161	  pkg=$$(sed -En 's,^import "(.*)".*,\1,p' pin.go); \
   162	  ver=$$(go list -f='{{ .Module.Version }}' "$$pkg"); \
   163	  GOOS= GOARCH= go build -o $(abspath $@) -ldflags="-X $$pkg/cmd.Version=$$ver" "$$pkg"; \
   164	}
   165$(tools/ct).d/bin/kubectl: $(tools/kubectl)
   166	mkdir -p $(@D)
   167	ln -s ../../kubectl $@
   168$(tools/ct).d/dir.txt: $(tools.srcdir)/ct/pin.go $(tools.srcdir)/ct/go.mod
   169	mkdir -p $(@D)
   170	cd $(<D) && GOFLAGS='-mod=readonly' go list -f='{{ .Module.Dir }}' "$$(sed -En 's,^import "(.*)".*,\1,p' pin.go)" >$(abspath $@)
   171$(tools/ct).d/venv: %/venv: %/dir.txt
   172	rm -rf $@
   173	python3 -m venv $@
   174	$@/bin/pip3 install \
   175	  yamllint==$$(sed -n 's/ARG yamllint_version=//p' "$$(cat $<)/Dockerfile") \
   176	  yamale==$$(sed -n 's/ARG yamale_version=//p' "$$(cat $<)/Dockerfile") \
   177	  || (rm -rf $@; exit 1)
   178$(tools/ct).d/home: %/home: %/dir.txt
   179	rm -rf $@
   180	mkdir $@ $@/.ct
   181	cp "$$(cat $<)"/etc/* $@/.ct || (rm -rf $@; exit 1)
   182
   183# Inter-tool dependencies
   184# =======================
   185#
   186$(tools/devversion): $(tools/goversion)
   187
   188endif

View as plain text