And another iteration.  This time the build script that is
auto-generated by "go install" is filtered through sed(1) to fix paths
(under some circumstances Go tends to write to ${LOCALBASE}/go, which is
obviously undesirable), force ${WRKBUILD} usage and remove error
messages that are generated when USE_SYSTRACE=Yes is set.  The filtered
script is fed to sh(1) then.

This is absolutely necessary to allow rebuilding already installed go
packages.

To avoid confusion, I am resending all patches and ports.

-- 
Dmitrij D. Czarkoff
Index: lang/go/go.port.mk
===================================================================
RCS file: /var/cvs/ports/lang/go/go.port.mk,v
retrieving revision 1.1
diff -u -p -r1.1 go.port.mk
--- lang/go/go.port.mk  15 May 2015 07:30:41 -0000      1.1
+++ lang/go/go.port.mk  5 Jun 2015 18:52:11 -0000
@@ -11,8 +11,76 @@ MODGO_BUILD_DEPENDS =        lang/go
 BUILD_DEPENDS +=       ${MODGO_BUILD_DEPENDS}
 .endif
 
-GO_PKG ?=              pkg/tool/openbsd_${MACHINE_ARCH:S/i386/386/}
+MODGO_PACKAGES =       go/pkg/openbsd_${MACHINE_ARCH:S/i386/386/}
+MODGO_SOURCES =                go/src
+MODGO_TOOLS =          go/pkg/tool/openbsd_${MACHINE_ARCH:S/i386/386/}
 
-SUBST_VARS +=          GO_PKG
+SUBST_VARS +=          MODGO_TOOLS MODGO_PACKAGES MODGO_SOURCES
 
