Skip to content

Commit 406ed3a

Browse files
hyangahhajimehoshi
authored andcommitted
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 <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Hajime Hoshi <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
1 parent 51f526d commit 406ed3a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cmd/gobind/gen.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,14 @@ func defaultFileName(lang string, pkg *types.Package) string {
376376
}
377377

378378
func packageDir(path string) (string, error) {
379-
pkgs, err := packages.Load(nil, path)
379+
mode := packages.NeedFiles
380+
pkgs, err := packages.Load(&packages.Config{Mode: mode}, path)
380381
if err != nil {
381382
return "", err
382383
}
384+
if len(pkgs) == 0 || len(pkgs[0].GoFiles) == 0 {
385+
return "", fmt.Errorf("no Go package in %v", path)
386+
}
383387
pkg := pkgs[0]
384388
if len(pkg.Errors) > 0 {
385389
return "", fmt.Errorf("%v", pkg.Errors)

0 commit comments

Comments
 (0)