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: run and build with path outside of $GOPATH doesn't rebuild out of date installed packages #8244

Closed
gopherbot opened this issue Jun 19, 2014 · 2 comments

Comments

@gopherbot
Copy link

by ej@evanjones.ca:

Summary: If you use go run or go build with a path outside of $GOPATH it doesn't check
if installed packages in $GOPATH are out of date and should be rebuilt. This happens for
both go run/build of a command (example.go), or a relative package (./relativepkg). I
believe it should, so that the results are the same as if you had not run "go
install".

go version go1.3 darwin/amd64


The following bash script can be run to reproduce this. It shows that after adding an
error to an installed package, go run of a script outside the path doesn't report the
error until the installed packages are removed.


mkdir -p newgopath/src/pathpackage
export GOPATH=`pwd`/newgopath
cat > newgopath/src/pathpackage/pkg.go <<HERE
package pathpackage

func Exported() {}
HERE
go install pathpackage
cat > cmd.go <<HERE
package main

import "pathpackage"

func main() {
  pathpackage.Exported()
}
HERE
# Build and run this program that depends on a package installed in $GOPATH: works
go run cmd.go; echo "run outside GOPATH code $?"
# Copy it into GOPATH: also works
mkdir -p newgopath/src/pathcmd
cp cmd.go newgopath/src/pathcmd
go run newgopath/src/pathcmd/cmd.go; echo "run in GOPATH code $?"
go build pathcmd; echo "build pathcmd code $?"

# Now add an error to the package: outside of GOPATH doesn't rebuild
echo "ADDING ERROR"
sleep 1 # sleep to make sure timestamp is different from go install
echo error >> newgopath/src/pathpackage/pkg.go
go run cmd.go; echo "run outside GOPATH code $?"
go run newgopath/src/pathcmd/cmd.go; echo "run in GOPATH code $?"
go build pathcmd; echo "build in GOPATH code $?"

# Remove the installed packages and all fail
echo "REMOVING INSTALLED PACKAGES"
rm -rf newgopath/pkg
go run cmd.go; echo "run outside GOPATH code $?"
go run newgopath/src/pathcmd/cmd.go; echo "run in GOPATH code $?"
go build pathcmd; echo "build in GOPATH code $?"
@minux
Copy link
Member

minux commented Jun 19, 2014

Comment 1:

search for "outside of $GOPATH" and you will find explanations.
for example, issue #6504.

Status changed to WorkingAsIntended.

@gopherbot
Copy link
Author

Comment 2 by ej@evanjones.ca:

Ah. This seems particularly bad with "go run", which is where I screwed this up. I
didn't understand why it wasn't picking up my changes in a one off script. I'd love to
see an error or warning in this case, like with go test.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants