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: support ~ in replace statements #33586

Open
FiloSottile opened this issue Aug 11, 2019 · 9 comments
Open

cmd/go: support ~ in replace statements #33586

FiloSottile opened this issue Aug 11, 2019 · 9 comments
Labels
FeatureRequest GoCommand cmd/go modules NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@FiloSottile
Copy link
Contributor

I share some directories between machines with different user names. It would be useful to be able to add a statement like the following to a go.mod.

replace golang.org/x/net => ~/src/golang.org/x/net
@robpike
Copy link
Contributor

robpike commented Aug 12, 2019

Does the file support $HOME? Because ~ is some modern aberration (says the old grump).

@FiloSottile
Copy link
Contributor Author

It doesn't support $HOME either. I suggested ~ because $HOME would likely be the only expansion available, but I don't have a strong opinion between the two.

@cuonglm
Copy link
Member

cuonglm commented Aug 12, 2019

@FiloSottile I think adding this feature will be more complicated than we usually thought, I invite you to read https://unix.stackexchange.com/q/146671/38906

@robpike
Copy link
Contributor

robpike commented Aug 12, 2019

I also think it's a slippery slope to start putting expressions that must be evaluated into module specification.

@dmitshur dmitshur added this to the Go1.14 milestone Aug 12, 2019
@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Aug 12, 2019
@bcmills
Copy link
Contributor

bcmills commented Aug 12, 2019

@cuonglm, I think the natural meaning of ~/ in a Go-specific configuration file is os.UserHomeDir(), which is hopefully not ambiguous.

@bcmills bcmills added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Aug 12, 2019
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 12, 2019
@ianthehat
Copy link

If you are going to do anything at all I think it should be to call os.ExpandEnv, but my vote would be to do nothing.
The idea of a checked in module line that varies its behavior depending on which machine it is checked out on sends chills down my spine.

@bcmills
Copy link
Contributor

bcmills commented Aug 12, 2019

I tend to agree with @ianthehat and @robpike on this. Relative paths are one thing, since there is a pretty solid use-case for pointing a replace directive into the same repository. And absolute paths are probably necessary for tool-driven edits (like CI scripts that inject replace directives). But I don't see a strong use-case for variable absolute paths.

See previously #27824.

@iapyeh
Copy link

iapyeh commented Sep 19, 2019

I have a scenario for supporting ~ (expanding to user home directory):
Suppose there is a module/package named "A" on a desktop and on a notebook.
Because their username are different, "A" have two different paths:
On desktop: "A" is of path: "/home/pineapple/Dropbox/A"
On notebook: "A" is of path: "/home/orange/Dropbox/A"
On both the folder is symbolic linked to GOPATH "~/go/src/A"
So this configuration works in "package".
(For some reason that I can not change username or commit to github.com at this moment)

Now, if I want to "upgrade A" from package to module, I have to utility "replace" in go.mod to reference "A". The absolute path of "A" does not work for both. If the "replace" supports ~ or environ variables, it would be great!

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@duzy
Copy link

duzy commented Dec 11, 2020

Does it support the environment replacement (from #27824) now? Like this:

replace example.io/foo => $MYDIR/mod/foo

I happen to work with go.mod recently, and come into this need again. Unfortunately #27824 was closed due to the implementation complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest GoCommand cmd/go modules NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

10 participants