golang: Move module cache into DL_DIR

This also adds a config option GOLANG_MOD_CACHE_WORLD_READABLE; if
enabled, chmod is run after a Go package build to make all
files/directories in the module cache world-readable.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
This commit is contained in:
Jeffery To
2020-08-19 05:39:41 +08:00
parent 4674564e42
commit 3dd55b504c
4 changed files with 80 additions and 6 deletions

View File

@@ -186,6 +186,7 @@ GO_PKG_TARGET_VARS= \
GO_PKG_BUILD_VARS= \
GOPATH=$(GO_PKG_BUILD_DIR) \
GOCACHE=$(GO_PKG_CACHE_DIR) \
GOMODCACHE=$(GO_MOD_CACHE_DIR) \
GOENV=off
GO_PKG_DEFAULT_VARS= \
@@ -226,7 +227,7 @@ GoPackage/has_binaries=$(call GoPackage/is_dir_not_empty,$(GO_PKG_BUILD_BIN_DIR)
define GoPackage/Build/Configure
( \
cd $(PKG_BUILD_DIR) ; \
mkdir -p $(GO_PKG_BUILD_DIR)/bin $(GO_PKG_BUILD_DIR)/src $(GO_PKG_CACHE_DIR) ; \
mkdir -p $(GO_PKG_BUILD_DIR)/bin $(GO_PKG_BUILD_DIR)/src $(GO_PKG_CACHE_DIR) $(GO_MOD_CACHE_DIR) ; \
\
files=$$$$($(FIND) ./ \
-type d -a \( -path './.git' -o -path './$(GO_PKG_WORK_DIR_NAME)' \) -prune -o \
@@ -303,9 +304,12 @@ define GoPackage/Build/Compile
( \
cd $(GO_PKG_BUILD_DIR) ; \
export $(GO_PKG_VARS) ; \
if [ -f "$(PKG_BUILD_DIR)/go.mod" ] ; then \
modargs="$(GO_MOD_ARGS)" ; \
fi ; \
\
echo "Finding targets" ; \
targets=$$$$(go list $(GO_PKG_BUILD_PKG)) ; \
targets=$$$$(go list $$$$modargs $(GO_PKG_BUILD_PKG)) ; \
for pattern in $(GO_PKG_EXCLUDES); do \
targets=$$$$(echo "$$$$targets" | grep -v "$$$$pattern") ; \
done ; \
@@ -319,7 +323,7 @@ define GoPackage/Build/Compile
\
if [ "$(strip $(GO_PKG_SOURCE_ONLY))" != 1 ]; then \
echo "Building targets" ; \
go install $(GO_PKG_INSTALL_ARGS) $(1) $$$$targets ; \
go install $(GO_PKG_INSTALL_ARGS) $$$$modargs $(1) $$$$targets ; \
retval=$$$$? ; \
echo ; \
\
@@ -328,9 +332,9 @@ define GoPackage/Build/Compile
echo ; \
fi ; \
\
echo "Cleaning module download cache (golang/go#27455)" ; \
go clean -modcache ; \
echo ; \
if [ "$$$$retval" -ne 0 ]; then \
$(call Go/CacheCleanup) ; \
fi ; \
fi ; \
exit $$$$retval ; \
)
@@ -362,6 +366,7 @@ endef
ifneq ($(strip $(GO_PKG)),)
Build/Configure=$(call GoPackage/Build/Configure)
Build/Compile=$(call GoPackage/Build/Compile)
Hooks/Compile/Post+=Go/CacheCleanup
Build/InstallDev=$(call GoPackage/Build/InstallDev,$(1))
endif