-
-
Notifications
You must be signed in to change notification settings - Fork 673
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
Adds go_repository options for using vendored code #601
Conversation
This lets BUILD files be generated for projects that use vendored dependencies with a non-standard location, such as etcd.
These attributes can be used to enable building a depended-up repository using its own vendored dependencies, instead of workspace dependencies.
Can one of the admins verify this patch? |
Related issues:
|
Could you explain more about how this would be used for etcd? I see there is a cmd/vendor directory. If I understand correctly, you'd like to be able to add etcd as an external repository in some other workspace, and you'd like the generated BUILD files to respect vendor directories that aren't at the top level. Rather than adding a new command line argument to Gazelle, I think it would be better for Gazelle to detect and use vendor directories at any place in the tree automatically (#486). I don't think we should support vendoring in directories named something other than The main deficiency of Gazelle is that it currently does a fairly simple transformation from import paths to labels without actually looking at where depended-upon packages are located or whether they exist. I'm about to start a larger project that should fix that. Improved vendoring will be part of it. |
That's correct. The only thing our builds depend on from the etcd external repository is the etcd binary.
I'm somewhat uncomfortable at the idea of Gazelle trying to auto-detect where the vendor directory is, considering how many ways there are for users to fiddle with
Could you expand on that? I don't understand why the Bazel rules should be more restrictive about directory layout than the underlying Go build system. Ideally, Bazel should be able to build any reasonably-shaped Go codebase. |
We'd like Gazelle to be simple enough to be run automatically by editors when a file is saved. Within Google, there's an analogous tool called Glaze which does this very well. In that context, there's no opportunity to pass arguments on the command line. The behavior of Gazelle should be determined by convention whenever possible.
I just meant that Gazelle shouldn't allow directories with other names (for example, |
Do you think it would make sense to have two separate modes for Gazelle? It seems like the job of "generate BUILD files in a non-Bazel source tree" is very different from "refresh existing BUILD files", and it would be a shame if the usefulness of Bazel's Go rules were limited by google3 usability requirements. Remember that
The etcd build scripts run something like If the concern is about the final directory being named "vendor", would you be OK with a flag like |
Perhaps, but this would add complexity. This would mean some options are available in one mode but not another. I'd prefer to have very little reliance on the command line.
This is roughly what we want to do though. In #460, we're planning to remove There is also some discussion on the bazel-discuss mailing list about having a central repository of BUILD files for various libraries. See meeting notes.
I think we should have a more general solution. If Gazelle sees a directory named |
That wouldn't help in this case. The etcd code layout assumes there's a single vendor directory, it just happens they've named it
Will the
What's the timeline for this work? From the discussion on #460 it sounds like removing |
I took another look at etcd, and it's stranger than I thought. I think supporting this in Gazelle is too much of a special case, and I'd rather not accept this PR. This is a situation where hand-written build files are needed. When Gazelle supports flat mode (#608), it will help generate a file that can be used with
Not sure yet. Ideally, it would be removed.
As a rough estimate, this should be done by the end of August. I'll be working on this primarily after Gophercon. |
It's now been ~3 months since this PR, and there doesn't seem to be any movement toward removing |
I'm still planning to remove In the mean time, I'm okay with landing the portion of this PR that allows vendoring to be turned on in |
Done. I moved it to a new PR since nearly all the discussion here is about the vendor prefix. |
There are two commits here:
First, I've added a
--vendor_prefix
flag to Gazelle. Setting this flag lets the caller adjust where Gazelle looks for vendored dependencies, for cases where the repository owner didn't use the defaultvendor/
location.Second, I added attributes to the
go_repository()
rule to let Gazelle use vendored dependencies in external repositories. I understand this is not quite the preferred approach of having everything inWORKSPACE
, but it makes life significantly easier when our build wants to depend on a singlego_binary()
that itself requires ~dozens of vendored dependencies.The motivating use case for us is bundling a compiled-from-Git etcd (https://github.com/coreos/etcd) into some Docker images built with Bazel's docker rules. With these changes, it's possible to depend on the etcd binary from our build without having to maintain a permanent "etcd plus BUILD rules" fork.