X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=Makefile;h=0ae100ba58f9a0ffeaa5254067eb134023464219;hb=c94a962279858fb13eaacc689f47aed358373e44;hp=f6e2b9c632e5aa942a8385cb25502734a2bfe0ca;hpb=d4d3b9c6fa67fe454f8d8adc7502b3b645ecab10;p=govpp.git diff --git a/Makefile b/Makefile index f6e2b9c..0ae100b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SHELL := /usr/bin/env bash -o pipefail VERSION ?= $(shell git describe --always --tags --dirty) COMMIT ?= $(shell git rev-parse HEAD) -BUILD_STAMP ?= $(shell git log -1 --format="%ct") +BUILD_STAMP ?= $(shell git log -1 --format='%ct') BUILD_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) BUILD_HOST ?= $(shell hostname) @@ -10,7 +10,7 @@ BUILD_USER ?= $(shell id -un) GO ?= go -GOVPP_PKG := $(shell go list) +GOVPP_PKG := git.fd.io/govpp.git LDFLAGS = \ -X ${GOVPP_PKG}/version.version=$(VERSION) \ -X ${GOVPP_PKG}/version.commitHash=$(COMMIT) \ @@ -24,7 +24,7 @@ endif GO_BUILD_TAGS ?= novpp -GO_BUILD_ARGS = -ldflags "${LDFLAGS}" +GO_BUILD_ARGS = -ldflags "$(LDFLAGS)" ifneq ($(GO_BUILD_TAGS),) GO_BUILD_ARGS += -tags="${GO_BUILD_TAGS}" endif @@ -35,16 +35,16 @@ ifeq ($(V),1) GO_BUILD_ARGS += -v endif -VPP_VERSION = $(shell dpkg-query -f '\${Version}' -W vpp) +VPP_VERSION ?= $(shell dpkg-query -f '\${Version}' -W vpp) -VPP_IMG ?= ligato/vpp-base:latest -BINAPI_DIR ?= ./examples/binapi - -help: - @echo "List of make targets:" - grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' - -.DEFAULT = help +# VPP Docker image to use for api generation (gen-binapi-docker) +VPP_IMG ?= ligato/vpp-base:latest +# Local VPP directory used for binary api generation (gen-binapi-from-code) +VPP_DIR ?= +# Target directory for generated go api bindings +BINAPI_DIR ?= ./binapi +# Binapi generator path +BINAPI_GENERATOR = ./bin/binapi-generator bin: mkdir -p bin @@ -53,6 +53,9 @@ build: ## Build all @echo "# building ${VERSION}" $(GO) build ${GO_BUILD_ARGS} ./... +cmd-binapi-generator: bin ## Build commands + $(GO) build ${GO_BUILD_ARGS} -o bin ./cmd/binapi-generator + cmd: bin ## Build commands $(GO) build ${GO_BUILD_ARGS} -o bin ./cmd/... @@ -64,6 +67,7 @@ clean: ## Clean all $(GO) clean -v ./... test: ## Run unit tests + $(GO) version @echo "# running tests" $(GO) test -tags="${GO_BUILD_TAGS}" ./... @@ -79,7 +83,7 @@ install: install-generator install-proxy ## Install all install-generator: ## Install binapi-generator @echo "# installing binapi-generator ${VERSION}" - $(GO) install ${GO_BUILD_ARGS} ./cmd/binapi-generator + @$(GO) install ${GO_BUILD_ARGS} ./cmd/binapi-generator install-proxy: ## Install vpp-proxy @echo "# installing vpp-proxy ${VERSION}" @@ -93,20 +97,39 @@ generate-binapi: install-generator ## Generate binapi code @echo "# generating binapi VPP $(VPP_VERSION)" $(GO) generate -x "$(BINAPI_DIR)" +gen-binapi-from-code: cmd-binapi-generator + $(eval VPP_API_DIR := ${VPP_DIR}/build-root/install-vpp-native/vpp/share/vpp/api/) + @echo "Generating vpp API.json and go bindings" + @echo "Vpp Directory ${VPP_DIR}" + @echo "Vpp API files ${VPP_API_DIR}" + @echo "Go bindings ${BINAPI_DIR}" + @cd ${VPP_DIR} && make json-api-files + @${BINAPI_GENERATOR} \ + --input-dir=${VPP_API_DIR} \ + --output-dir=${BINAPI_DIR} \ + --gen rpc,rest \ + --no-source-path-info + gen-binapi-docker: install-generator ## Generate binapi code (using Docker) @echo "# generating binapi in docker image ${VPP_IMG}" $(eval cmds := $(shell go generate -n $(BINAPI_DIR) 2>&1 | tr "\n" ";")) docker run -t --rm \ - -v "$(shell which gofmt):/usr/local/bin/gofmt:ro" \ + -e DEBUG_GOVPP \ -v "$(shell which binapi-generator):/usr/local/bin/binapi-generator:ro" \ - -v "$(shell pwd):/govpp" -w /govpp \ + -v "$(shell pwd):/govpp" \ + -w /govpp \ -u "$(shell id -u):$(shell id -g)" \ "${VPP_IMG}" \ - sh -xc "cd $(BINAPI_DIR) && $(cmds)" + sh -ec "cd $(BINAPI_DIR) && $(cmds)" extras: @make -C extras +help: + @echo "List of make targets:" + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.DEFAULT_GOAL = help .PHONY: help \ build cmd examples clean \