From d08c26517bb5e9f172718d33de4d486c4465ad19 Mon Sep 17 00:00:00 2001 From: Todd Knight Date: Tue, 19 May 2020 08:33:19 -0700 Subject: [PATCH] Makefile target to remove generated files (#63) * Makefile rm's generated files before generating again and does operations relative to Makefile's path. --- Makefile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a2827dff0..6b6a4bec6 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,19 @@ # Determine this makefile's path. # Be sure to place this BEFORE `include` directives, if any. THIS_FILE := $(lastword $(MAKEFILE_LIST)) +THIS_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) TMP_DIR := $(shell mktemp -d) REPO_PATH := github.com/hashicorp/watchtower +GENERATED_CODE := $(shell find ${THIS_DIR} -name '*.gen.go' && find ${THIS_DIR} -name '*.pb.go' && find ${THIS_DIR} -name '*.pb.gw.go') + export GEN_BASEPATH := $(shell pwd) bootstrap: go generate -tags tools tools/tools.go -gen: proto api migrations +gen: cleangen proto api migrations api: $(MAKE) --environment-overrides -C api/internal/genapi api @@ -18,9 +21,12 @@ api: migrations: $(MAKE) --environment-overrides -C internal/db/migrations/genmigrations migrations +cleangen: + @rm -f ${GENERATED_CODE} + ### oplog requires protoc-gen-go v1.20.0 or later # GO111MODULE=on go get -u github.com/golang/protobuf/protoc-gen-go@v1.40 -proto: protolint protobuild cleanup +proto: protolint protobuild protolint: @buf check lint @@ -40,18 +46,16 @@ protobuild: "--plugin_out=logtostderr=true:${TMP_DIR}" # Move the generated files from the tmp file subdirectories into the current repo. - cp -R ${TMP_DIR}/${REPO_PATH}/* . + cp -R ${TMP_DIR}/${REPO_PATH}/* ${THIS_DIR} @protoc --proto_path=internal/proto/local --proto_path=internal/proto/third_party --swagger_out=logtostderr=true,disable_default_errors=true,include_package_in_tags=true,fqn_for_swagger_name=true,allow_merge,merge_file_name=controller:internal/gen/. internal/proto/local/controller/api/services/v1/*.proto @protoc-go-inject-tag -input=./internal/oplog/store/oplog.pb.go @protoc-go-inject-tag -input=./internal/oplog/oplog_test/oplog_test.pb.go @protoc-go-inject-tag -input=./internal/iam/store/scope.pb.go @protoc-go-inject-tag -input=./internal/db/db_test/db_test.pb.go - -cleanup: @rm -R ${TMP_DIR} -.PHONY: api bootstrap cleanup gen migrations proto +.PHONY: api bootstrap gen migrations proto .NOTPARALLEL: