Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: add a go work use command #48257

Closed
matloob opened this issue Sep 8, 2021 · 12 comments
Closed

cmd/go: add a go work use command #48257

matloob opened this issue Sep 8, 2021 · 12 comments

Comments

@matloob
Copy link
Contributor

matloob commented Sep 8, 2021

This proposal is an amendment of the Go Workspace Proposal (#45713) originally suggested by @jayconrod in a comment on that issue:

I'd like a way to add all modules in a subtree to a workspace using wildcards. Specifically, I'd like go workspace add ./....

  • go workspace use would be a better subcommand name if we end up using that in go.work.
  • I think this would help build a more familiar environment for folks used to working on related projects in GOPATH. I could put a go.work file in $GOPATH/src, then just have one VSCode window for all projects.
  • We've talked about supporting wildcards in go mod initwork and go mod editwork, but that breaks some parallelism with go mod init, which only creates an empty go.mod file, and go mod edit, which only performs low-level syntactic edits without extra processing.

This proposal would add a new go command subcommand, perhaps called go mod addwork (if #48256 is accepted, the new subcommand would be called go work add or go work use).

It would ensure that the go.work command contains modules denoted by the given pattern, removing any matches of the pattern that no longer exist on disk.

cc @bcmills @ianthehat

@gopherbot gopherbot added this to the Proposal milestone Sep 8, 2021
@seankhliao seankhliao changed the title Proposal: cmd/go: add a go mod addwork command proposal: cmd/go: add a go mod addwork command Sep 8, 2021
@bcmills
Copy link
Contributor

bcmills commented Sep 9, 2021

Would there be a corresponding command to remove modules from the workspace? (That could be useful for, say, scripting.)

@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Sep 15, 2021
@matloob
Copy link
Contributor Author

matloob commented Sep 17, 2021

Modules can still be removed by go mod editwork, and go mod addwork will remove any modules that match the pattern but don't exist on disk.

@rsc
Copy link
Contributor

rsc commented Oct 6, 2021

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc rsc moved this from Incoming to Active in Proposals (old) Oct 6, 2021
@hyangah
Copy link
Contributor

hyangah commented Oct 11, 2021

@rsc Is it possible to review #48256 together at the proposal review meetings? (go mod addwork vs go work add) That proposal is not in the active column yet.

This proposal would add a new go command subcommand, perhaps called go mod addwork (if #48256 is accepted, the new subcommand would be called go work add or go work use).

@rsc
Copy link
Contributor

rsc commented Oct 12, 2021

@hyangah added to my list for next meeting, thanks. Not sure how I missed that one.

@matloob matloob changed the title proposal: cmd/go: add a go mod addwork command proposal: cmd/go: add a go work use command Oct 12, 2021
@matloob
Copy link
Contributor Author

matloob commented Oct 12, 2021

In consultation with @jayconrod @rsc and @bcmills, we want to rename this proposed command to go work use (or go mod usework if #48256 isn't accepted). Along with renaming the command, we'd rename the directory to to use. go work use would add a single directory or set of directories stated on the command line and go work use -r would search all subdirectories recursively and add the modules it finds (or remove modules in the go.work file that are contained in the directory but no longer exist).

@rsc rsc moved this from Active to Likely Accept in Proposals (old) Oct 13, 2021
@rsc
Copy link
Contributor

rsc commented Oct 13, 2021

Based on the discussion above, this proposal seems like a likely accept.
— rsc for the proposal review group

@rsc rsc moved this from Likely Accept to Accepted in Proposals (old) Oct 20, 2021
@rsc
Copy link
Contributor

rsc commented Oct 20, 2021

No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group

@rsc rsc changed the title proposal: cmd/go: add a go work use command cmd/go: add a go work use command Oct 20, 2021
@rsc rsc modified the milestones: Proposal, Backlog Oct 20, 2021
@gopherbot
Copy link

Change https://golang.org/cl/359534 mentions this issue: cmd/go: add go work use command

@gopherbot
Copy link

Change https://golang.org/cl/359412 mentions this issue: modfile: rename directory directive to use

gopherbot pushed a commit to golang/mod that referenced this issue Nov 2, 2021
For golang/go#48257

Change-Id: I9cbb222c93a066717595bec14ff26f2902ef05d9
Reviewed-on: https://go-review.googlesource.com/c/mod/+/359412
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
gopherbot pushed a commit that referenced this issue Nov 12, 2021
For #45713, #48257

Change-Id: I7e9248f22fe7ab33b151e07cc296d64c194154e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/359534
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
@matloob
Copy link
Contributor Author

matloob commented Feb 1, 2022

This is done.

@matloob matloob closed this as completed Feb 1, 2022
@gopherbot
Copy link

Change https://golang.org/cl/382240 mentions this issue: cmd/go: fix relative-path normalization in go.work files

gopherbot pushed a commit that referenced this issue Feb 1, 2022
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 <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

5 participants