[VOL-2875] Documentation update
Also, update the Makefile "help" target to self-generate from comments
Change-Id: I26d329a2838ea360f3b2c96d44357b9fb8c51b84
diff --git a/Makefile b/Makefile
index a46a2e6..6f257c0 100644
--- a/Makefile
+++ b/Makefile
@@ -56,32 +56,11 @@
GOLANGCI_LINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golangci-lint golangci-lint
HADOLINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-hadolint hadolint
-.PHONY: docker-build local-protos local-lib-go
-
-# This should to be the first and default target in this Makefile
-help:
- @echo "Usage: make [<target>]"
- @echo "where available targets are:"
- @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 "build : Build all openolt adapter artifacts"
- @echo "docker-build : Build openolt adapter docker image"
- @echo "docker-build-profile : Build openolt adapter docker image with profiling enabled"
- @echo "docker-push : Push the docker images to an external repository"
- @echo "help : Print this help"
- @echo "lint : Run all lint targets"
- @echo "lint-dockerfile : Perform static analysis on Dockerfiles"
- @echo "lint-mod : Verify the Go dependencies"
- @echo "local-protos : Copies a local verison of the VOLTHA protos into the vendor directory"
- @echo "local-lib-go : 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
+.PHONY: docker-build local-protos local-lib-go help
+.DEFAULT_GOAL := help
## Local Development Helpers
-
-local-protos:
+local-protos: ## Copies a local version of the voltha-protos dependency into the vendor directory
ifdef LOCAL_PROTOS
rm -rf vendor/github.com/opencord/voltha-protos/v3/go
mkdir -p vendor/github.com/opencord/voltha-protos/v3/go
@@ -89,39 +68,35 @@
rm -rf vendor/github.com/opencord/voltha-protos/v3/go/vendor
endif
-## Local Development Helpers
-local-lib-go:
+local-lib-go: ## Copies a local version of the voltha-lib-go dependency into the vendor directory
ifdef LOCAL_LIB_GO
mkdir -p vendor/github.com/opencord/voltha-lib-go/v3/pkg
cp -r ${LOCAL_LIB_GO}/pkg/* vendor/github.com/opencord/voltha-lib-go/v3/pkg/
endif
## Docker targets
+build: docker-build ## Alias for 'docker build'
-build: docker-build
-
-docker-build: local-protos local-lib-go
+docker-build: local-protos local-lib-go ## Build openolt adapter docker image
docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME} -f docker/Dockerfile.openolt .
-docker-build-profile: local-protos local-lib-go
+docker-build-profile: local-protos local-lib-go ## Build openolt adapter docker image with profiling enabled
docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME}-profile -f docker/Dockerfile.openolt_profile .
-docker-push:
+docker-push: ## Push the docker images to an external repository
docker push ${ADAPTER_IMAGENAME}
-docker-kind-load:
+docker-kind-load: ## Load docker images into a KinD cluster
@if [ "`kind get clusters | grep voltha-$(TYPE)`" = '' ]; then echo "no voltha-$(TYPE) cluster found" && exit 1; fi
kind load docker-image ${ADAPTER_IMAGENAME} --name=voltha-$(TYPE) --nodes $(shell kubectl get nodes --template='{{range .items}}{{.metadata.name}},{{end}}' | sed 's/,$$//')
-
## lint and unit tests
-
-lint-dockerfile:
+lint-dockerfile: ## Perform static analysis on Dockerfile
@echo "Running Dockerfile lint check ..."
@${HADOLINT} $$(find . -name "Dockerfile.*")
@echo "Dockerfile lint check OK"
-lint-mod:
+lint-mod: ## Verify the Go dependencies
@echo "Running dependency check..."
@${GO} mod verify
@echo "Dependency check OK. Running vendor check..."
@@ -135,9 +110,9 @@
@[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files detected after running go mod tidy / go mod vendor" && git status -- go.mod go.sum vendor && git checkout -- go.mod go.sum vendor && exit 1)
@echo "Vendor check OK."
-lint: local-lib-go lint-mod lint-dockerfile
+lint: local-lib-go lint-mod lint-dockerfile ## Run all lint targets
-test:
+test: ## Run unit tests
@mkdir -p ./tests/results
@${GO} test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
RETURN=$$? ;\
@@ -145,7 +120,7 @@
${GOCOVER_COBERTURA} < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
exit $$RETURN
-sca:
+sca: ## Runs static code analysis with the golangci-lint tool
@rm -rf ./sca-report
@mkdir -p ./sca-report
@echo "Running static code analysis..."
@@ -153,11 +128,19 @@
@echo ""
@echo "Static code analysis OK"
-clean: distclean
+clean: distclean ## Removes any local filesystem artifacts generated by a build
-distclean:
+distclean: ## Removes any local filesystem artifacts generated by a build or test run
rm -rf ./sca-report
-mod-update:
+mod-update: ## Update go mod files
${GO} mod tidy
${GO} mod vendor
+
+# For each makefile target, add ## <description> on the target line and it will be listed by 'make help'
+help: ## Print help for each Makefile target
+ @echo "Usage: make [<target>]"
+ @echo "where available targets are:"
+ @echo
+ @grep '^[[:alpha:]_-]*:.* ##' $(MAKEFILE_LIST) \
+ | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s : %s\n", $$1, $$2};'