github.com/datastax/go-cassandra-native-protocol@v0.0.0-20220706104457-5e8aad05cf90/Makefile (about)

     1  # From https://raw.githubusercontent.com/vincentbernat/hellogopher/1cf9ebeeaea41d2e159e196f7d176d6b12ff0eb2/Makefile
     2  # Licensed under Creative Commons Zero v1.0 Universal (CC0)
     3  
     4  MODULE   = $(shell env GO111MODULE=on $(GO) list -m)
     5  DATE    ?= $(shell date +%FT%T%z)
     6  VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \
     7  			cat .version 2> /dev/null || echo v0)
     8  PKGS     = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./...))
     9  BUILD    = build
    10  BIN      = $(BUILD)/bin
    11  TEST     = $(BUILD)/test
    12  
    13  GO      = go
    14  TIMEOUT = 15
    15  V = 0
    16  Q = $(if $(filter 1,$V),,@)
    17  M = $(shell [ "$$(tput colors 2> /dev/null || echo 0)" -ge 8 ] && printf "\033[34;1m▶\033[0m" || printf "▶")
    18  
    19  export GO111MODULE=on
    20  
    21  .PHONY: all
    22  all: check-license mocks deep-copy fmt lint test-coverage | $(BIN)
    23  
    24  # Tools
    25  
    26  $(BUILD):
    27  	@mkdir -p $@
    28  
    29  $(BIN):
    30  	@mkdir -p $@
    31  
    32  $(TEST):
    33  	@mkdir -p $@
    34  
    35  $(BIN)/%: | $(BIN) ; $(info $(M) installing $(PACKAGE)...)
    36  	$Q if [ ! -z "INSTALL_ROOT" ]; then cd $(INSTALL_ROOT); fi; env GOBIN=$(abspath $(BIN)) $(GO) install $(PACKAGE)
    37  
    38  GOIMPORTS = $(BIN)/goimports
    39  $(BIN)/goimports: PACKAGE=golang.org/x/tools/cmd/goimports@latest
    40  
    41  REVIVE = $(BIN)/revive
    42  $(BIN)/revive: PACKAGE=github.com/mgechev/revive@latest
    43  
    44  GOCOV = $(BIN)/gocov
    45  $(BIN)/gocov: PACKAGE=github.com/axw/gocov/gocov@latest
    46  
    47  GOCOVXML = $(BIN)/gocov-xml
    48  $(BIN)/gocov-xml: PACKAGE=github.com/AlekSi/gocov-xml@latest
    49  
    50  GOTESTSUM = $(BIN)/gotestsum
    51  $(BIN)/gotestsum: PACKAGE=gotest.tools/gotestsum@latest
    52  
    53  ADDLICENSE = $(BIN)/addlicense
    54  $(BIN)/addlicense: PACKAGE=github.com/google/addlicense@latest
    55  
    56  # FIXME this might break in the future since Mockery does not officially support installing with go install
    57  MOCKERY = $(BIN)/mockery
    58  $(BIN)/mockery: PACKAGE=github.com/vektra/mockery/v2@v2.12.3
    59  
    60  # Note: deepcopy-gen contains replace directives and cannot be installed in module-aware mode,
    61  # instead it is checked out and installed from the checked-out directory.
    62  DEEPCOPY = $(BIN)/deepcopy-gen
    63  $(BIN)/deepcopy-gen: PACKAGE=k8s.io/gengo/examples/deepcopy-gen
    64  $(BIN)/deepcopy-gen: INSTALL_ROOT=./$(GENGO_DIR)/examples/deepcopy-gen
    65  
    66  GENGO_DIR = $(BUILD)/src/gengo
    67  $(GENGO_DIR): ; $(info $(M) cloning Gengo...)
    68  	@mkdir -p $@
    69  	$Q git clone -q https://github.com/kubernetes/gengo.git $@
    70  	$Q cd $@; git checkout -q 4627b89bbf1b # v0.0.0-20220307231824-4627b89bbf1b
    71  
    72  # Tests
    73  
    74  test-bench: NAME=benchmarks ## Run benchmarks
    75  test-bench: ARGS=-run=__absolutelynothing__ -bench=.
    76  
    77  test-short: NAME=short tests ## Run only short tests
    78  test-short: ARGS=-short
    79  
    80  test-verbose: NAME=tests in verbose mode ## Run tests in verbose mode
    81  test-verbose: GOTESTSUM_ARGS=--format=standard-verbose
    82  
    83  test-race: NAME=tests with race detection ## Run tests with race detection
    84  test-race: ARGS=-race
    85  
    86  COVERAGE_MODE = atomic
    87  test-coverage: NAME=tests with coverage ## Run tests with coverage
    88  test-coverage: ARGS=-coverpkg=$(shell echo $(PKGS) | tr ' ' ',') -covermode=$(COVERAGE_MODE) -coverprofile=$(TEST)/profile.out $(PKGS)
    89  test-coverage: | $(GOCOV) $(GOCOVXML)
    90  	$Q $(GO) tool cover -html=$(TEST)/profile.out -o $(TEST)/coverage.html
    91  	$Q $(GOCOV) convert $(TEST)/profile.out | $(GOCOVXML) > $(TEST)/coverage.xml
    92  	@echo "Code coverage: "; \
    93  		echo "scale=1;$$(sed -En 's/^<coverage line-rate="([0-9.]+)".*/\1/p' $(TEST)/coverage.xml) * 100 / 1" | bc -q
    94  
    95  TEST_TARGETS := test-bench test-short test-verbose test-race test-coverage
    96  $(TEST_TARGETS): test
    97  .PHONY: $(TEST_TARGETS) check test tests
    98  
    99  check test tests: | $(GOTESTSUM) $(TEST) ; $(info $(M) running $(if $(NAME),$(NAME),tests)...) @ ## Run tests
   100  	$Q $(GOTESTSUM) $(GOTESTSUM_ARGS) --junitfile $(TEST)/tests.xml -- -timeout $(TIMEOUT)s $(ARGS) $(PKGS)
   101  
   102  # Formatting and linting
   103  
   104  .PHONY: lint
   105  lint: | $(REVIVE) ; $(info $(M) running golint...) @ ## Run golint
   106  	$Q $(REVIVE) -formatter friendly -set_exit_status ./...
   107  
   108  .PHONY: fmt
   109  fmt: | $(GOIMPORTS) ; $(info $(M) running gofmt...) @ ## Run gofmt on all source files
   110  	$Q $(GOIMPORTS) -local $(MODULE) -w $(shell $(GO) list -f '{{$$d := .Dir}}{{range $$f := .GoFiles}}{{printf "%s/%s\n" $$d $$f}}{{end}}{{range $$f := .CgoFiles}}{{printf "%s/%s\n" $$d $$f}}{{end}}{{range $$f := .TestGoFiles}}{{printf "%s/%s\n" $$d $$f}}{{end}}' $(PKGS))
   111  
   112  # Misc
   113  
   114  .PHONY: clean
   115  clean: ; $(info $(M) cleaning...) @ ## Cleanup everything (deletes build directory)
   116  	@rm -rf $(BUILD)
   117  
   118  .PHONY: help
   119  help: ## Displays this help message
   120  	@grep -hE '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
   121  		awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-17s\033[0m %s\n", $$1, $$2}'
   122  
   123  .PHONY: version
   124  version: ## Displays the current version on this git branch
   125  	@echo $(VERSION)
   126  
   127  # See https://stackoverflow.com/questions/52242077/go-modules-finding-out-right-pseudo-version-vx-y-z-timestamp-commit-of-re
   128  PSEUDO_VERSION ?= $(shell TZ=UTC git --no-pager show --quiet --abbrev=12 --date='format-local:%Y%m%d%H%M%S' --format="%cd-%h" 2> /dev/null || echo v0)
   129  .PHONY: pseudo-version
   130  pseudo-version: ## Displays the current pseudo-version on this git branch
   131  	@echo $(PSEUDO_VERSION)
   132  
   133  # License
   134  
   135  check-license: | $(ADDLICENSE) ; $(info $(M) checking license headers...) @ ## Checks license headers in all source files
   136  	$Q $(ADDLICENSE) -check -c "DataStax" -ignore '.github/**'  -ignore '.idea/**' -ignore '$(BUILD)/**' . 2> /dev/null
   137  
   138  update-license: | $(ADDLICENSE) ; $(info $(M) updating license headers...) @ ## Updates license headers in all source files
   139  	$Q $(ADDLICENSE) -c "DataStax" -ignore '.github/**'  -ignore '.idea/**' -ignore '$(BUILD)/**' . 2> /dev/null
   140  
   141  # Mocks
   142  
   143  .PHONY: mock mocks
   144  mock mocks: | $(MOCKERY) ; $(info $(M) generating mocks...) @ ## Generates mocks
   145  	$Q $(MOCKERY) --quiet --dir=./datacodec --name=Codec             --output=./datacodec --outpkg=datacodec --filename=mock_codec_test.go               --structname=mockCodec
   146  	$Q $(MOCKERY) --quiet --dir=./datacodec --name=injector          --output=./datacodec --outpkg=datacodec --filename=mock_injector_test.go            --structname=mockInjector
   147  	$Q $(MOCKERY) --quiet --dir=./datacodec --name=extractor         --output=./datacodec --outpkg=datacodec --filename=mock_extractor_test.go           --structname=mockExtractor
   148  	$Q $(MOCKERY) --quiet --dir=./datacodec --name=keyValueExtractor --output=./datacodec --outpkg=datacodec --filename=mock_key_value_extractor_test.go --structname=mockKeyValueExtractor
   149  	$Q $(MOCKERY) --quiet --dir=./datacodec --name=keyValueInjector  --output=./datacodec --outpkg=datacodec --filename=mock_key_value_injector_test.go  --structname=mockKeyValueInjector
   150  
   151  # Deep Copy
   152  
   153  deep-copy: | $(GENGO_DIR) $(DEEPCOPY) ; $(info $(M) generating deepcopy methods...) @ ## Generates DeepCopy methods
   154  	$Q $(DEEPCOPY) -h deepcopy-header.txt -i github.com/datastax/go-cassandra-native-protocol/primitive --trim-path-prefix github.com/datastax/go-cassandra-native-protocol -o .
   155  	$Q $(DEEPCOPY) -h deepcopy-header.txt -i github.com/datastax/go-cassandra-native-protocol/message   --trim-path-prefix github.com/datastax/go-cassandra-native-protocol -o .
   156  	$Q $(DEEPCOPY) -h deepcopy-header.txt -i github.com/datastax/go-cassandra-native-protocol/datatype  --trim-path-prefix github.com/datastax/go-cassandra-native-protocol -o .
   157  	$Q $(DEEPCOPY) -h deepcopy-header.txt -i github.com/datastax/go-cassandra-native-protocol/frame     --trim-path-prefix github.com/datastax/go-cassandra-native-protocol -o .
   158  	$Q $(DEEPCOPY) -h deepcopy-header.txt -i github.com/datastax/go-cassandra-native-protocol/segment   --trim-path-prefix github.com/datastax/go-cassandra-native-protocol -o .