From b614246881087000d946bedaed97d956b240e7d0 Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Fri, 29 Dec 2023 12:12:46 -0800 Subject: [PATCH] gopackagesdriver: skip root packages that can't be built Fixes #3805 --- go/tools/gopackagesdriver/packageregistry.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/go/tools/gopackagesdriver/packageregistry.go b/go/tools/gopackagesdriver/packageregistry.go index 2dc85faaa..f9082eb25 100644 --- a/go/tools/gopackagesdriver/packageregistry.go +++ b/go/tools/gopackagesdriver/packageregistry.go @@ -115,12 +115,18 @@ func (pr *PackageRegistry) Match(labels []string) ([]string, []*FlatPackage) { roots[pkg.ID] = struct{}{} } } - } else { + } else if _, ok := pr.packagesByID[label]; ok { roots[label] = struct{}{} // If an xtest package exists for this package add it to the roots if _, ok := pr.packagesByID[label+"_xtest"]; ok { roots[label+"_xtest"] = struct{}{} } + } else { + // Skip a package if we don't have .pkg.json for it. + // This happens if 'bazel query' matches the target, but 'bazel build' + // can't analyze it, for example, if target_compatible_with is set + // with contraints not compatible with the host platform. + continue } }