VOL-1921 - updated to use go mod

Change-Id: I8d5187fa91fa619494f972bc29d3bd61e5be3a82
diff --git a/Makefile b/Makefile
index e2bcb27..edca893 100644
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,13 @@
 DOCKER_LABEL_BUILD_DATE    ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
 DOCKER_LABEL_COMMIT_DATE   = $(shell git show -s --format=%cd --date=iso-strict HEAD)
 
+# Default is GO111MODULE=auto, which will refuse to use go mod if running
+# go less than 1.13.0 and this repository is checked out in GOPATH. For now,
+# force module usage. This affects commands executed from this Makefile, but
+# not the environment inside the Docker build (which does not build from
+# inside a GOPATH).
+export GO111MODULE=on
+
 DOCKER_BUILD_ARGS ?= \
 	${DOCKER_EXTRA_ARGS} \
 	--build-arg org_label_schema_version="${VERSION}" \
@@ -46,41 +53,46 @@
 	--build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
 	--build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}"
 
-DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \
-	--build-arg LOCAL_PROTOS=${LOCAL_PROTOS}
-
 .PHONY: docker-build local-protos local-voltha
 
 # This should to be the first and default target in this Makefile
 help:
 	@echo "Usage: make [<target>]"
 	@echo "where available targets are:"
-	@echo
+	@echo ""
+	@echo "clean             : Removes any local filesystem artifacts generated by a build"
+	@echo "distclean         : Removes any local filesystem artifacts generated by a build or test run"
 	@echo "docker-build      : Build openolt adapter docker image"
-	@echo "help              : Print this help"
 	@echo "docker-push       : Push the docker images to an external repository"
-	@echo "lint              : Run lint verification, depenancy, gofmt and reference check"
+	@echo "help              : Print this help"
+	@echo "lint              : Run all lint targets"
+	@echo "lint-mod          : Verify the Go dependencies"
+	@echo "lint-sanity       : Run the Go language sanity tests (vet)"
+	@echo "lint-style        : Verify the Go standard format of the source"
+	@echo "local-protos      : Copies a local verison of the VOLTHA protos into the vendor directory"
+	@echo "local-voltha      : Copies a local version of the VOTLHA dependencies into the vendor directory"
 	@echo "sca               : Runs various SCA through golangci-lint tool"
 	@echo "test              : Run unit tests, if any"
 	@echo
 
-
 ## Local Development Helpers
 
 local-protos:
 ifdef LOCAL_PROTOS
+	rm -rf vendor/github.com/opencord/voltha-protos/go
 	mkdir -p vendor/github.com/opencord/voltha-protos/go
-	cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
+	cp -r ${LOCAL_PROTOS}/go/* vendor/github.com/opencord/voltha-protos/go
+	rm -rf vendor/github.com/opencord/voltha-protos/go/vendor
 endif
 
 local-voltha:
 ifdef LOCAL_VOLTHA
+	rm -rf vendor/github.com/opencord/voltha-go
 	mkdir -p vendor/github.com/opencord/voltha-go/
-	cp -rf ${GOPATH}/src/github.com/opencord/voltha-go/ vendor/github.com/opencord/
+	cp -rf ${LOCAL_VOLTHA} vendor/github.com/opencord/
 	rm -rf vendor/github.com/opencord/voltha-go/vendor
 endif
 
-
 ## Docker targets
 
 docker-build: local-protos local-voltha
@@ -106,24 +118,26 @@
 
 lint-sanity:
 	@echo "Running sanity check..."
-	@go vet ./...
+	@go vet -mod=vendor ./...
 	@echo "Sanity check OK"
 
-lint-dep:
+lint-mod:
 	@echo "Running dependency check..."
-	@dep check
+	@go mod verify
 	@echo "Dependency check OK"
 
-lint: lint-style lint-sanity lint-dep
+lint: lint-style lint-sanity lint-mod
+
+__GOPATH=$(shell go env GOPATH)
 
 # Rules to automatically install golangci-lint
 GOLANGCI_LINT_TOOL?=$(shell which golangci-lint)
 ifeq (,$(GOLANGCI_LINT_TOOL))
-GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint
+GOLANGCI_LINT_TOOL=$(__GOPATH)/bin/golangci-lint
 golangci_lint_tool_install:
 	# Same version as installed by Jenkins ci-management
 	# Note that install using `go get` is not recommended as per https://github.com/golangci/golangci-lint
-	curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.17.0
+	curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(__GOPATH)/bin v1.17.0
 else
 golangci_lint_tool_install:
 endif
@@ -131,7 +145,7 @@
 # Rules to automatically install go-junit-report
 GO_JUNIT_REPORT?=$(shell which go-junit-report)
 ifeq (,$(GO_JUNIT_REPORT))
-GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
+GO_JUNIT_REPORT=$(__GOPATH)/bin/go-junit-report
 go_junit_install:
 	go get -u github.com/jstemmer/go-junit-report
 else
@@ -141,7 +155,7 @@
 # Rules to automatically install gocover-covertura
 GOCOVER_COBERTURA?=$(shell which gocover-cobertura)
 ifeq (,$(GOCOVER_COBERTURA))
-	@GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
+	@GOCOVER_COBERTURA=$(__GOPATH)/bin/gocover-cobertura
 gocover_cobertura_install:
 	go get -u github.com/t-yuki/gocover-cobertura
 else
@@ -151,7 +165,7 @@
 test: go_junit_install gocover_cobertura_install
 	@mkdir -p ./tests/results
 
-	@go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
+	@go test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
 	RETURN=$$? ;\
 	$(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
 	$(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
@@ -160,13 +174,11 @@
 GOLANGCI_LINT_TOOL:=$(shell which golangci-lint)
 sca: golangci_lint_tool_install
 	@mkdir -p ./sca-report
-	GO111MODULE=on golangci-lint run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml
+	golangci-lint run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml
 
 clean:
-	rm -rf sca-report
 
 distclean: clean
-	rm -rf ${VENVDIR}
 	rm -rf ./sca_report
 
 # end file