mirror of
https://github.com/agent-substrate/substrate.git
synced 2026-11-11 10:23:17 +08:00
$(KO) != $(GO)
ko does not support any way to pass build flags directly. We have to
use GOFLAGS. Go does not fully shell-parse GOFLAGS, it just does simple
whitespace splitting and whole-value quoting.
E.g. this fails for good reason:
GOFLAGS="-ldflags=-X=foo=foo -X=bar=bar"
...becomes:
[ "go", "build", "-ldflags=-X=foo=foo", "-X=bar=bar" ]
...where `-X` is passed to `go build`
We can try:
GOFLAGS="-ldflags='-X=foo=foo -X=bar=bar'"
...but that becomes
[ "go", "build", "-ldflags='-X=foo=foo", "-X=bar=bar'" ]
...which is unfortunate.
Go does some quote handling, but:
GOFLAGS='-ldflags="-X=foo=foo -X=bar=bar"'
...still becomes:
[ "go", "build", "-ldflags=\"-X=foo=foo", "-X=bar=bar\"" ]
...which is surprising.
We can try:
GOFLAGS="-ldflags=-X=foo=foo -ldflags=-X=bar=bar"
...but go just takes the last value of that flag rather than the
accumulation.
What does work is:
GOFLAGS='"-ldflags=-X=foo=foo -X=bar=bar"'
...with the WHOLE flag quoted.
94 lines
2.1 KiB
Makefile
94 lines
2.1 KiB
Makefile
# Copyright 2026 Google LLC
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# Default project ID, can be overridden
|
|
PROJECT_ID ?= $(shell echo $${USER}-gke-dev)
|
|
|
|
# Ko configuration
|
|
export KO_DOCKER_REPO := gcr.io/$(PROJECT_ID)/ate-images
|
|
|
|
# Go commands
|
|
GO := go
|
|
KO := hack/run-tool.sh ko
|
|
|
|
# Binaries
|
|
BINDIR := bin/
|
|
ATECTL := $(BINDIR)/kubectl-ate
|
|
|
|
# Version stamping. Override on the make command line to pin
|
|
# (e.g. `make VERSION=v0.5.0 build`).
|
|
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
|
VERSION_PKG := github.com/agent-substrate/substrate/internal/version
|
|
LDFLAGS := -X=$(VERSION_PKG).Version=$(VERSION)
|
|
|
|
.PHONY: all
|
|
all: build
|
|
|
|
.PHONY: build
|
|
build: build-images build-atectl
|
|
|
|
.PHONY: build-images
|
|
build-images:
|
|
GOFLAGS='"-ldflags=$(LDFLAGS)"' \
|
|
$(KO) build \
|
|
./cmd/ateapi \
|
|
./cmd/atelet \
|
|
./cmd/podcertcontroller \
|
|
./cmd/atenet
|
|
|
|
.PHONY: build-atectl
|
|
build-atectl:
|
|
$(GO) build -ldflags "$(LDFLAGS)" -o $(ATECTL) ./cmd/kubectl-ate
|
|
|
|
.PHONY: build-atenet
|
|
build-atenet:
|
|
$(GO) build -ldflags "$(LDFLAGS)" -o $(BINDIR)/atenet ./cmd/atenet
|
|
|
|
.PHONY: build-demos
|
|
build-demos:
|
|
GOFLAGS='"-ldflags=$(LDFLAGS)"' \
|
|
$(KO) build ./demos/counter
|
|
|
|
.PHONY: test
|
|
test:
|
|
$(GO) test ./...
|
|
|
|
.PHONY: e2e
|
|
e2e: build build-demos
|
|
hack/run-e2e.sh
|
|
|
|
.PHONY: fmt verify-fmt
|
|
|
|
# Formats all Go files in the project
|
|
fmt:
|
|
@./hack/update/gofmt.sh
|
|
|
|
# Fails if any Go files are not formatted properly
|
|
verify-fmt:
|
|
@./hack/verify/gofmt.sh
|
|
|
|
.PHONY: lint
|
|
|
|
# Runs golangci-lint and fails on any reported issues.
|
|
lint:
|
|
@./hack/verify/golangci-lint.sh
|
|
|
|
.PHONY: verify
|
|
verify: test
|
|
bash hack/verify-all.sh
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
rm -rf $(BINDIR)
|