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 · 8 comments
Open

cmd/go: support ~ in replace statements #33586

FiloSottile opened this issue Aug 11, 2019 · 8 comments

Comments

@FiloSottile
Copy link
Member

@FiloSottile FiloSottile commented Aug 11, 2019

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

This comment has been minimized.

Copy link
Contributor

@robpike robpike commented Aug 12, 2019

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

@FiloSottile

This comment has been minimized.

Copy link
Member Author

@FiloSottile FiloSottile commented Aug 12, 2019

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

This comment has been minimized.

Copy link
Contributor

@cuonglm 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

This comment has been minimized.

Copy link
Contributor

@robpike 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
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills 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.

@ianthehat

This comment has been minimized.

Copy link

@ianthehat ianthehat commented Aug 12, 2019

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

This comment has been minimized.

Copy link
Member

@bcmills 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

This comment has been minimized.

Copy link

@iapyeh 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.