简体   繁体   English

构建期间的模块依赖缓存问题

[英]Module dependency caching issue during build

Recently swapped to using Go 1.11 release and am trying to convert our projects over to using the new module system.最近切换到使用 Go 1.11 版本,并尝试将我们的项目转换为使用新的模块系统。 However, I'm running into a frustrating issue with the caching system (I've thus far run with GOCACHE=off because of unrelated issues in the past, but that's not an option with modules).但是,我在缓存系统方面遇到了令人沮丧的问题(由于过去不相关的问题,我迄今为止一直使用GOCACHE=off运行,但这不是模块的选项)。

The below command log is based on using a fresh upgrade of my system Go to 1.11 using Homebrew (I typically use gvm to install and manage Go versions, but swapped to system build for this to see if gvm was the issue).下面的命令日志基于使用 Homebrew 将我的系统全新升级到 1.11(我通常使用 gvm 来安装和管理 Go 版本,但为此切换到系统构建以查看 gvm 是否是问题)。 I set my GOPATH to a temporary directory and moved the source code out of the default GOPATH (it is currently at ~/gotemp/statsbot ).我将我的 GOPATH 设置为一个临时目录,并将源代码移出默认的 GOPATH(它当前位于~/gotemp/statsbot )。

For this command log, I'm nuking the cache first, to get it in a fresh state.对于此命令日志,我首先对缓存进行核处理,以使其处于全新状态。 I'm then doing a build (to pull in any missing dependencies, which should also recache deps) followed by a test on one of the subdirectories.然后我正在构建(以引入任何丢失的依赖项,这也应该重新缓存 deps),然后对其中一个子目录进行测试。

[08:34:48] statsbot (feature/bot-rebuild-gomod) $ rm -rf on

[08:34:49] statsbot (feature/bot-rebuild-gomod) $ go clean --cache

[08:34:50] statsbot (feature/bot-rebuild-gomod) $ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="on"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/tmp.3ga5Iq09"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/kaedys/gotemp/statsbot/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/go-build065167780=/tmp/go-build -gno-record-gcc-switches -fno-common"

[08:34:53] statsbot (feature/bot-rebuild-gomod) $ go build .

[08:35:01] statsbot (feature/bot-rebuild-gomod) $ ginkgo stats
Failed to compile stats:

# golang.org/x/text/runes
/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/tmp.3ga5Iq09/pkg/mod/golang.org/x/text@v0.3.0/runes/cond.go:10:2: can't open import: "golang.org/x/text/transform": open on/51/51b9b2cf5a27a7ff06942814ad6ef031de64dc6d773c835916067578ea1ae3a1-d: no such file or directory
# golang.org/x/text/encoding
/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/tmp.3ga5Iq09/pkg/mod/golang.org/x/text@v0.3.0/encoding/encoding.go:19:2: can't open import: "golang.org/x/text/encoding/internal/identifier": open on/4c/4c2fad64312f6ec34b38755ccecb96bb31c6995211f39e0eb4112abc2fac560c-d: no such file or directory
# gopkg.in/fsnotify.v1
/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/tmp.3ga5Iq09/pkg/mod/gopkg.in/fsnotify.v1@v1.4.7/kqueue.go:18:2: can't open import: "golang.org/x/sys/unix": open on/77/77790588f9aed90a52efdb1dac069953e1ea2bf82db8627a47a9492862b39c6e-d: no such file or directory

Ginkgo ran 1 suite in 4.123499564s
Test Suite Failed

I see this same error message in a number of build situations.我在许多构建情况下看到相同的错误消息。 go build . will usually succeed, but sometimes will fail with similar messages.通常会成功,但有时会失败并显示类似的消息。 Running go clean --cache invariable fixes these issue, but I don't really want to run that before every build, and it doesn't work when trying to use Ginkgo to test since that seems to involve several successive compilations.运行go clean --cache invariable 修复了这些问题,但我真的不想在每次构建之前运行它,并且在尝试使用 Ginkgo 进行测试时它不起作用,因为这似乎涉及几个连续的编译。

The error itself is what's baffling, because these files do exist:错误本身是令人困惑的,因为这些文件确实存在:

[08:40:49] statsbot (feature/bot-rebuild-gomod) $ ll on/4c
total 112
-rw-r--r--  1 kaedys  staff  18346 Sep 14 08:40:19 2018 4c1d5db302dff0381c402160d7fd2bd89a6dafd3edc61b3dbd5e8f1a85108fb7-d
-rw-r--r--  1 kaedys  staff  27980 Sep 14 08:40:45 2018 4c2fad64312f6ec34b38755ccecb96bb31c6995211f39e0eb4112abc2fac560c-d
-rw-r--r--  1 kaedys  staff    175 Sep 14 08:40:20 2018 4cbbc40c46eba0ef41f3ebd23470c3327215fa6e05e269c276c6635da79f2e8e-a
-rw-r--r--  1 kaedys  staff     13 Sep 14 08:40:20 2018 4cffcbd4a7f1255ca3696f5e24e0b1045d14c25f1f90cbbb077b5d6f2d11e68c-d

The second file in that ll is the file the second error message complained was missing, so I can only assume that either it was trying to access the file while the file was still being generated, or it was looking in a different directory (which is difficult to tell, since the error message only reports a relative path for the file). ll中的第二个文件是第二个错误消息所抱怨的文件丢失,所以我只能假设它在文件仍在生成时试图访问该文件,或者它正在寻找不同的目录(这是很难说,因为错误消息只报告了文件的相对路径)。

Posting here to see if anyone knows how to solve this or if it's something funky in my environment setup before creating an official issue on the Go github.在 Go github 上创建官方问题之前,在此处发布以查看是否有人知道如何解决此问题,或者在我的环境设置中是否有问题。

Your GOCACHE environment variable is set to "on" .您的GOCACHE环境变量设置为"on" Value of GOCACHE must be a folder, and the special "off" value means to not cache build and test results and to not use already cached data of those. GOCACHE值必须是一个文件夹,特殊的"off"值意味着不缓存构建和测试结果,也不使用那些已经缓存的数据。 There is no special value "on" .没有特殊值"on"

You don't have to set GOCACHE , as it has a default value.您不必设置GOCACHE ,因为它具有默认值。 Quoting from Command Go: Build and test caching:引自Command Go:构建和测试缓存:

The go command caches build outputs for reuse in future builds. go 命令缓存构建输出以在未来构建中重用。 The default location for cache data is a subdirectory named go-build in the standard user cache directory for the current operating system.缓存数据的默认位置是当前操作系统的标准用户缓存目录中名为 go-build 的子目录。 Setting the GOCACHE environment variable overrides this default, and running 'go env GOCACHE' prints the current cache directory.设置 GOCACHE 环境变量会覆盖此默认值,并且运行 'go env GOCACHE' 会打印当前缓存目录。 You can set the variable to 'off' to disable the cache.您可以将该变量设置为“关闭”以禁用缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM