Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: GOCACHE=off doesn't work if the compiled binary is already there #25929

Closed
hirochachacha opened this issue Jun 17, 2018 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hirochachacha
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

  1. write a code.
$ cat x.go
package main

func main() {
}
  1. go build without caching
$ GOCACHE=off go build -x x.go
WORK=/var/folders/ch/83g06zb552q0x4phn3zv14sr0000gn/T/go-build895690551
mkdir -p $WORK/b001/
cat >$WORK/b001/importcfg << 'EOF' # internal
# import config
packagefile runtime=/Users/hiro/go/pkg/darwin_amd64/runtime.a
EOF
cd /Users/hiro
./go/pkg/tool/darwin_amd64/compile -o $WORK/b001/_pkg_.a -trimpath $WORK/b001 -p main -complete -buildid XWpnY2Jb0l3Ag5SxF9tS/XWpnY2Jb0l3Ag5SxF9tS -D _/Users/hiro -importcfg $WORK/b001/importcfg -pack -c=4 ./x.go
/Users/hiro/go/pkg/tool/darwin_amd64/buildid -w $WORK/b001/_pkg_.a # internal
cat >$WORK/b001/importcfg.link << 'EOF' # internal
packagefile command-line-arguments=$WORK/b001/_pkg_.a
packagefile runtime=/Users/hiro/go/pkg/darwin_amd64/runtime.a
packagefile internal/bytealg=/Users/hiro/go/pkg/darwin_amd64/internal/bytealg.a
packagefile internal/cpu=/Users/hiro/go/pkg/darwin_amd64/internal/cpu.a
packagefile runtime/internal/atomic=/Users/hiro/go/pkg/darwin_amd64/runtime/internal/atomic.a
packagefile runtime/internal/sys=/Users/hiro/go/pkg/darwin_amd64/runtime/internal/sys.a
EOF
mkdir -p $WORK/b001/exe/
cd .
/Users/hiro/go/pkg/tool/darwin_amd64/link -o $WORK/b001/exe/a.out -importcfg $WORK/b001/importcfg.link -buildmode=exe -buildid=iZ9HlFqFeDlyv66b2Pq4/XWpnY2Jb0l3Ag5SxF9tS/lnDZh39OUxQs_p0Z4vt2/iZ9HlFqFeDlyv66b2Pq4 -extld=clang $WORK/b001/_pkg_.a
/Users/hiro/go/pkg/tool/darwin_amd64/buildid -w $WORK/b001/exe/a.out # internal
mv $WORK/b001/exe/a.out x
rm -r $WORK/b001/
  1. go build without caching
$ GOCACHE=off go build -x x.go
WORK=/var/folders/ch/83g06zb552q0x4phn3zv14sr0000gn/T/go-build773387881
  1. clean up
$ rm x
  1. go build without caching
$ GOCACHE=off go build -x x.go
WORK=/var/folders/ch/83g06zb552q0x4phn3zv14sr0000gn/T/go-build315202340
mkdir -p $WORK/b001/
cat >$WORK/b001/importcfg << 'EOF' # internal
# import config
packagefile runtime=/Users/hiro/go/pkg/darwin_amd64/runtime.a
EOF
cd /Users/hiro
./go/pkg/tool/darwin_amd64/compile -o $WORK/b001/_pkg_.a -trimpath $WORK/b001 -p main -complete -buildid XWpnY2Jb0l3Ag5SxF9tS/XWpnY2Jb0l3Ag5SxF9tS -D _/Users/hiro -importcfg $WORK/b001/importcfg -pack -c=4 ./x.go
/Users/hiro/go/pkg/tool/darwin_amd64/buildid -w $WORK/b001/_pkg_.a # internal
cat >$WORK/b001/importcfg.link << 'EOF' # internal
packagefile command-line-arguments=$WORK/b001/_pkg_.a
packagefile runtime=/Users/hiro/go/pkg/darwin_amd64/runtime.a
packagefile internal/bytealg=/Users/hiro/go/pkg/darwin_amd64/internal/bytealg.a
packagefile internal/cpu=/Users/hiro/go/pkg/darwin_amd64/internal/cpu.a
packagefile runtime/internal/atomic=/Users/hiro/go/pkg/darwin_amd64/runtime/internal/atomic.a
packagefile runtime/internal/sys=/Users/hiro/go/pkg/darwin_amd64/runtime/internal/sys.a
EOF
mkdir -p $WORK/b001/exe/
cd .
/Users/hiro/go/pkg/tool/darwin_amd64/link -o $WORK/b001/exe/a.out -importcfg $WORK/b001/importcfg.link -buildmode=exe -buildid=iZ9HlFqFeDlyv66b2Pq4/XWpnY2Jb0l3Ag5SxF9tS/lnDZh39OUxQs_p0Z4vt2/iZ9HlFqFeDlyv66b2Pq4 -extld=clang $WORK/b001/_pkg_.a
/Users/hiro/go/pkg/tool/darwin_amd64/buildid -w $WORK/b001/exe/a.out # internal
mv $WORK/b001/exe/a.out x
rm -r $WORK/b001/

What did you expect to see?

The output of the step 3 is similar to the step 2 and the step 5.

What did you see instead?

GOCACHE=off doesn't force rebuilding.

Does this issue reproduce with the latest release (go1.10.3)?

I think so.

System details

go version devel +05f8b44d5e Sun Jun 17 08:48:39 2018 +0000 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hiro/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hiro/.go"
GOPROXY=""
GORACE=""
GOROOT="/Users/hiro/go"
GOTMPDIR=""
GOTOOLDIR="/Users/hiro/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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/ch/83g06zb552q0x4phn3zv14sr0000gn/T/go-build502207139=/tmp/go-build -gno-record-gcc-switches -fno-common"
VGOMODROOT=""
GOROOT/bin/go version: go version devel +05f8b44d5e Sun Jun 17 08:48:39 2018 +0000 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +05f8b44d5e Sun Jun 17 08:48:39 2018 +0000
uname -v: Darwin Kernel Version 17.6.0: Tue May  8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.5
BuildVersion:	17F77
lldb --version: lldb-902.0.79.7
  Swift-4.1

Maybe, this is an intended behavior. Even so, -x message can be improved.
For example, I'd rather see

# compiled binary 'x' founded. build steps were skipped.

than

WORK=/var/folders/ch/83g06zb552q0x4phn3zv14sr0000gn/T/go-build773387881
@andybons
Copy link
Member

@ianlancetaylor @rsc

@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 18, 2018
@andybons andybons added this to the Unplanned milestone Jun 18, 2018
@ianlancetaylor ianlancetaylor modified the milestones: Unplanned, Go1.12 Jun 18, 2018
@rsc
Copy link
Contributor

rsc commented Oct 24, 2018

This is completely working as intended. GOCACHE=off disables the use of the "build cache" but not the preinstalled artifacts in GOPATH/pkg nor the possibly-already-built target binary. GOCACHE=off does not mean "rebuild everything".

If you really want to just rebuild everything, use -a, which means "rebuild everything".

@rsc rsc closed this as completed Oct 24, 2018
@golang golang locked and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants