<commit_before>HAS_SDKTEST := $(shell command -v sdk-test 2> /dev/null)
BRANCH	:= $(shell git rev-parse --abbrev-ref HEAD)

ifeq ($(TRAVIS_BRANCH), master)
MOCKSDKSERVERTAG := latest
else

ifeq ($(BRANCH), master)
MOCKSDKSERVERTAG := latest
else
MOCKSDKSERVERTAG := $(shell go run tools/sdkver/sdkver.go)
endif

endif

REGISTRY = openstorage
IMAGE_MOCKSDKSERVER := $(REGISTRY)/mock-sdk-server:$(MOCKSDKSERVERTAG)

ifndef TAGS
TAGS := daemon
endif

ifndef PKGS
PKGS := $(shell go list ./... 2>&1 | grep -v 'vendor' | grep -v 'sanity')
endif

ifeq ($(BUILD_TYPE),debug)
BUILDFLAGS := -gcflags "-N -l"
endif

ifdef HAVE_BTRFS
TAGS+=btrfs_noversion have_btrfs
endif

ifdef HAVE_CHAINFS
TAGS+=have_chainfs
endif

ifndef PROTOC
PROTOC = protoc
endif

ifndef PROTOS_PATH
PROTOS_PATH = $(GOPATH)/src
endif

ifndef PROTOSRC_PATH
PROTOSRC_PATH = $(PROTOS_PATH)/github.com/libopenstorage/openstorage
endif

OSDSANITY:=cmd/osd-sanity/osd-sanity

.PHONY: \
	all \
	deps \
	update-deps \
	test-deps \
	update-test-deps \
	vendor-update \
	vendor-without-update \
	vendor-gomod \
	vendor \
	build \
	install \
	proto \
	lint \
	vet \
	fmt \
	packr \
	errcheck \
	pretest \
	test \
	hack-tests \
	docs \
	docker-build-osd-dev \
	docker-build \
	docker-test \
	docker-build-osd-internal \
	docker-build-osd \
	launch \
	launch-local-btrfs \
	install-flexvolume-plugin \
	$(OSDSANITY)-install \
	$(OSDSANITY)-clean \
	clean \
	generate \
	generate-mockfiles \
	e2e \
	verify \
	osd-tests \
	pr-lint \
	pr-verify \
	pr-unit-tests \
	sdk-check-version


all: build $(OSDSANITY)

# TOOLS build rules
#
$(GOPATH)/bin/golint:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/golang/lint/golint

$(GOPATH)/bin/errcheck:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/kisielk/errcheck

$(GOPATH)/bin/protoc-gen-go:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/golang/protobuf/protoc-gen-go

$(GOPATH)/bin/protoc-gen-grpc-gateway:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

$(GOPATH)/bin/protoc-gen-swagger:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger

$(GOPATH)/bin/packr2:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/gobuffalo/packr/...

$(GOPATH)/bin/cover:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u golang.org/x/tools/cmd/cover

$(GOPATH)/bin/gotestcover:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/pierrre/gotestcover

# DEPS build rules
#

deps:
	GO111MODULE=off go get -d -v $(PKGS)

update-deps:
	GO111MODULE=off go get -d -v -u -f $(PKGS)

test-deps:
	GO111MODULE=off go get -d -v -t $(PKGS)

update-test-deps:
	GO111MODULE=off go get -tags "$(TAGS)" -d -v -t -u -f $(PKGS)

vendor-update:
	GOOS=linux GOARCH=amd64 go get -tags "daemon btrfs_noversion have_btrfs have_chainfs" -d -v -t -u -f $(PKGS)

vendor-gomod:
	GOOS=linux GOARCH=amd64 go mod tidy
	GOOS=linux GOARCH=amd64 go mod vendor

vendor: vendor-gomod

build: packr
	go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)

install: packr $(OSDSANITY)-install
	go install -gcflags="all=-N -l" -tags "$(TAGS)" $(PKGS)
	go install github.com/libopenstorage/openstorage/cmd/osd-token-generator

$(OSDSANITY):
	@$(MAKE) -C cmd/osd-sanity

$(OSDSANITY)-install:
	@$(MAKE) -C cmd/osd-sanity install

$(OSDSANITY)-clean:
	@$(MAKE) -C cmd/osd-sanity clean

docker-build-proto:
	docker build -t quay.io/openstorage/osd-proto --network=host -f Dockerfile.proto .

# the docker-build-proto should be there temporarily for the go mod upgrade
docker-proto: docker-build-proto $(GOPATH)/bin/protoc-gen-go
	docker run \
		--privileged --rm \
		-v $(shell pwd):/go/src/github.com/libopenstorage/openstorage \
		-e "GOPATH=/go" \
		-e "DOCKER_PROTO=yes" \
		-e "PATH=/bin:/usr/bin:/usr/local/bin:/go/bin:/usr/local/go/bin" \
		quay.io/openstorage/osd-proto \
			make proto mockgen

proto: $(GOPATH)/bin/protoc-gen-go $(GOPATH)/bin/protoc-gen-grpc-gateway $(GOPATH)/bin/protoc-gen-swagger
ifndef DOCKER_PROTO
	$(error Do not run directly. Run 'make docker-proto' instead.)
