From 5e35764d3fd974205e7dde698484e072269d7fd4 Mon Sep 17 00:00:00 2001 From: Cameron Nemo Date: Tue, 18 Jun 2019 19:37:27 -0700 Subject: [PATCH] build-style: use XBPS_MAKEJOBS to set go processes Clean up some minor unnecessary bashisms, and an unquoted variable. --- Manual.md | 7 ++++++- common/build-style/go.sh | 16 ++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Manual.md b/Manual.md index 5c5d3aa03fe..d29afbd2cce 100644 --- a/Manual.md +++ b/Manual.md @@ -1472,7 +1472,7 @@ Go packages should be built with the `go` build style, if possible. The `go` build style takes care of downloading Go dependencies and setting up cross compilation. -The following variables influence how Go packages are built: +The following template variables influence how Go packages are built: - `go_import_path`: The import path of the package included in the distfile, as it would be used with `go get`. For example, GitHub's @@ -1491,6 +1491,11 @@ The following variables influence how Go packages are built: accepted by `go build -mod MODE`. Defaults to `vendor` if there's a vendor directory, otherwise `default`. +The following environment variables influence how Go packages are built: + +- `XBPS_MAKEJOBS`: Value passed to the `-p` flag of `go install`, to + control the parallelism of the Go compiler. + Occasionally it is necessary to perform operations from within the Go source tree. This is usually needed by programs using go-bindata or otherwise preping some assets. If possible do this in pre_build(). diff --git a/common/build-style/go.sh b/common/build-style/go.sh index 98f95bea2e5..97412843b20 100644 --- a/common/build-style/go.sh +++ b/common/build-style/go.sh @@ -12,31 +12,31 @@ do_configure() { # This isn't really configuration, but its needed by packages # that do unusual things with the build where the expect to be # able to cd into the $GOSRCPATH - if [[ "${go_mod_mode}" != "off" ]] && [[ -f go.mod ]]; then + if [ "${go_mod_mode}" != "off" ] && [ -f go.mod ]; then # Skip GOPATH symlink for Go modules msg_normal "Building $pkgname using Go modules.\n" - elif [[ "${go_get}" != "yes" ]]; then + elif [ "${go_get}" != "yes" ]; then mkdir -p ${GOSRCPATH%/*}/ - ln -fs $PWD "${GOSRCPATH}" + ln -fs "$PWD" "${GOSRCPATH}" fi } do_build() { go_package=${go_package:-$go_import_path} # Build using Go modules if there's a go.mod file - if [[ "${go_mod_mode}" != "off" ]] && [[ -f go.mod ]]; then - if [[ -z "${go_mod_mode}" ]] && [[ -d vendor ]]; then + if [ "${go_mod_mode}" != "off" ] && [ -f go.mod ]; then + if [ -z "${go_mod_mode}" ] && [ -d vendor ]; then msg_normal "Using vendor dir for $pkgname Go dependencies.\n" go_mod_mode=vendor - elif [[ "${go_mod_mode}" = "default" ]]; then + elif [ "${go_mod_mode}" = "default" ]; then # Allow templates to explicitly opt into the go tool's # default behavior. go_mod_mode= fi - go install -mod="${go_mod_mode}" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package} + go install -p "$XBPS_MAKEJOBS" -mod="${go_mod_mode}" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package} else # Otherwise, build using GOPATH - go get -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package} + go get -p "$XBPS_MAKEJOBS" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package} fi }