Skip to content

Commit

Permalink
cmd/go: add basic support for overlays
Browse files Browse the repository at this point in the history
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 <matloob@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
  • Loading branch information
matloob committed Oct 6, 2020
1 parent f8d8097 commit ab2a5b4
Show file tree
Hide file tree
Showing 13 changed files with 1,081 additions and 53 deletions.
12 changes: 12 additions & 0 deletions src/cmd/go/internal/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import (
"fmt"
"go/build"
"internal/cfg"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"sync"

"cmd/go/internal/fsys"

"cmd/internal/objabi"
)

Expand Down Expand Up @@ -104,6 +107,15 @@ func defaultContext() build.Context {
// Nothing to do here.
}

ctxt.OpenFile = func(path string) (io.ReadCloser, error) {
return fsys.Open(path)
}
ctxt.ReadDir = fsys.ReadDir
ctxt.IsDir = func(path string) bool {
isDir, err := fsys.IsDir(path)
return err == nil && isDir
}

return ctxt
}

Expand Down
5 changes: 5 additions & 0 deletions src/cmd/go/internal/envcmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"cmd/go/internal/base"
"cmd/go/internal/cache"
"cmd/go/internal/cfg"
"cmd/go/internal/fsys"
"cmd/go/internal/load"
"cmd/go/internal/modload"
"cmd/go/internal/work"
Expand Down Expand Up @@ -197,6 +198,10 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) {
env := cfg.CmdEnv
env = append(env, ExtraEnvVars()...)

if err := fsys.Init(base.Cwd); err != nil {
base.Fatalf("go: %v", err)
}

// Do we need to call ExtraEnvVarsCostly, which is a bit expensive?
// Only if we're listing all environment variables ("go env")
// or the variables being requested are in the extra list.
Expand Down
Loading

0 comments on commit ab2a5b4

Please sign in to comment.