cmd/gobind: do not compile package just to find package dir

Gobind utilizes golang.org/x/tools/go/packages.Load to find
the directory of a package. Configure the load configuration
to just find the list of files. Zero load mode is equivalent
to combining NeedName+NeedFiles+NeedCompiledGoFiles bits.
That is unnecessary, and can increase the chance of load
failures. For example, load with the zero load mode may fail
if all the necessary cgo dependencies aren't available in the
system, but that shouldn't be critical for gobind's use case.

Updates golang/go#56292

Change-Id: Ifaf4f43e9053cf4a43fd657a9a394fc13f611576
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/443935
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/cmd/gobind/gen.go b/cmd/gobind/gen.go
index ce2bc5d..fedbc27 100644
--- a/cmd/gobind/gen.go
+++ b/cmd/gobind/gen.go
@@ -376,10 +376,14 @@
 }
 
 func packageDir(path string) (string, error) {
-	pkgs, err := packages.Load(nil, path)
+	mode := packages.NeedFiles
+	pkgs, err := packages.Load(&packages.Config{Mode: mode}, path)
 	if err != nil {
 		return "", err
 	}
+	if len(pkgs) == 0 || len(pkgs[0].GoFiles) == 0 {
+		return "", fmt.Errorf("no Go package in %v", path)
+	}
 	pkg := pkgs[0]
 	if len(pkg.Errors) > 0 {
 		return "", fmt.Errorf("%v", pkg.Errors)