endif

	@echo ">>> Generating protobuf definitions from api/api.proto"
	$(PROTOC) -I $(PROTOSRC_PATH) \
		-I /usr/local/include \
		-I $(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \<commit_msg>Use pushed quay.io image in docker-proto (#2007)<commit_after>HAS_SDKTEST := $(shell command -v sdk-test 2> /dev/null)
BRANCH	:= $(shell git rev-parse --abbrev-ref HEAD)

ifeq ($(TRAVIS_BRANCH), master)
MOCKSDKSERVERTAG := latest
else

ifeq ($(BRANCH), master)
MOCKSDKSERVERTAG := latest
else
MOCKSDKSERVERTAG := $(shell go run tools/sdkver/sdkver.go)
endif

endif

REGISTRY = openstorage
IMAGE_MOCKSDKSERVER := $(REGISTRY)/mock-sdk-server:$(MOCKSDKSERVERTAG)

ifndef TAGS
TAGS := daemon
endif

ifndef PKGS
PKGS := $(shell go list ./... 2>&1 | grep -v 'vendor' | grep -v 'sanity')
endif

ifeq ($(BUILD_TYPE),debug)
BUILDFLAGS := -gcflags "-N -l"
endif

ifdef HAVE_BTRFS
TAGS+=btrfs_noversion have_btrfs
endif

ifdef HAVE_CHAINFS
TAGS+=have_chainfs
endif

ifndef PROTOC
PROTOC = protoc
endif

ifndef PROTOS_PATH
PROTOS_PATH = $(GOPATH)/src
endif

ifndef PROTOSRC_PATH
PROTOSRC_PATH = $(PROTOS_PATH)/github.com/libopenstorage/openstorage
endif

OSDSANITY:=cmd/osd-sanity/osd-sanity

.PHONY: \
	all \
	deps \
	update-deps \
	test-deps \
	update-test-deps \
	vendor-update \
	vendor-without-update \
	vendor-gomod \
	vendor \
	build \
	install \
	proto \
	lint \
	vet \
	fmt \
	packr \
	errcheck \
	pretest \
	test \
	hack-tests \
	docs \
	docker-build-osd-dev \
	docker-build \
	docker-test \
	docker-build-osd-internal \
	docker-build-osd \
	launch \
	launch-local-btrfs \
	install-flexvolume-plugin \
	$(OSDSANITY)-install \
	$(OSDSANITY)-clean \
	clean \
	generate \
	generate-mockfiles \
	e2e \
	verify \
	osd-tests \
	pr-lint \
	pr-verify \
	pr-unit-tests \
	sdk-check-version


all: build $(OSDSANITY)

# TOOLS build rules
#
$(GOPATH)/bin/golint:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/golang/lint/golint

$(GOPATH)/bin/errcheck:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/kisielk/errcheck

$(GOPATH)/bin/protoc-gen-go:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/golang/protobuf/protoc-gen-go

$(GOPATH)/bin/protoc-gen-grpc-gateway:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

$(GOPATH)/bin/protoc-gen-swagger:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger

$(GOPATH)/bin/packr2:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/gobuffalo/packr/...

$(GOPATH)/bin/cover:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u golang.org/x/tools/cmd/cover

$(GOPATH)/bin/gotestcover:
	@echo "Installing missing $@ ..."
	GO111MODULE=off go get -u github.com/pierrre/gotestcover

# DEPS build rules
#

deps:
	GO111MODULE=off go get -d -v $(PKGS)

update-deps:
	GO111MODULE=off go get -d -v -u -f $(PKGS)

test-deps:
	GO111MODULE=off go get -d -v -t $(PKGS)

update-test-deps:
	GO111MODULE=off go get -tags "$(TAGS)" -d -v -t -u -f $(PKGS)

vendor-update:
	GOOS=linux GOARCH=amd64 go get -tags "daemon btrfs_noversion have_btrfs have_chainfs" -d -v -t -u -f $(PKGS)

vendor-gomod:
	GOOS=linux GOARCH=amd64 go mod tidy
	GOOS=linux GOARCH=amd64 go mod vendor

vendor: vendor-gomod

build: packr
	go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)

install: packr $(OSDSANITY)-install
	go install -gcflags="all=-N -l" -tags "$(TAGS)" $(PKGS)
	go install github.com/libopenstorage/openstorage/cmd/osd-token-generator

$(OSDSANITY):
	@$(MAKE) -C cmd/osd-sanity

$(OSDSANITY)-install:
	@$(MAKE) -C cmd/osd-sanity install

$(OSDSANITY)-clean:
	@$(MAKE) -C cmd/osd-sanity clean

docker-build-proto:
	docker build -t quay.io/openstorage/osd-proto --network=host -f Dockerfile.proto .

docker-proto:  $(GOPATH)/bin/protoc-gen-go
	docker run \
		--privileged --rm \
		-v $(shell pwd):/go/src/github.com/libopenstorage/openstorage \
		-e "GOPATH=/go" \
		-e "DOCKER_PROTO=yes" \
		-e "PATH=/bin:/usr/bin:/usr/local/bin:/go/bin:/usr/local/go/bin" \
		quay.io/openstorage/osd-proto \
			make proto mockgen

proto: $(GOPATH)/bin/protoc-gen-go $(GOPATH)/bin/protoc-gen-grpc-gateway $(GOPATH)/bin/protoc-gen-swagger
ifndef DOCKER_PROTO
	$(error Do not run directly. Run 'make docker-proto' instead.)
endif

	@echo ">>> Generating protobuf definitions from api/api.proto"
	$(PROTOC) -I $(PROTOSRC_PATH) \
		-I /usr/local/include \
		-I $(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
{'fraction_non_alphanumeric': 0.15426559127570147, 'fraction_numerical': 0.011132568442576395, 'mean_word_length': 3.621522309711286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1703065', 'n_tokens_mistral': 3766, 'n_tokens_neox': 3562, 'n_words': 750}