aboutsummaryrefslogtreecommitdiff
path: root/Mk
diff options
context:
space:
mode:
authorDmitri Goutnik <dmgk@FreeBSD.org>2020-02-20 12:15:37 +0000
committerDmitri Goutnik <dmgk@FreeBSD.org>2020-02-20 12:15:37 +0000
commit851ac3fa52670a6c68d788ec33640406ccd1364d (patch)
treeef4fac2c52a8bc2fa680d0fbb739132897614f1f /Mk
parentb543e13adb49cd9781070326dc7b222489b1c6d8 (diff)
downloadports-851ac3fa52670a6c68d788ec33640406ccd1364d.tar.gz
ports-851ac3fa52670a6c68d788ec33640406ccd1364d.zip
Notes
Diffstat (limited to 'Mk')
-rw-r--r--Mk/Uses/go.mk43
1 files changed, 29 insertions, 14 deletions
diff --git a/Mk/Uses/go.mk b/Mk/Uses/go.mk
index 9d0cba7aa56a..7107cd3370f2 100644
--- a/Mk/Uses/go.mk
+++ b/Mk/Uses/go.mk
@@ -12,8 +12,8 @@
# in modules-aware mode.
# no_targets Indicates that Go is needed at build time as a part of
# make/CMake build. This will setup build environment like
-# GO_ENV, GO_BUILDFLAGS but will not create post-extract, do-build
-# and do-install targets.
+# GO_ENV, GO_BUILDFLAGS but will not create post-extract and
+# do-{build,install,test} targets.
# run Indicates that Go is needed at run time and adds it to
# RUN_DEPENDS.
#
@@ -21,19 +21,19 @@
#
# GO_PKGNAME
# The name of the package when building in GOPATH mode. This
-# is the directory that will be created in GOPATH/src and seen
-# by the `go` command. If not set explicitly and GH_SUBDIR or
-# GL_SUBDIR is present, GO_PKGNAME will be inferred from it.
+# is the directory that will be created in ${GOPATH}/src. If not set
+# explicitly and GH_SUBDIR or GL_SUBDIR is present, GO_PKGNAME will
+# be inferred from it.
# It is not needed when building in modules-aware mode.
#
# GO_TARGET
-# The packages to build. If not set explicitly, defaults to
-# GO_PKGNAME. GO_TARGET can also be a tuple in the form
-# package:path where path can be either a simple filename or a
-# full path starting with ${PREFIX}. Specifying a full path
-# like ${PREFIX}/sbin/binary will install the resulting binary
-# as ${PREFIX}/sbin/binary. Using just simple filename is a
-# shortcut to installing it as ${PREFIX}/bin/filename.
+# The packages to build. The default value is ${GO_PKGNAME}.
+# GO_TARGET can also be a tuple in the form package:path where path can be
+# either a simple filename or a full path starting with ${PREFIX}.
+#
+# GO_TESTTARGET
+# The packages to test. The default value is `./...` (the current package
+# and all subpackages).
#
# CGO_CFLAGS
# Additional CFLAGS variables to be passed to the C compiler by the `go`
@@ -46,6 +46,9 @@
# GO_BUILDFLAGS
# Additional build arguments to be passed to the `go build` command
#
+# GO_TESTFLAGS
+# Additional build arguments to be passed to the `go test` command
+#
# GO_PORT
# The Go port to use. By default this is lang/go but can be set
# to lang/go-devel in make.conf for testing with future Go versions.
@@ -72,12 +75,15 @@ GO_PKGNAME= ${GL_SUBDIR:S|^src/||}
GO_PKGNAME= ${PORTNAME}
. endif
.endif
+
GO_TARGET?= ${GO_PKGNAME}
+GO_TESTTARGET?= ./...
GO_BUILDFLAGS+= -v -buildmode=exe
.if !defined(WITH_DEBUG) && empty(GO_BUILDFLAGS:M-ldflags*)
GO_BUILDFLAGS+= -ldflags=-s
.endif
+GO_TESTFLAGS+= -v
CGO_ENABLED?= 1
CGO_CFLAGS+= -I${LOCALBASE}/include
@@ -98,12 +104,12 @@ GO_ENV+= CGO_ENABLED=${CGO_ENABLED} \
.if ${go_ARGS:Mmodules}
GO_BUILDFLAGS+= -mod=vendor
+GO_TESTFLAGS+= -mod=vendor
GO_WRKSRC= ${WRKSRC}
GO_ENV+= GOPATH="" \
GOBIN="${GO_WRKDIR_BIN}"
.else
-GO_WRKDIR_SRC= ${WRKDIR}/src
-GO_WRKSRC= ${GO_WRKDIR_SRC}/${GO_PKGNAME}
+GO_WRKSRC= ${WRKDIR}/src/${GO_PKGNAME}
GO_ENV+= GOPATH="${WRKDIR}" \
GOBIN=""
.endif
@@ -160,6 +166,15 @@ do-install:
done
.endif
+.if !target(do-test) && empty(go_ARGS:Mno_targets)
+do-test:
+ (cd ${GO_WRKSRC}; \
+ for t in ${GO_TESTTARGET}; do \
+ ${ECHO_MSG} "===> Testing $${t}"; \
+ ${SETENV} ${MAKE_ENV} ${GO_ENV} ${GO_CMD} test ${GO_TESTFLAGS} $${t}; \
+ done)
+.endif
+
# Helper targets for port maintainers
.if ${go_ARGS:Mmodules}