#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

export DH_GOLANG_EXCLUDES := plugin/builtin plugin/someteam.example.com
export DH_GOLANG_INSTALL_EXTRA := plugin/someteam.example.com/v1/bashedconfigmap/BashedConfigMap

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

execute_after_dh_auto_configure:
	# dh_auto_configure first copies source files to the build root, then
	# symlinks libraries from /usr/share/gocode/src.
	# The dependency symlink will NOT occur when the library package uses the
	# same XS-Go-Import-Path (DH_GOPKG) as the source package and ship files
	# under the same GOPATH, causing problems in dh_auto_build due to lack of
	# installed libraries.
	# dh_auto_configure: warning: "sigs.k8s.io/kustomize" is already installed.
	# https://salsa.debian.org/go-team/packages/dh-golang/-/blob/81892fe8d3a51a22c910a649052669dd9f18837e/lib/Debian/Debhelper/Buildsystem/golang.pm#L495
	ln -vs /usr/share/gocode/src/sigs.k8s.io/kustomize/kyaml $(CURDIR)/_build/src/sigs.k8s.io/kustomize/kyaml

override_dh_auto_test:
	# Set missing flags and skip tests that try to access the internet.
	dh_auto_test --builddirectory=_build -- -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=2023-01-31T23:38:41Z -X sigs.k8s.io/kustomize/api/provenance.version=(test)" -skip='TestDefaultAbsPluginHomeNoXdgWithDotConfig|TestDefaultAbsPluginHomeNoXdgJustHomeDir|TestAnnoOriginRemoteBuiltinTransformer|TestRemoteLoad_RemoteProtocols|TestAnnoOriginRemoteBuiltinGenerator|TestCustomOpenApiFieldFromOverlayWithRemoteSchema|TestCustomOpenApiFieldFromBaseWithRemoteSchema|TestCustomOpenApiFieldBasicUsageWithRemoteSchema|TestExistingCacheDir|TestRemoteRootNoRef|TestResourcesRepoNotFile|TestNestedRemoteRoots|TestRemoteRoot|TestRemoteFile|TestBadArgs|TestRemoteTargetDefaultDst|ExampleFilter|TestSedTransformer|TestPluginEnvironment'

execute_before_dh_auto_install:
	rm -rf $(CURDIR)/_build/src/sigs.k8s.io/kustomize/api/krusty/testdata
	rm -rf $(CURDIR)/_build/src/sigs.k8s.io/kustomize/plugin

override_dh_auto_install:
	dh_auto_install -- --no-binaries
