-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: fix relative-path normalization in go.work files
We had been statting 'dir' instead of 'absDir', which statted the wrong directory if 'dir' was made relative to the location of the go.work file and that location was different from the current working directory. While we're here, I also noticed some other dir-vs.-absDir discrepancies. The haveDirs map had assumed relative, slash-separated filesystem paths, but absolute paths on Windows are not slash-separated and we do retain those. Moreover, if users hand-edit the go.work file they may introduce non-canonical paths. I have changed the haveDirs logic to retain absolute paths in their platform-specific forms, and to call DropUse with the original path from the go.work file instead of the newly-resolved path. Fixes #50931 Updates #48257 Change-Id: Ib0a46179aa20c99f045aac5c7c02dbb55da455c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/382240 Trust: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
Bryan C. Mills
committed
Feb 1, 2022
1 parent
e22a14b
commit 5522f8c
Showing
2 changed files
with
59 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
cp go.work go.work.orig | ||
|
||
# 'go work use .' should add an entry for the current directory. | ||
cd bar/baz | ||
go work use . | ||
cmp ../../go.work ../../go.work.rel | ||
|
||
# If the current directory lacks a go.mod file, 'go work use .' | ||
# should remove its entry. | ||
mv go.mod go.mod.bak | ||
go work use . | ||
cmp ../../go.work ../../go.work.orig | ||
|
||
mv go.mod.bak go.mod | ||
go work use $PWD | ||
cmpenv ../../go.work ../../go.work.abs | ||
|
||
-- go.mod -- | ||
module example | ||
go 1.18 | ||
-- go.work -- | ||
go 1.18 | ||
-- go.work.rel -- | ||
go 1.18 | ||
|
||
use bar/baz | ||
-- go.work.abs -- | ||
go 1.18 | ||
|
||
use $PWD | ||
-- bar/baz/go.mod -- | ||
module example/bar/baz | ||
go 1.18 |