You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 $?"
The text was updated successfully, but these errors were encountered:
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.
by ej@evanjones.ca:
The text was updated successfully, but these errors were encountered: