Skip to content

go_library: add experimental importpath_aliases attribute#2068

Merged
jayconrod merged 3 commits intobazel-contrib:masterfrom
jayconrod:min-mod-compat
Jun 28, 2019
Merged

go_library: add experimental importpath_aliases attribute#2068
jayconrod merged 3 commits intobazel-contrib:masterfrom
jayconrod:min-mod-compat

Conversation

@jayconrod
Copy link
Copy Markdown
Collaborator

importpath_aliases lets a go_library specify a list of secondary names
by which it may be imported.

This is necessary to support minimal module compatibility. For
example, suppose we have module example.com/foo/v2 which doesn't use
major version subdirectories. example.com/bar imports a library in
this module as example.com/foo (not v2). In GOPATH mode, 'go build'
internally translates the import example.com/foo/v2 to
example.com/foo. To support this in bazel, we'll require
importpath_aliases = ["example.com/foo"] so the library may be
imported with either name. Gazelle may generate these attributes,
given a command line option.

Go 1.14 will likely have more powerful replace directives, which will
also let users import packages within a module by multiple names.
importpath_aliases will be useful for supporting that as well.

Fixes #2058

importpath_aliases lets a go_library specify a list of secondary names
by which it may be imported.

This is necessary to support minimal module compatibility. For
example, suppose we have module example.com/foo/v2 which doesn't use
major version subdirectories. example.com/bar imports a library in
this module as example.com/foo (not v2). In GOPATH mode, 'go build'
internally translates the import example.com/foo/v2 to
example.com/foo. To support this in bazel, we'll require
importpath_aliases = ["example.com/foo"] so the library may be
imported with either name. Gazelle may generate these attributes,
given a command line option.

Go 1.14 will likely have more powerful replace directives, which will
also let users import packages within a module by multiple names.
importpath_aliases will be useful for supporting that as well.

Fixes bazel-contrib#2058
@jayconrod
Copy link
Copy Markdown
Collaborator Author

Holding off on submitting until the corresponding change is in Gazelle so the whole thing can be verified.

@jayconrod jayconrod merged commit 8ea79bb into bazel-contrib:master Jun 28, 2019
@jayconrod jayconrod deleted the min-mod-compat branch June 28, 2019 20:32
yushan26 pushed a commit to yushan26/rules_go that referenced this pull request Jun 16, 2025
…azel-contrib#2068)

This is just a small PR to reduce the scope of bazel-contrib#2059.

This just moves some code from one python file to a separate one.

Work towards bazel-contrib#260, bazel-contrib#1105, bazel-contrib#1868.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minimal module compatibility

2 participants