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

Add, update, and remove repository rules #56

Open
jayconrod opened this issue Dec 27, 2017 · 7 comments
Open

Add, update, and remove repository rules #56

jayconrod opened this issue Dec 27, 2017 · 7 comments

Comments

@jayconrod
Copy link
Contributor

This is a catch-all issues for Gazelle repository rule management.

Gazelle will support an update-repos command. This will be able to:

  • Add, remove, or update a repository rule in WORKSPACE for a specific dependency.
  • Add repository rules for direct and transitive dependencies, based on import paths from Go libraries.
  • Update a set of repository rules (possibly all).
  • Remove repository rules for dependencies that aren't needed anymore.
jayconrod pushed a commit to jayconrod/bazel-gazelle that referenced this issue Jan 29, 2018
The update-repos command can now add or update go_repository rules by
import path. To use:

    gazelle update-repos example.com/repo1 example.com/repo2

This will automatically discover the remote, VCS, and latest commit
for each repository containing the named packages. If a repository
already exists in WORKSPACE, it will be updated in place.

This functionality replaces wtool, which will be deleted soon after
this lands.

Related bazelbuild#56
jayconrod added a commit that referenced this issue Jan 31, 2018
The update-repos command can now add or update go_repository rules by
import path. To use:

    gazelle update-repos example.com/repo1 example.com/repo2

This will automatically discover the remote, VCS, and latest commit
for each repository containing the named packages. If a repository
already exists in WORKSPACE, it will be updated in place.

Related #56
@ashi009
Copy link
Contributor

ashi009 commented Jun 28, 2018

I guess this will not come before vgo hits GA?

@jayconrod
Copy link
Contributor Author

Not sure what you mean by GA. The earliest vgo could possibly become the official Go build system is Go 1.12 (next winter). It will be shipped in the 1.11 SDK as an experimental tool.

I'll get this functionality in as soon as I can, but there are a lot of things going on in parallel right now. We'll probably want more direct support for importing vgo mod files, too.

@ashi009
Copy link
Contributor

ashi009 commented Jun 28, 2018 via email

@clintberry
Copy link

The link to the tool that adds repo rules to WORKSPACE doesn't appear to work anymore. The link is in this comment: bazelbuild/rules_go#295 (comment)

What is the latest and greatest way to update the WORKSPACE with all my external dependencies automagically? :-)

@linzhp
Copy link
Contributor

linzhp commented Nov 27, 2019

To get the transitive dependencies of an external package, I am thinking about the following:

  1. Create a Go module in TempDir
  2. Convert the existing go_repository rules into the new go.mod file in TempDir.
  3. Run go get import/path@vx.x.x in the TempDir
  4. Add/update existing go_repository rules based on the new go.mod/go.sum files

I don't want to assume go.mod file exists in the main repo, and instead use go_repository rules as the source of truth in Step 2.

@jayconrod What do you think?

@jayconrod
Copy link
Contributor Author

@linzhp I'm not sure the go command should be involved at all in this process. There may be a number of workspaces declared with http_archive or other repository rules, and go get won't be able to work with those. Gazelle won't be able to update those, but it should still be able to load dependencies from them.

Some more thought also needs to go into making this language agnostic.

@linzhp
Copy link
Contributor

linzhp commented Dec 2, 2019

I agree that we should make this language agnostic by having each language extension implement how they get their dependencies and resolve the versions. But for Go, I don't see a big issue with the "go get" approach:

  • With close to 1000 external libraries we are using in our Go repo, we don't see any other Go library except Gazelle itself for which we cannot use go_repository. We even use go_repository for some repos that only contain proto files and use them to generate Go code at build time.
  • Gazelle only generates go_repository rules for Go libraries. I think it's a fair assumption that if people decide to use http_archive or other workspace rules to download their Go libraries, they will have to manage those rules themselves.
  • With no public API available, go get seems the only way we can resolve the transitive deps and their version in a consistent way to the Go modules system. Gazelle calls other go subcommands anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants