Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. MODULE := hth
  2. GO ?= go
  3. PYTHON ?= python3
  4. PROTOC ?= protoc
  5. GOPROXY ?= https://goproxy.cn,direct
  6. export GOPROXY
  7. export CGO_ENABLED ?= 0
  8. export GOTOOLCHAIN ?= local
  9. HOST_ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
  10. REPO_ROOT := $(abspath $(HOST_ROOT)/..)
  11. PROTO := $(HOST_ROOT)/api/proto/hth/api/v1/hth.proto
  12. GEN_DIR := $(HOST_ROOT)/internal/gen/hth/api/v1
  13. PROFILE := $(HOST_ROOT)/profiles/prod2u-door-temp/profile.json
  14. BIN_DIR := $(HOST_ROOT)/bin
  15. API_VERSION := hth.api.v1
  16. .PHONY: all generate profile proto tidy build build-amd64 build-arm64 test test-race vet fuzz python-sdk check-config doctor-bin gofmt-check clean
  17. all: generate build test
  18. generate: profile proto
  19. profile:
  20. $(PYTHON) $(HOST_ROOT)/tools/gen_profile.py --repo-root $(REPO_ROOT) --out $(PROFILE)
  21. proto:
  22. @mkdir -p $(GEN_DIR)
  23. $(PROTOC) --version
  24. $(PROTOC) -I $(HOST_ROOT)/api/proto \
  25. --go_out=$(HOST_ROOT)/internal/gen --go_opt=module=hth/internal/gen \
  26. --go-grpc_out=$(HOST_ROOT)/internal/gen --go-grpc_opt=module=hth/internal/gen \
  27. $(PROTO)
  28. $(PYTHON) $(HOST_ROOT)/tools/gen_python_stubs.py || $(PYTHON) -m grpc_tools.protoc -I $(HOST_ROOT)/api/proto \
  29. --python_out=$(HOST_ROOT)/sdk/python/hth_sdk/generated \
  30. --grpc_python_out=$(HOST_ROOT)/sdk/python/hth_sdk/generated \
  31. $(PROTO)
  32. $(PROTOC) -I $(HOST_ROOT)/api/proto --include_imports --descriptor_set_out=$(HOST_ROOT)/api/proto/hth/api/v1/hth.desc $(PROTO)
  33. tidy:
  34. cd $(HOST_ROOT) && $(GO) mod tidy
  35. build: generate
  36. mkdir -p $(BIN_DIR)
  37. cd $(HOST_ROOT) && $(GO) build -trimpath -ldflags '-s -w -X hth/internal/app.APIVersion=$(API_VERSION)' -o $(BIN_DIR)/hthd ./cmd/hthd
  38. cd $(HOST_ROOT) && $(GO) build -trimpath -ldflags '-s -w -X hth/internal/app.APIVersion=$(API_VERSION)' -o $(BIN_DIR)/hthctl ./cmd/hthctl
  39. cd $(HOST_ROOT) && $(GO) build -trimpath -ldflags '-s -w -X hth/internal/app.APIVersion=$(API_VERSION)' -o $(BIN_DIR)/hth-capture ./cmd/hth-capture
  40. build-amd64: generate
  41. mkdir -p $(BIN_DIR)
  42. cd $(HOST_ROOT) && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build -trimpath -o $(BIN_DIR)/hthd-linux-amd64 ./cmd/hthd
  43. cd $(HOST_ROOT) && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build -trimpath -o $(BIN_DIR)/hthctl-linux-amd64 ./cmd/hthctl
  44. cd $(HOST_ROOT) && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build -trimpath -o $(BIN_DIR)/hth-capture-linux-amd64 ./cmd/hth-capture
  45. build-arm64: generate
  46. mkdir -p $(BIN_DIR)
  47. cd $(HOST_ROOT) && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO) build -trimpath -o $(BIN_DIR)/hthd-linux-arm64 ./cmd/hthd
  48. cd $(HOST_ROOT) && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO) build -trimpath -o $(BIN_DIR)/hthctl-linux-arm64 ./cmd/hthctl
  49. cd $(HOST_ROOT) && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO) build -trimpath -o $(BIN_DIR)/hth-capture-linux-arm64 ./cmd/hth-capture
  50. test: generate
  51. cd $(HOST_ROOT) && $(GO) test ./...
  52. test-race:
  53. cd $(HOST_ROOT) && CGO_ENABLED=1 $(GO) test -race ./...
  54. vet:
  55. cd $(HOST_ROOT) && $(GO) vet ./...
  56. gofmt-check:
  57. @test -z "$$(cd $(HOST_ROOT) && gofmt -l $(shell cd $(HOST_ROOT) && find . -name '*.go' ! -path './internal/gen/*'))"
  58. fuzz:
  59. cd $(HOST_ROOT) && $(GO) test ./internal/protocol -fuzz=FuzzParser -fuzztime=8s
  60. python-sdk:
  61. $(PYTHON) -m pip install -e $(HOST_ROOT)/sdk/python -q
  62. $(PYTHON) -m pytest -q $(HOST_ROOT)/sdk/python/tests
  63. check-config: build
  64. $(BIN_DIR)/hthd --check-config --config $(HOST_ROOT)/deploy/examples/hthd.mock.yaml
  65. clean:
  66. rm -rf $(BIN_DIR)