-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
Gazelle broken when go_prefix is "" #870
Comments
The direct cause of this is logic in Resolver.ResolveGo that decides whether an import path is local or not. It checks whether an import path equals the prefix or starts with the prefix followed by a slash. This is so that "foobar/baz" is not considered local under the prefix "foo". That doesn't work if your prefix is "" though. #859 will fix this, but that's a ways off. I'll put together a fix today that should mitigate this. |
Sorry this isn't fixed yet. I'm at GothamGo, and that's taking most of my time. One other complication with this is that Gazelle will view these import paths as being part of the standard library. It doesn't keep a full list of standard packages (we don't want to hard code that), so it uses a simple heuristic to check if something is standard: does not contain a dot, and not under the prefix. A possible workaround for the short term: use a non-empty prefix. So importing |
Is there a recommended directory structure for a mono-repo? Is it best practice to push all go code under a top-level "//go" sub-folder? It's kind of nice not having a go-prefix in the mono-repo because then non-go code can live with their associated service without being in a separate folder hierarchy. E.g. //go/my_service, //py/my_service, and //proto/my_service all just becomes //my_service, and the import paths in all languages are easy (for Go, python, and C++, at least). There may be drawbacks to doing this though in the long run. We're just winging it! Not sure what the "correct" approach is. |
@kgreenek At the moment, there isn't a recommended approach because We plan to deprecate |
Gazelle now allows go_prefix to be empty. It must still be set either on the command line or in a go_prefix rule. When the prefix is empty, all imports not in the standard library are resolved locally. Dependencies will not point to the vendor directory or to external repositories. * Gazelle now hard-codes a list of standard packages from the SDK that was used to build it. * All imports (including standard imports) are now added to packages.GoTarget. The resolve package filters out standard libraries. Fixes bazel-contrib#870
Gazelle now allows go_prefix to be empty. It must still be set either on the command line or in a go_prefix rule. When the prefix is empty, all imports not in the standard library are resolved locally. Dependencies will not point to the vendor directory or to external repositories. * Gazelle now hard-codes a list of standard packages from the SDK that was used to build it. * All imports (including standard imports) are now added to packages.GoTarget. The resolve package filters out standard libraries. Fixes #870
…weird stuff with the paths - manually editing the build files makes both go cmdline tool and bazel work with the import paths I want ... will revisit, see bazel-contrib/rules_go#870
I have a monorepo, where my go_prefix is set to "". The repository is structured like this:
If //my_prefix/foo/lib.go imports //my_prefix/bar, it does so as follows:
In the root BUILD.bazel file, we don't need a go_prefix, because it's already implicit in the directory structure of the monorepo. So we set go_prefix to an empty string:
I used to be able to generate BUILD files using gazelle. However, in a recent update, it stopped working.
When I run gazelle, I would expect the generated //my_prefix/foo/BUILD.bazel file to look something like:
However, deps for any modules in my WORKSPACE are not set. In other words, the dependency on "//my_prefix/bar:go_default_library" is not found. External dependencies are added correctly though.
Also, my_prefix is not a URL, it is just a string that is literally similar to "my_prefix".
The text was updated successfully, but these errors were encountered: