go_library: add importpath_aliases attribute (#2068)

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
17 files changed