Index: Mk/Uses/go.mk =================================================================== --- Mk/Uses/go.mk +++ Mk/Uses/go.mk @@ -5,9 +5,10 @@ # # Feature: go # Usage: USES=go -# Valid ARGS: (none), modules, no_targets, run +# Valid ARGS: (none), mage, modules, no_targets, run # # (none) Setup GOPATH and build in GOPATH mode. +# mage Indicates that mage should be used to build # modules If the upstream uses Go modules, this can be set to build # in modules-aware mode. # no_targets Indicates that Go is needed at build time as a part of @@ -60,8 +61,8 @@ .if !defined(_INCLUDE_USES_GO_MK) _INCLUDE_USES_GO_MK= yes -.if !empty(go_ARGS:Nmodules:Nno_targets:Nrun) -IGNORE= USES=go has invalid arguments: ${go_ARGS:Nmodules:Nno_targets:Nrun} +.if !empty(go_ARGS:Nmodules:Nno_targets:Nrun:Nmage) +IGNORE= USES=go has invalid arguments: ${go_ARGS:Nmodules:Nno_targets:Nrun:Nmage} .endif # Settable variables @@ -102,6 +103,11 @@ CGO_LDFLAGS="${CGO_LDFLAGS}" \ GOARM=${GOARM} +.if ${go_ARGS:Mmage} +BUILD_DEPENDS+= mage>=1.9.0:devel/mage +MAGE_CMD= ${LOCALBASE}/bin/mage +.endif + .if ${go_ARGS:Mmodules} GO_BUILDFLAGS+= -mod=vendor GO_TESTFLAGS+= -mod=vendor @@ -128,7 +134,17 @@ .if defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_GO_POST_MK) _INCLUDE_USES_GO_POST_MK= yes -.if !target(post-extract) && empty(go_ARGS) +.if ${go_ARGS:Mmage} +_GO_BUILD_CMD=${MAGE_CMD} -gocmd ${GO_CMD} -d $${pkg} build +_GO_TEST_CMD=${MAGE_CMD} -gocmd ${GO_CMD} -d $${t} test +.else +_GO_BUILD_CMD=${GO_CMD} build ${GO_BUILDFLAGS} \ + -o ${GO_WRKDIR_BIN}/$${out} \ + $${pkg} +_GO_TEST_CMD=${GO_CMD} test ${GO_TESTFLAGS} $${t} +.endif + +.if !target(post-extract) && empty(go_ARGS:Mno_targets) post-extract: @${MKDIR} ${GO_WRKSRC:H} @${LN} -sf ${WRKSRC} ${GO_WRKSRC} @@ -143,9 +159,7 @@ pkg=$$(${ECHO_CMD} $${t} | \ ${SED} -Ee 's/^([^:]*).*$$/\1/' -e 's/^${PORTNAME}$$/./'); \ ${ECHO_MSG} "===> Building $${out} from $${pkg}"; \ - ${SETENV} ${MAKE_ENV} ${GO_ENV} ${GO_CMD} build ${GO_BUILDFLAGS} \ - -o ${GO_WRKDIR_BIN}/$${out} \ - $${pkg}; \ + ${SETENV} ${MAKE_ENV} ${GO_ENV} ${_GO_BUILD_CMD}; \ done) .endif @@ -169,7 +183,7 @@ (cd ${GO_WRKSRC}; \ for t in ${GO_TESTTARGET}; do \ ${ECHO_MSG} "===> Testing $${t}"; \ - ${SETENV} ${MAKE_ENV} ${GO_ENV} ${GO_CMD} test ${GO_TESTFLAGS} $${t}; \ + ${SETENV} ${MAKE_ENV} ${GO_ENV} ${_GO_TEST_CMD}; \ done) .endif