[internal-branch.go1.20-vendor] internal/gcimporter: skip tests earlier when 'go build' is not available

This fixes tests failing on the Android builders on Go 1.20 after CL
454499. Previously the tests were skipped in the 'compile' helper
function, but as of that CL they fail before reaching that point due
to missing export data for packages in std.

Updates golang/go#56967.
Updates golang/go#47257.

Change-Id: Ief953b6dbc54c8e0b1f71fc18a0d6ab212caf308
Reviewed-on: https://go-review.googlesource.com/c/tools/+/454500
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
(cherry picked from commit bdcd08225250423bf7f5f70d1dad7b2f96c380f0)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462638
Reviewed-by: Russ Cox <rsc@golang.org>
diff --git a/internal/gcimporter/gcimporter_test.go b/internal/gcimporter/gcimporter_test.go
index 1e1dd35..ab9a4db 100644
--- a/internal/gcimporter/gcimporter_test.go
+++ b/internal/gcimporter/gcimporter_test.go
@@ -118,6 +118,7 @@
 
 func TestImportTestdata(t *testing.T) {
 	needsCompiler(t, "gc")
+	testenv.NeedsGoBuild(t) // to find stdlib export data in the build cache
 
 	tmpdir := mktmpdir(t)
 	defer os.RemoveAll(tmpdir)
@@ -164,6 +165,7 @@
 	}
 
 	testenv.NeedsGo1Point(t, 18) // requires generics
+	testenv.NeedsGoBuild(t)      // to find stdlib export data in the build cache
 
 	// This package only handles gc export data.
 	if runtime.Compiler != "gc" {
@@ -601,6 +603,7 @@
 func TestIssue13566(t *testing.T) {
 	// This package only handles gc export data.
 	needsCompiler(t, "gc")
+	testenv.NeedsGoBuild(t) // to find stdlib export data in the build cache
 
 	// On windows, we have to set the -D option for the compiler to avoid having a drive
 	// letter and an illegal ':' in the import path - just skip it (see also issue #3483).