<commit_before># Copyright 2018 Datawire. All rights reserved.
#
# Makefile snippet of common bits between go-mod.mk and
# go-workspace.mk.  Don't include this directly from your Makefile,
# include either go-mod.mk or go-workspace.mk!

ifeq ($(go.module),)
$(error Do not include _go-common.mk directly, include go-mod.mk or go-workspace.mk)
endif

# It would be simpler to create this list if we could use Go modules:
#
#     go.bins := $(shell $(GO) list -f='{{if eq .Name "main"}}{{.ImportPath}}{{end}}' ./...)
#
# But alas, we can't do that *even if* the build is using Go modules,
# as that would cause the module system go ahead and download
# dependencies.  We don't want Go to do that at Makefile-parse-time;
# what if we're running `make clean`?
#
# So instead, we must deal with this abomination.  At least that means
# we can share it between go-mod.mk and go-workspace.mk.
_go.submods := $(patsubst %/go.mod,%,$(shell git ls-files '*/go.mod'))
go.list = $(call path.addprefix,$(go.module),\
                                $(filter-out $(foreach d,$(_go.submods),$d $d/%),\
                                             $(call path.trimprefix,_$(CURDIR),\
                                                                    $(shell GO111MODULE=off GOCACHE=off go list $1))))
go.bins := $(call go.list,-f='{{if eq .Name "main"}}{{.ImportPath}}{{end}}' ./...)

#
# Rules

# go-FOO.mk is responsible for implementing go-get
go-get: ## Download Go dependencies
.PHONY: go-get

define _go.bin.rule
bin_%/$(notdir $(go.bin)): go-get FORCE
	go build -o $$@ $(go.bin)
endef
$(foreach go.bin,$(go.bins),$(eval $(_go.bin.rule)))

go-build: $(addprefix bin_$(GOOS)_$(GOARCH)/,$(notdir $(go.bins)))
.PHONY: go-build

check-go-fmt: ## Check whether the code conforms to `gofmt`
	test -z "$$(git ls-files -z '*.go' | xargs -0 gofmt -d | tee /dev/stderr)"
.PHONY: check-go-fmt

go-vet: ## Check the code with `go vet`
go-vet: go-get
	go vet $(go.pkgs)
.PHONY: go-vet

go-fmt: ## Fixup the code with `go fmt`
	go fmt ./...
.PHONY: go-fmt

go-test: ## Check the code with `go test`
go-test: go-build
	go test $(go.pkgs)
.PHONY: go-test

#
# Hook in to common.mk

build: go-build
lint: check-go-fmt go-vet
check: go-test
format: go-fmt
<commit_msg>Squashed 'build-aux/' changes from 7e78ccb..d4ccfd1<commit_after># Copyright 2018 Datawire. All rights reserved.
#
# Makefile snippet of common bits between go-mod.mk and
# go-workspace.mk.  Don't include this directly from your Makefile,
# include either go-mod.mk or go-workspace.mk!

ifeq ($(go.module),)
$(error Do not include _go-common.mk directly, include go-mod.mk or go-workspace.mk)
endif

# It would be simpler to create this list if we could use Go modules:
#
#     go.bins := $(shell $(GO) list -f='{{if eq .Name "main"}}{{.ImportPath}}{{end}}' ./...)
#
# But alas, we can't do that *even if* the build is using Go modules,
# as that would cause the module system go ahead and download
# dependencies.  We don't want Go to do that at Makefile-parse-time;
# what if we're running `make clean`?
#
# So instead, we must deal with this abomination.  At least that means
# we can share it between go-mod.mk and go-workspace.mk.
_go.submods := $(patsubst %/go.mod,%,$(shell git ls-files '*/go.mod'))
go.list = $(call path.addprefix,$(go.module),\
                                $(filter-out $(foreach d,$(_go.submods),$d $d/%),\
                                             $(call path.trimprefix,_$(CURDIR),\
                                                                    $(shell GO111MODULE=off GOCACHE=off GOPATH=$(GOPATH) go list $1))))
go.bins := $(call go.list,-f='{{if eq .Name "main"}}{{.ImportPath}}{{end}}' ./...)

#
# Rules

# go-FOO.mk is responsible for implementing go-get
go-get: ## Download Go dependencies
.PHONY: go-get

define _go.bin.rule
bin_%/$(notdir $(go.bin)): go-get FORCE
	go build -o $$@ $(go.bin)
endef
$(foreach go.bin,$(go.bins),$(eval $(_go.bin.rule)))

go-build: $(addprefix bin_$(GOOS)_$(GOARCH)/,$(notdir $(go.bins)))
.PHONY: go-build

check-go-fmt: ## Check whether the code conforms to `gofmt`
	test -z "$$(git ls-files '*.go' | grep -v -e ^vendor/ -e /vendor/ | xargs gofmt -d | tee /dev/stderr)"
.PHONY: check-go-fmt

go-vet: ## Check the code with `go vet`
go-vet: go-get
	go vet $(go.pkgs)
.PHONY: go-vet

go-fmt: ## Fixup the code with `go fmt`
	go fmt ./...
.PHONY: go-fmt

go-test: ## Check the code with `go test`
go-test: go-build
	go test $(go.pkgs)
.PHONY: go-test

#
# Hook in to common.mk

build: go-build
lint: check-go-fmt go-vet
check: go-test
format: go-fmt

{'fraction_non_alphanumeric': 0.16626558739881864, 'fraction_numerical': 0.004812951214176329, 'mean_word_length': 2.825941422594142, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '563948', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1594, 'n_words': 525}