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: provide way to disable use of alias #7453

Closed
rsc opened this issue Mar 4, 2014 · 6 comments
Closed

cmd/go: provide way to disable use of alias #7453

rsc opened this issue Mar 4, 2014 · 6 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Mar 4, 2014

If rsc.io/pdf redirects to github.com/rsc/pdf, we'd like some way to prevent import
"github.com/rsc/pdf".
Best suggestion so far is to make package clause look like an import statement
(optionally), so that you'd write `package pdf "rsc.io/pdf"` (by analogy with
the fully-specified `import pdf "rsc.io/pdf"`) and the compiler or the go
command would disallow use of the package under any other import path. Vendoring would
need to edit this path if present, but it already needs to edit import paths too.

There is a discussion on golang-dev with subject "locking down vanity import
paths". 

Too late for Go 1.3 but we'd like to do something for Go 1.4.
@adg
Copy link
Contributor

adg commented Mar 4, 2014

Comment 1:

https://groups.google.com/forum/#!topic/golang-dev/RgHGBXROeAw

@gopherbot
Copy link

Comment 2 by yiyu.jgl:

An alternative solution is to use a special package. For example, include in your
repository an import.go file with:
    package importPath
    
    import _ "rsc.io/pdf"
When go get finds an importPath package, it checks that it has a single import whose
path matches with the one defined by the directory name (or, alternatively, that the
imported url doesn't resolve to it, as initially proposed by rsc in golang-dev). The go
tool would otherwise ignore importPath packages, which would never be built.
I think this approach has several advantages:
- It doesn't require any change to the language or the compiler.
- It is unlikely that additional info will creep into the import.go file (as with a
.json file).
- Vendoring becomes a matter of only rewriting import paths (current tools already work
with no changes!).
- This same method could be extended to support more than one import path, although I'm
not sure we would want to do that.
One drawback that I see is that godoc would also need to be aware of importPath
packages, but it won't be more difficult than making it understand the modified package
clause.
By the way, the importPath name is of course arbitrary. I'm sure there will be some
better option. My point is that it is easy to avoid conflicts with existing package
names (something like Path or ROOT would also work, there are more radical solutions
such as "package ." or "package import" which I find less appealing because they would
require a language change).

@gopherbot
Copy link

Comment 3:

CL https://golang.org/cl/124940043 mentions this issue.

@rsc
Copy link
Contributor Author

rsc commented Aug 12, 2014

Comment 4:

This issue was closed by revision 0c61467.

Status changed to Fixed.

@gopherbot
Copy link

Comment 5:

CL https://golang.org/cl/127210043 mentions this issue.

@rsc
Copy link
Contributor Author

rsc commented Aug 12, 2014

Comment 6:

This issue was closed by revision 3763a39.

@rsc rsc added fixed labels Aug 12, 2014
@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
See golang.org/s/go14customimport for design.

Added case to deps_test to allow go/build to import regexp.
Not a new dependency, because go/build already imports go/doc
which imports regexp.

Fixes golang#7453.

LGTM=r
R=r, josharian
CC=golang-codereviews
https://golang.org/cl/124940043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
See golang.org/s/go14customimport for design.

Added case to deps_test to allow go/build to import regexp.
Not a new dependency, because go/build already imports go/doc
which imports regexp.

Fixes golang#7453.

LGTM=r
R=r, josharian
CC=golang-codereviews
https://golang.org/cl/124940043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants