Commit a5bfd9da authored by Bryan C. Mills's avatar Bryan C. Mills

go/build: rename WorkingDir to Dir

Fixes #36168

Change-Id: If2b7368671e83657a3a74dd030e66e7c68bf2361
Reviewed-on: https://go-review.googlesource.com/c/go/+/211657Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent ba4593ac
...@@ -144,7 +144,7 @@ pkg debug/dwarf, method (*Reader) ByteOrder() binary.ByteOrder ...@@ -144,7 +144,7 @@ pkg debug/dwarf, method (*Reader) ByteOrder() binary.ByteOrder
pkg encoding/asn1, const TagBMPString = 30 pkg encoding/asn1, const TagBMPString = 30
pkg encoding/asn1, const TagBMPString ideal-int pkg encoding/asn1, const TagBMPString ideal-int
pkg encoding/json, method (*Decoder) InputOffset() int64 pkg encoding/json, method (*Decoder) InputOffset() int64
pkg go/build, type Context struct, WorkingDir string pkg go/build, type Context struct, Dir string
pkg go/doc, func NewFromFiles(*token.FileSet, []*ast.File, string, ...interface{}) (*Package, error) pkg go/doc, func NewFromFiles(*token.FileSet, []*ast.File, string, ...interface{}) (*Package, error)
pkg go/doc, type Example struct, Suffix string pkg go/doc, type Example struct, Suffix string
pkg go/doc, type Func struct, Examples []*Example pkg go/doc, type Func struct, Examples []*Example
......
...@@ -36,13 +36,13 @@ type Context struct { ...@@ -36,13 +36,13 @@ type Context struct {
GOROOT string // Go root GOROOT string // Go root
GOPATH string // Go path GOPATH string // Go path
// WorkingDir is the caller's working directory, or the empty string to use // Dir is the caller's working directory, or the empty string to use
// the current directory of the running process. In module mode, this is used // the current directory of the running process. In module mode, this is used
// to locate the main module. // to locate the main module.
// //
// If WorkingDir is non-empty, directories passed to Import and ImportDir must // If Dir is non-empty, directories passed to Import and ImportDir must
// be absolute. // be absolute.
WorkingDir string Dir string
CgoEnabled bool // whether cgo files are included CgoEnabled bool // whether cgo files are included
UseAllFiles bool // use files regardless of +build lines, file names UseAllFiles bool // use files regardless of +build lines, file names
...@@ -1041,8 +1041,8 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode) ...@@ -1041,8 +1041,8 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode)
var absSrcDir string var absSrcDir string
if filepath.IsAbs(srcDir) { if filepath.IsAbs(srcDir) {
absSrcDir = srcDir absSrcDir = srcDir
} else if ctxt.WorkingDir != "" { } else if ctxt.Dir != "" {
return fmt.Errorf("go/build: WorkingDir is non-empty, so relative srcDir is not allowed: %v", srcDir) return fmt.Errorf("go/build: Dir is non-empty, so relative srcDir is not allowed: %v", srcDir)
} else { } else {
// Find the absolute source directory. hasSubdir does not handle // Find the absolute source directory. hasSubdir does not handle
// relative paths (and can't because the callbacks don't support this). // relative paths (and can't because the callbacks don't support this).
...@@ -1076,16 +1076,16 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode) ...@@ -1076,16 +1076,16 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode)
parent string parent string
err error err error
) )
if ctxt.WorkingDir == "" { if ctxt.Dir == "" {
parent, err = os.Getwd() parent, err = os.Getwd()
if err != nil { if err != nil {
// A nonexistent working directory can't be in a module. // A nonexistent working directory can't be in a module.
return errNoModules return errNoModules
} }
} else { } else {
parent, err = filepath.Abs(ctxt.WorkingDir) parent, err = filepath.Abs(ctxt.Dir)
if err != nil { if err != nil {
// If the caller passed a bogus WorkingDir explicitly, that's materially // If the caller passed a bogus Dir explicitly, that's materially
// different from not having modules enabled. // different from not having modules enabled.
return err return err
} }
...@@ -1105,8 +1105,8 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode) ...@@ -1105,8 +1105,8 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode)
cmd := exec.Command("go", "list", "-e", "-compiler="+ctxt.Compiler, "-tags="+strings.Join(ctxt.BuildTags, ","), "-installsuffix="+ctxt.InstallSuffix, "-f={{.Dir}}\n{{.ImportPath}}\n{{.Root}}\n{{.Goroot}}\n{{if .Error}}{{.Error}}{{end}}\n", "--", path) cmd := exec.Command("go", "list", "-e", "-compiler="+ctxt.Compiler, "-tags="+strings.Join(ctxt.BuildTags, ","), "-installsuffix="+ctxt.InstallSuffix, "-f={{.Dir}}\n{{.ImportPath}}\n{{.Root}}\n{{.Goroot}}\n{{if .Error}}{{.Error}}{{end}}\n", "--", path)
if ctxt.WorkingDir != "" { if ctxt.Dir != "" {
cmd.Dir = ctxt.WorkingDir cmd.Dir = ctxt.Dir
} }
var stdout, stderr strings.Builder var stdout, stderr strings.Builder
......
...@@ -328,7 +328,7 @@ func TestImportDirNotExist(t *testing.T) { ...@@ -328,7 +328,7 @@ func TestImportDirNotExist(t *testing.T) {
defer os.RemoveAll(emptyDir) defer os.RemoveAll(emptyDir)
ctxt.GOPATH = emptyDir ctxt.GOPATH = emptyDir
ctxt.WorkingDir = emptyDir ctxt.Dir = emptyDir
tests := []struct { tests := []struct {
label string label string
...@@ -459,7 +459,7 @@ func TestImportPackageOutsideModule(t *testing.T) { ...@@ -459,7 +459,7 @@ func TestImportPackageOutsideModule(t *testing.T) {
os.Setenv("GOPATH", gopath) os.Setenv("GOPATH", gopath)
ctxt := Default ctxt := Default
ctxt.GOPATH = gopath ctxt.GOPATH = gopath
ctxt.WorkingDir = filepath.Join(gopath, "src/example.com/p") ctxt.Dir = filepath.Join(gopath, "src/example.com/p")
want := "cannot find module providing package" want := "cannot find module providing package"
if _, err := ctxt.Import("example.com/p", gopath, FindOnly); err == nil { if _, err := ctxt.Import("example.com/p", gopath, FindOnly); err == nil {
...@@ -519,7 +519,7 @@ func TestMissingImportErrorRepetition(t *testing.T) { ...@@ -519,7 +519,7 @@ func TestMissingImportErrorRepetition(t *testing.T) {
os.Setenv("GONOPROXY", "none") os.Setenv("GONOPROXY", "none")
ctxt := Default ctxt := Default
ctxt.WorkingDir = tmp ctxt.Dir = tmp
pkgPath := "example.com/hello" pkgPath := "example.com/hello"
_, err = ctxt.Import(pkgPath, tmp, FindOnly) _, err = ctxt.Import(pkgPath, tmp, FindOnly)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment