#!/usr/bin/make -f
# -*- makefile -*-

# Excluded binaries. List all binary names:
# go list -f '{{ if eq .Name "main" }}{{ .ImportPath }}{{ end }}' ./...
# (cd gopls && go list -f '{{ if eq .Name "main" }}{{ .ImportPath }}{{ end }}' ./...)
export DH_GOLANG_EXCLUDES := \
	cmd/cover \
	cmd/getgo/server \
	cmd/signature-fuzzer \
	gopls/api-diff \
	gopls/doc \
	gopls/integration/govim \
	gopls/internal/coverage \
	gopls/internal/lsp/helper \
	gopls/internal/lsp/protocol/generate \
	gopls/release \
	internal/loopclosure \
	internal/stack/gostacks

# Excluded tests
export DH_GOLANG_EXCLUDES += \
	copyright \
	gopls/internal/regtest \
	gopls/test

# needed for tests.
export DH_GOLANG_INSTALL_EXTRA := \
	godoc/static \
	gopls/go.sum \
	gopls/internal/lsp/cmd/usage

# eg #753978
# stress #793693
# bundle #818551
RENAME_BIN := \
	bisect \
	bundle \
	deadcode \
	eg \
	guru \
	stress

# All go/analysis/*/*/cmd/*
RENAME_BIN += \
	defers \
	fieldalignment \
	findcall \
	ifaceassert \
	lostcancel \
	nilness \
	shadow \
	stringintconv \
	unmarshal \
	unusedresult

# All cmd/auth/*
RENAME_BIN += \
	authtest \
	cookieauth \
	gitauth \
	netrcauth

# All go/*/internal/*
RENAME_BIN += \
	nodecount \
	play

execute_after_dh_auto_install:
	for i in $(RENAME_BIN); \
	do \
	    mv debian/tmp/usr/bin/$$i debian/tmp/usr/bin/golang-$$i; \
	done
	# gopls can't be not imported by other packages.
	# remove it to avoid tests in autopkgtest which causes circular
	# dependencies when updating golang-golang-x-vuln.
	rm -rvf debian/tmp/usr/share/gocode/src/golang.org/x/tools/gopls

override_dh_auto_test:
ifeq (,$(findstring gccgo, $(shell go version)))
	# use short tests where possible (especially to skip tests like
	# TestWebIndex which are very slow)
	dh_auto_test -- -short -timeout=30m
endif

%:
	dh $@ --builddirectory=_build --buildsystem=golang
