Skip to content

Commit ab2a5b4

Browse files
committed
cmd/go: add basic support for overlays
This CL adds basic support for listing packages with overlays. The new cmd/go/internal/fs package adds an abstraction for communicating with the file system that will open files according to their overlaid paths, and provides functions to override those in the build context to open overlaid files. There is also some support for executing builds on packages with overlays. In cmd/go/internal/work.(*Builder).build, paths are mapped to their overlaid paths before they are given as arguments to tools. For #39958 Change-Id: I5ec0eb9ebbca303e2f1e7dbe22ec32613bc1fd17 Reviewed-on: https://go-review.googlesource.com/c/go/+/253747 Trust: Michael Matloob <[email protected]> Trust: Jay Conrod <[email protected]> Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent f8d8097 commit ab2a5b4

File tree

13 files changed

+1081
-53
lines changed

13 files changed

+1081
-53
lines changed

src/cmd/go/internal/cfg/cfg.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import (
1111
"fmt"
1212
"go/build"
1313
"internal/cfg"
14+
"io"
1415
"io/ioutil"
1516
"os"
1617
"path/filepath"
1718
"runtime"
1819
"strings"
1920
"sync"
2021

22+
"cmd/go/internal/fsys"
23+
2124
"cmd/internal/objabi"
2225
)
2326

@@ -104,6 +107,15 @@ func defaultContext() build.Context {
104107
// Nothing to do here.
105108
}
106109

110+
ctxt.OpenFile = func(path string) (io.ReadCloser, error) {
111+
return fsys.Open(path)
112+
}
113+
ctxt.ReadDir = fsys.ReadDir
114+
ctxt.IsDir = func(path string) bool {
115+
isDir, err := fsys.IsDir(path)
116+
return err == nil && isDir
117+
}
118+
107119
return ctxt
108120
}
109121

src/cmd/go/internal/envcmd/env.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"cmd/go/internal/base"
2222
"cmd/go/internal/cache"
2323
"cmd/go/internal/cfg"
24+
"cmd/go/internal/fsys"
2425
"cmd/go/internal/load"
2526
"cmd/go/internal/modload"
2627
"cmd/go/internal/work"
@@ -197,6 +198,10 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) {
197198
env := cfg.CmdEnv
198199
env = append(env, ExtraEnvVars()...)
199200

201+
if err := fsys.Init(base.Cwd); err != nil {
202+
base.Fatalf("go: %v", err)
203+
}
204+
200205
// Do we need to call ExtraEnvVarsCostly, which is a bit expensive?
201206
// Only if we're listing all environment variables ("go env")
202207
// or the variables being requested are in the extra list.

0 commit comments

Comments
 (0)