From: Alexander Mazuruk Date: Thu, 20 Sep 2018 16:52:16 +0000 (+0200) Subject: Adjust Makefile X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F83%2F189683%2F14;p=tools%2Fweles.git Adjust Makefile Change-Id: Iee1d410de72f70617751c22218b08aafa9406c28 Signed-off-by: Alexander Mazuruk Signed-off-by: Michal Sidor --- diff --git a/Makefile b/Makefile index ad38d27..d0f3dbe 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,33 @@ -DEV_TOOLS_DIR = ./bin/dev-tools +BIN_DIR = bin +DEV_TOOLS_DIR = $(BIN_DIR)/dev-tools DEV_TOOLS = ./vendor/github.com/golang/mock/mockgen ./vendor/github.com/go-swagger/go-swagger/cmd/swagger MOCKGEN_BIN = $(DEV_TOOLS_DIR)/mockgen SWAGGER_BIN = $(DEV_TOOLS_DIR)/swagger - DEV_TOOLS_BIN = $(MOCKGEN_BIN) $(SWAGGER_BIN) rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) - WELES_FILES = $(filter-out *_test.go, $(call rwildcard, , *.go)) SERVER_MAIN = cmd/weles-server/main.go -SERVER_BIN = bin/weles-server - -.PHONY: server -server: vendor $(WELES_FILES) +SERVER_BIN = $(BIN_DIR)/weles-server + +DOC_DIR = doc +SPHINX_DOCKER_IMAGE = weles-doc-image +SPHINX_DOCKER_CONTAINER = weles-doc-container +SPHINX_DOCKER_CONTAINER_WORKDIR = /doc +SWAGGER_DOCKER_IMAGE = swaggerapi/swagger-codegen-cli +SWAGGER_DOCKER_CONTAINER = weles-swagger-container +SWAGGER_DOCKER_CONTAINER_WORKDIR = /local + +.PHONY: weles +weles: vendor $(WELES_FILES) go build -o $(SERVER_BIN) $(SERVER_MAIN) -# dep ensure is run after swagger generation to update Gopkg.lock with packages needed to build server -.PHONY: swagger-server-generate -swagger-server-generate: swagger.yml COPYING +# server recipe generates Weles server code. dep ensure is run after swagger +# generation to update Gopkg.lock with packages needed to build server. +.PHONY: server +server: swagger.yml COPYING ./$(DEV_TOOLS_DIR)/swagger generate server \ -A weles \ -f ./swagger.yml \ @@ -31,19 +39,59 @@ swagger-server-generate: swagger.yml COPYING --compatibility-mode=modern dep ensure +.PHONY: docs +docs: docs-swagger docs-sphinx + +.PHONY: clean-docs +clean-docs: clean-docs-swagger clean-docker-swagger clean-docs-sphinx clean-docker-sphinx -.PHONY: swagger-docs-html -swagger-docs-html: swagger.yml - mkdir -p doc/build/swagger +.PHONY: docs-sphinx +docs-sphinx: docker-image-sphinx docker run \ --rm \ - -v $$PWD:/local \ - --user `id -u $$USER`:`id -g $$USER` \ - swaggerapi/swagger-codegen-cli \ + --volume "`pwd`:${SPHINX_DOCKER_CONTAINER_WORKDIR}" \ + --user "`id -u $$USER`:`id -g $$USER`" \ + --name "${SPHINX_DOCKER_CONTAINER}" "${SPHINX_DOCKER_IMAGE}" \ + make -C "${SPHINX_DOCKER_CONTAINER_WORKDIR}/${DOC_DIR}" html + +.PHONY: docker-image-sphinx +docker-image-sphinx: + docker build -t "${SPHINX_DOCKER_IMAGE}" ${DOC_DIR} + +.PHONY: clean-docs-sphinx +clean-docs-sphinx: + -rm -r "${DOC_DIR}/build" + +.PHONY: clean-docker-sphinx +clean-docker-sphinx: + -docker rm "${SPHINX_DOCKER_CONTAINER}" + -docker rmi "${SPHINX_DOCKER_IMAGE}" + +# docs-swagger generates API documentation in HTML format, to be used by +# Sphinx. +.PHONY: docs-swagger +docs-swagger: swagger.yml + mkdir -p ${DOC_DIR}/source/_static/swagger + docker run \ + --rm \ + -v "`pwd`:${SWAGGER_DOCKER_CONTAINER_WORKDIR}" \ + --user "`id -u $$USER`:`id -g $$USER`" \ + --name "${SWAGGER_DOCKER_CONTAINER}" \ + "${SWAGGER_DOCKER_IMAGE}"\ generate \ - -i local/swagger.yml \ + -i "${SWAGGER_DOCKER_CONTAINER_WORKDIR}/swagger.yml" \ -l html \ - -o /local/doc/build/swagger/ + -o "${SWAGGER_DOCKER_CONTAINER_WORKDIR}/${DOC_DIR}/source/_static/swagger/" + +.PHONY: clean-docs-swagger +clean-docs-swagger: + -rm -rf doc/source/_static/swagger + +.PHONY: clean-docker-swagger +clean-docker-swagger: + -docker rm "${SWAGGER_DOCKER_CONTAINER}" + -docker rmi "${SWAGGER_DOCKER_IMAGE}" + vendor: Gopkg.lock dep ensure -v -vendor-only @@ -55,18 +103,21 @@ Gopkg.lock: Gopkg.toml dep-update: clean-vendor dep ensure -update -# clean-vendor has not been added to vendor dependencies as dep is able to check out appropriate -# packages on versions set in the Gopkg.lock file. Removing vendor would force dep to re-download -# all the packages instead of only the missing ones. Global prune is turned off (see Gopkg.toml -# for explanation) thus vendor recipe will leave unused packages in the vendor/ directory. If that -# bothers you, run sequentially clean-vendor and vendor recipes. +# clean-vendor has not been added to vendor dependencies as dep is able to +# check out appropriate packages on versions set in the Gopkg.lock file. +# Removing vendor would force dep to re-download all the packages instead of +# only the missing ones. Global prune is turned off (see Gopkg.toml for +# explanation) thus vendor recipe will leave unused packages in the vendor/ +# directory. If that bothers you, run sequentially clean-vendor and vendor +# recipes. .PHONY: clean-vendor clean-vendor: - rm -rf vendor + -rm -rf vendor -# Due to lack of standard approach to naming and separation of both interfaces and generated mock files -# below recipe does not have any file dependencies and is PHONY. Interface changes should be rare thus -# it is up to the developer to regenerate mocks after interface changes. +# Due to lack of standard approach to naming and separation of both interfaces +# and generated mock files below recipe does not have any file dependencies and +# is PHONY. Interface changes should be rare thus it is up to the developer to +# regenerate mocks after interface changes. .PHONY: mocks mocks: tools go generate ./mock @@ -76,7 +127,7 @@ mocks: tools .PHONY: tools tools: vendor $(DEV_TOOLS_BIN) -# This recipe will rebuild all tools on vendor directory change. -# Due to short build time it is not treated as issue. +# This recipe will rebuild all tools on vendor directory change. Due to short +# build time it is not treated as issue. $(DEV_TOOLS_DIR)/%: $(DEV_TOOLS) go build -o $@ $(filter %$(@F),$(DEV_TOOLS))