-GOPATH ?=              "${WRKSRC}:${LOCALBASE}/go"
+MODGO_SUBDIR ?=                ${WRKDIST}
+MODGO_TYPE ?=          bin
+MODGO_WORKSPACE ?=     ${WRKDIR}/go
+MODGO_CMD ?=           unset GOPATH; export GOPATH="${MODGO_WORKSPACE}"; go
+MODGO_FLAGS +=         -a -x -work
+MODGO_BUILD_CMD =      ${MODGO_CMD} install ${MODGO_FLAGS}
+MODGO_TEST_CMD =       ${MODGO_CMD} test ${MODGO_FLAGS}
+
+.if ${MODGO_TYPE:L:Mlib}
+RUN_DEPENDS +=         ${MODGO_RUN_DEPENDS}
+.endif
+
+.if defined(GH_ACCOUNT) && defined(GH_PROJECT)
+ALL_TARGET ?=          github.com/${GH_ACCOUNT}/${GH_PROJECT}
+.endif
+TEST_TARGET ?=         ${ALL_TARGET}
+
+SEPARATE_BUILD ?=      Yes
+WRKSRC ?=              ${MODGO_WORKSPACE}/src/${ALL_TARGET}
+
+MODGO_SETUP_WORKSPACE =        mkdir -p ${WRKSRC:H}; mv ${MODGO_SUBDIR} 
${WRKSRC};
+
+# Go tends to ignore environment and place some files to system-wide
+# directories.  To prevent such behavior, this modules fixes paths in
+# auto-generated build instructions, and then feeds fixed script to shell
+# The "operation not permitted" filter is needed because Go outputs permission
+# error if USE_SYSTRACE=Yes option is set.
+MODGO_BUILD_TARGET =   ${MODGO_BUILD_CMD} ${ALL_TARGET} 2>&1 | sed -E \
+                               -e 's, ${LOCALBASE}/go, ${MODGO_WORKSPACE},' \
+                               -e '/operation not permitted/d' \
+                               -e 's,\$$WORK,${WRKBUILD},g' | sh -v
+
+# Go source files serve the purpose of libraries, so sources should be included
+# with library ports.
+.if ${MODGO_TYPE:L:Mlib}
+MODGO_INSTALL_TARGET = ${INSTALL_DATA_DIR} ${PREFIX}/go; \
+                       cp -R ${MODGO_WORKSPACE}/pkg \
+                             ${MODGO_WORKSPACE}/src \
+                                       ${PREFIX}/go;
+.endif
+.if ${MODGO_TYPE:L:Mbin}
+MODGO_INSTALL_TARGET += cp ${MODGO_WORKSPACE}/bin/* ${PREFIX}/bin
+.endif
+
+MODGO_TEST_TARGET =    ${MODGO_TEST_CMD} ${TEST_TARGET}
+
+.if empty(CONFIGURE_STYLE)
+.  if !target(post-patch)
+post-patch:
+       ${MODGO_SETUP_WORKSPACE}
+.  endif
+
+.  if !target(do-build)
+do-build:
+       ${MODGO_BUILD_TARGET}
+.  endif
+
+.  if !target(do-install)
+do-install:
+       ${MODGO_INSTALL_TARGET}
+.  endif
+
+.  if !target(do-test)
+do-test:
+       ${MODGO_TEST_TARGET}
+.  endif
+.endif
Index: net/go-websocket/Makefile
===================================================================
RCS file: /var/cvs/ports/net/go-websocket/Makefile,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile
--- net/go-websocket/Makefile   15 May 2015 07:32:00 -0000      1.2
+++ net/go-websocket/Makefile   3 Jun 2015 20:03:32 -0000
@@ -7,7 +7,7 @@ DISTNAME =              go-websocket-${VERSION}
 GH_COMMIT =            97d8e4e174133a4d1d2171380e510eb4dea8f5ea
 GH_ACCOUNT =           golang
 GH_PROJECT =           net
-REVISION =             0
+REVISION =             1
 
 CATEGORIES =           net www
 
@@ -23,25 +23,8 @@ WANTLIB =            c pthread
 MODULES =              lang/go
 
 GO_PKG =               pkg/openbsd_${MACHINE_ARCH:S/i386/386/}
-
-post-extract:
-       mkdir -p ${WRKSRC}/src/golang.org/x/net
-       mv ${WRKSRC}/websocket ${WRKSRC}/src/golang.org/x/net/
-
-do-build:
-       GOPATH=${GOPATH} go install golang.org/x/net/websocket
-
-do-test:
-       GOPATH=${GOPATH} go test golang.org/x/net/websocket
-
-do-install:
-       ${INSTALL_DATA_DIR} ${PREFIX}/go/${GO_PKG}/golang.org/x/net
-       ${INSTALL_DATA} -p                                              \
-           ${WRKDIST}/${GO_PKG}/golang.org/x/net/websocket.a           \
-           ${PREFIX}/go/${GO_PKG}/golang.org/x/net/
-       ${INSTALL_DATA_DIR} ${PREFIX}/go/src/golang.org/x/net/websocket
-       ${INSTALL_DATA} -p                                              \
-           ${WRKDIST}/src/golang.org/x/net/websocket/websocket.go      \
-           ${PREFIX}/go/src/golang.org/x/net/websocket/
+MODGO_TYPE =           lib
+MODGO_SUBDIR =         ${WRKDIST}/websocket
+ALL_TARGET =           golang.org/x/net/websocket
 
 .include <bsd.port.mk>
Index: net/go-websocket/pkg/PLIST
===================================================================
RCS file: /var/cvs/ports/net/go-websocket/pkg/PLIST,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 PLIST
--- net/go-websocket/pkg/PLIST  31 Mar 2015 15:37:06 -0000      1.1.1.1
+++ net/go-websocket/pkg/PLIST  3 Jun 2015 20:03:32 -0000
@@ -1,14 +1,17 @@
 @comment $OpenBSD: PLIST,v 1.1.1.1 2015/03/31 15:37:06 kspillner Exp $
-go/
-go/pkg/
-go/${GO_PKG}/
-go/${GO_PKG}/golang.org/
-go/${GO_PKG}/golang.org/x/
-go/${GO_PKG}/golang.org/x/net/
-go/${GO_PKG}/golang.org/x/net/websocket.a
-go/src/
-go/src/golang.org/
-go/src/golang.org/x/
-go/src/golang.org/x/net/
-go/src/golang.org/x/net/websocket/
-go/src/golang.org/x/net/websocket/websocket.go
+${MODGO_PACKAGES}/golang.org/
+${MODGO_PACKAGES}/golang.org/x/
+${MODGO_PACKAGES}/golang.org/x/net/
+${MODGO_PACKAGES}/golang.org/x/net/websocket.a
+${MODGO_SOURCES}/golang.org/
+${MODGO_SOURCES}/golang.org/x/
+${MODGO_SOURCES}/golang.org/x/net/
+${MODGO_SOURCES}/golang.org/x/net/websocket/
+${MODGO_SOURCES}/golang.org/x/net/websocket/client.go
+${MODGO_SOURCES}/golang.org/x/net/websocket/exampledial_test.go
+${MODGO_SOURCES}/golang.org/x/net/websocket/examplehandler_test.go
+${MODGO_SOURCES}/golang.org/x/net/websocket/hybi.go
+${MODGO_SOURCES}/golang.org/x/net/websocket/hybi_test.go
+${MODGO_SOURCES}/golang.org/x/net/websocket/server.go
+${MODGO_SOURCES}/golang.org/x/net/websocket/websocket.go
+${MODGO_SOURCES}/golang.org/x/net/websocket/websocket_test.go
Index: net/websocketd/Makefile
===================================================================
RCS file: /var/cvs/ports/net/websocketd/Makefile,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile
--- net/websocketd/Makefile     15 May 2015 07:32:00 -0000      1.3
+++ net/websocketd/Makefile     3 Jun 2015 20:03:32 -0000
@@ -8,7 +8,7 @@ DISTNAME =              websocketd-$V
 GH_ACCOUNT =           joewalnes
 GH_PROJECT =           websocketd
 GH_TAGNAME =           v$V
-REVISION =             0
+REVISION =             1
 
 CATEGORIES =           net www
 
@@ -27,16 +27,7 @@ BUILD_DEPENDS =              net/go-websocket
 
 NO_TEST =              Yes
 
-post-extract:
-       mkdir -p ${WRKSRC}/src/github.com/joewalnes
-       ln -fhs ${WRKSRC} ${WRKSRC}/src/github.com/joewalnes/websocketd
-
-do-build:
-       GOPATH=${GOPATH} go build -o ${WRKDIST}/websocketd              \
-           github.com/joewalnes/websocketd
-
-do-install:
-       ${INSTALL_PROGRAM} -p ${WRKDIST}/websocketd ${PREFIX}/bin
+post-install:
        ${INSTALL_MAN} ${WRKSRC}/release/websocketd.man                 \
            ${PREFIX}/man/man8/websocketd.8
        ${INSTALL_DATA_DIR} ${PREFIX}/share/examples/websocketd
Index: sysutils/logstash/forwarder/Makefile
===================================================================
RCS file: /var/cvs/ports/sysutils/logstash/forwarder/Makefile,v
retrieving revision 1.4
diff -u -p -r1.4 Makefile
--- sysutils/logstash/forwarder/Makefile        15 May 2015 07:37:14 -0000      
1.4
+++ sysutils/logstash/forwarder/Makefile        3 Jun 2015 20:03:32 -0000
@@ -6,6 +6,7 @@ GH_ACCOUNT=     elastic
 GH_PROJECT=    logstash-forwarder
 GH_TAGNAME=    v0.4.0
 DISTNAME=      ${GH_PROJECT}-${GH_TAGNAME:S/v//}
+REVISION=      0
 
 MODULES=       lang/go
 
@@ -13,14 +14,9 @@ NO_TEST=     Yes
 
 WANTLIB +=     c pthread
 
-do-build:
-       cd ${WRKSRC} && go build -o logstash-forwarder
-
-pre-configure:
-       ${SUBST_CMD} ${WRKSRC}/logstash-forwarder.conf.example
-
 do-install:
-       ${INSTALL_PROGRAM} ${WRKSRC}/logstash-forwarder ${PREFIX}/sbin/
+       ${INSTALL_PROGRAM} ${MODGO_WORKSPACE}/bin/logstash-forwarder \
+               ${PREFIX}/sbin/
        ${INSTALL_DATA_DIR} ${PREFIX}/share/{doc,examples}/logstash-forwarder/
        ${INSTALL_DATA} ${WRKSRC}/README.md \
                ${PREFIX}/share/doc/logstash-forwarder/

Attachment: go-tools.tgz
Description: application/tar-gz

Attachment: hub.tgz
Description: application/tar-gz

Index: share/man/man5/port-modules.5
===================================================================
RCS file: /var/cvs/src/share/man/man5/port-modules.5,v
retrieving revision 1.188
diff -u -p -r1.188 port-modules.5
--- share/man/man5/port-modules.5       2 Apr 2015 15:47:40 -0000       1.188
+++ share/man/man5/port-modules.5       5 Jun 2015 18:55:31 -0000
@@ -734,6 +734,121 @@ command can be specified with
 .Ev MODGHC_SETUP_CONF_ARGS
 and
 .Ev MODGHC_SETUP_CONF_ENV .
+.It lang/go
+Adds Go toolchain support.
+Requires
+.Ev ALL_TARGET
+to be set to canonical Go import path of port.
+(Module sets it automatically for ports that use
+.Ev GH_ACCOUNT
+and
+.Ev GH_PROJECT
+macros.)
+.Pp
+During execution of
+.Ar post-patch
+target module moves source code from
+.Pa ${MODGO_SUBDIR}
+to
+.Pa ${WRKSRC} ,
+subdirectory of
+.Pa ${MODGO_WORKSPACE}
+- specially-crafted Go workspace located at
+.Pa ${WRKDIR}/go .
+During
+.Ar do-build
+module calls
+.Dq go install
+with
+.Ev GOPATH
+set to
+.Pa ${MODGO_WORKSPACE} ,
+runs its output through sed to prevent writes outside
+.Ev WRKDIR
+sandbox and sends output to
+.Xr sh 1 .
+During
+.Ar do-install
+it copies executables from
+.Pa ${MODGO_WORKSPACE}/bin
+to
+.Pa ${PREFIX}/bin ,
+and/or directories
+.Pa ${MODGO_WORKSPACE}/pkg
+and
+.Pa ${MODGO_WORKSPACE}/src
+to
+.Pa ${PREFIX}/go ,
+depending on
+.Ev MODGO_TYPE
+contents.
+.Pp
+Sets
+.Ev BUILD_DEPENDS ,
+.Ev RUN_DEPENDS ,
+.Ev ALL_TARGET ,
+.Ev TEST_TARGET ,
+.Ev ONLY_FOR_ARCHS ,
+.Ev SEPARATE_BUILD ,
+and
+.Ev WRKSRC .
+.Pp
+Defines:
+.Bl -tag -width MODGO_WORKSPACE
+.It Ev MODGO_TYPE
+Type of port.
+May be any combination of:
+.Bl -tag -width lib
+.It bin
+ordinary binary, which should be installed to
+.Pa ${PREFIX}/bin ,
+.It lib
+library, which should come with source code.
+.El
+.Pp
+Defaults to
+.Ar bin .
+.It Ev MODGO_WORKSPACE
+Path to Go workspace set up for port build process.
+Defaults to
+.Pa ${WRKDIR}/go .
+See Go documentation for details.
+.It Ev MODGO_SUBDIR
+Path to Go source code within port's sources tarball.
+Defaults to
+.Pa ${WRKDIST} .
+.It Ev MODGO_SETUP_WORKSPACE
+Commands setting up Go workspace for building ports.
+By default, happens during execution of
+.Ar post-patch
+target.
+.It Ev MODGO_BUILDDEP
+Controls whether contents of
+.Ev MODGO_BUILD_DEPENDS
+are appended to port's
+.Ev BUILD_DEPENDS .
+Defaults to
+.Ar Yes .
+.El
+.Pp
+Additionally defines
+.Ev MODGO_PACKAGES ,
+.Ev MODGO_SOURCES
+and
+.Ev MODGO_TOOLS
+(paths for installed Go packages, sources and tools respectively),
+.Ev MODGO_CMD
+and
+.Ev MODGO_FLAGS
+(source code build command and flags passed as its arguments),
+.Ev MODGO_BUILD_CMD
+and
+.Ev MODGO_TEST_CMD
+(commands for building and testing go packages; normally called with canonical
+Go package names as arguments),
+.Ev MODGO_{BUILD,INSTALL,TEST}_TARGET
+and
+.Ev MODGO_{BUILD,RUN}_DEPENDS .
 .It lang/lua
 Sets
 .Ev MODLUA_BIN ,

Reply via email to