#!/usr/bin/make -f

# Exclude development tools and non-library directories.
# internal/tools pulls in ~200 linting deps not needed for the library.
# cmd/builder and cmd/mdatagen are build/code-gen tools, not library components.
export DH_GOLANG_EXCLUDES := \
	cmd/builder \
	cmd/mdatagen \
	cmd/otelcorecol \
	confmap/internal/e2e \
	internal/cmd \
	internal/e2e \
	internal/schemagen \
	internal/tools \
	# EOL

# dh-golang (>= 1.39) installs go.mod and go.sum automatically, including from
# submodules, so they are not listed here.  We do list:
#  - the zpages HTML templates (not a default-installed extension), and
#  - each component's metadata.yaml: dh-golang only copies .go/.c/.h/... into
#    the build tree, but the generated TestComponentLifecycle reads its own
#    metadata.yaml relative to the working directory, so the file must be
#    present there for the test to run.
export DH_GOLANG_INSTALL_EXTRA := \
	service/internal/zpages/templates \
	connector/forwardconnector/metadata.yaml \
	exporter/debugexporter/metadata.yaml \
	exporter/nopexporter/metadata.yaml \
	exporter/otlpexporter/metadata.yaml \
	exporter/otlphttpexporter/metadata.yaml \
	extension/memorylimiterextension/metadata.yaml \
	extension/zpagesextension/metadata.yaml \
	processor/batchprocessor/metadata.yaml \
	processor/memorylimiterprocessor/metadata.yaml \
	receiver/nopreceiver/metadata.yaml \
	receiver/otlpreceiver/metadata.yaml \
	# EOL

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

execute_before_dh_auto_configure:
	rm -f pdata/internal/.gitignore

# Run the upstream test suite.  The component metadata.yaml files installed
# above let the generated TestComponentLifecycle tests find their config.
# GODEBUG: GOPATH mode (GO111MODULE=off) ignores go.mod's "go 1.25.0", so two
# tests regress to pre-go1.22/1.23 defaults (ServeMux routing, synctest timers);
# setting the go1.25 values, scoped to this test run, makes them pass.
# -skip: the service-telemetry tests that bind the fixed Prometheus port :8888,
# plus TestNoDataLoss, flake under the parallel build (port reuse / timing).
# 32-bit: the package is Architecture: all, so the tests only need to pass on a
# 64-bit builder; skip them on 32-bit arches where they fail (this blocked the
# autopkgtest-based testing migration).
override_dh_auto_test:
ifeq ($(DEB_HOST_ARCH_BITS),32)
	# Skip all tests on 32bits as this is Architecture: all
else
	export GODEBUG=asynctimerchan=0,httpmuxgo121=0; \
	dh_auto_test -- -skip='TestCreateMeterProvider$$|TestCreateMeterProvider_.*MigrationWarning|TestInstrumentEnabled|TestTelemetryMetrics_DefaultViews|TestNoDataLoss'
endif
