]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: don't invoke go command when setting UseAllFiles
authorAN Long <aisk1988@gmail.com>
Mon, 1 Sep 2025 14:00:45 +0000 (23:00 +0900)
committerSean Liao <sean@liao.dev>
Wed, 4 Feb 2026 22:45:16 +0000 (14:45 -0800)
Fixes #68556

Change-Id: I36b08577243a6b3a13b3adef116411d73a2d3428
Reviewed-on: https://go-review.googlesource.com/c/go/+/700337
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/go/build/build.go
src/go/build/build_test.go

index 68fb8dbbd7ab6988303585e3fecb20aeac3ef47d..157461d1afba745ae9c677c6718341637d1c79e2 100644 (file)
@@ -1139,7 +1139,7 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode)
        // we must not being doing special things like AllowBinary or IgnoreVendor,
        // and all the file system callbacks must be nil (we're meant to use the local file system).
        if mode&AllowBinary != 0 || mode&IgnoreVendor != 0 ||
-               ctxt.JoinPath != nil || ctxt.SplitPathList != nil || ctxt.IsAbsPath != nil || ctxt.IsDir != nil || ctxt.HasSubdir != nil || ctxt.ReadDir != nil || ctxt.OpenFile != nil || !slices.Equal(ctxt.ToolTags, defaultToolTags) || !slices.Equal(ctxt.ReleaseTags, defaultReleaseTags) {
+               ctxt.JoinPath != nil || ctxt.SplitPathList != nil || ctxt.IsAbsPath != nil || ctxt.IsDir != nil || ctxt.HasSubdir != nil || ctxt.ReadDir != nil || ctxt.OpenFile != nil || !slices.Equal(ctxt.ToolTags, defaultToolTags) || !slices.Equal(ctxt.ReleaseTags, defaultReleaseTags) || ctxt.UseAllFiles {
                return errNoModules
        }
 
index 605fa365dc49877bbe0a52ea296e69e1dd662340..09fbeebdc701b1ba1c5f63d18697945b10387643 100644 (file)
@@ -828,3 +828,14 @@ func TestDirectives(t *testing.T) {
        check("XTestDirectives", p.XTestDirectives,
                `[{"//go:xtest1" "testdata/directives/c_test.go:1:1"} {"//go:xtest2" "testdata/directives/d_test.go:1:1"} {"//go:xtest3" "testdata/directives/d_test.go:2:1"}]`)
 }
+
+// TestContextImportGoWithUseAllFiles ensures that when Context.UseAllFiles is set,
+// that the Go command is not invoked
+func TestContextImportGoWithUseAllFiles(t *testing.T) {
+       ctxt := &Context{UseAllFiles: true}
+       p := &Package{}
+       got := ctxt.importGo(p, "some/package", ".", 0)
+       if got != errNoModules {
+               t.Fatalf("Error mismatch:\n\tGot:  %v\n\tWant: %v", got, errNoModules)
+       }
+}