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

gazel not putting dependencies into WORKSPACE #295

Closed
justinsb opened this issue Mar 9, 2017 · 10 comments
Closed

gazel not putting dependencies into WORKSPACE #295

justinsb opened this issue Mar 9, 2017 · 10 comments
Labels

Comments

@justinsb
Copy link

justinsb commented Mar 9, 2017

I followed the instructions in the README, but gazelle does not add any of my dependencies to the WORKSPACE file. I don't know how to diagnose this - I can't see any options for verbose logging etc.

> go install k8s.io/kops/util/...

> gazelle -go_prefix k8s.io/kops/util

>  bazel build //channels/cmd/channels
...
ERROR: /home/justinsb/k8s/src/k8s.io/kops/util/channels/cmd/channels/BUILD:3:1: no such package '@io_k8s_kubernetes//pkg/api/v1': error loading package 'external': The repository named 'io_k8s_kubernetes' could not be resolved and referenced by '//channels/cmd/channels:go_default_library'.
...

WORKSPACE is unchanged - no dependencies:

git_repository(
    name = "io_bazel_rules_go",
    remote = "https://github.com/bazelbuild/rules_go.git",
    tag = "0.4.1",
)
load("@io_bazel_rules_go//go:def.bzl", "go_repositories")

go_repositories()
@justinsb justinsb changed the title gazel does not put dependencies into WORKSPACE gazel not putting dependencies into WORKSPACE Mar 9, 2017
@justinsb
Copy link
Author

justinsb commented Mar 9, 2017

(I'm pretty sure this is something odd about my repo, but I also just don't see any way to diagnose it.)

@pmbethe09
Copy link
Member

Actually you are doing nothing wrong.
Gazelle does not edit your WORKSPACE, just generate your build files. It is up to you to update your WORKSPACE with any remote dependencies.

There is a tool that mostly works called wtool,
https://github.com/bazelbuild/rules_go/tree/master/go/tools/wtool
but it is not perfect, so I haven't advertised it in the main doc.

In this case after gazelle, you would build and see this issue, then run:
wtool io_k8s_kubernetes

And try again, note this may require mutliple iterations, or you can build '-k' and add multiple repos at a time, but it is still a slightly annoying process.

@jayconrod
Copy link
Contributor

Having Gazelle update the WORKSPACE with missing dependencies would be pretty useful though. I can work on that soon.

@pmbethe09
Copy link
Member

That gets tricky. How do you know which dependencies are missing?
You encounter @io_k8s_kubernetes and @com_github_golang_protobuf and read the following WORKSPACE file (ignoring Go stuff):

load("@io_bazel_rules_go//proto/go_proto_repositories.bzl", "go_proto_repositories")
go_proto_repositories()

You would have to transitively load go_proto_repositories() from a remote repo to discover that it provides @com_github_golang_protobuf, and therefore only @io_k8s_kubernetes should be added to the WORKSPACE.

It is for this reason that I haven't added this functionality to gazelle, and wrote the quick & dirty wtool, which does not do transitive loading, but rather requires you to decide to run
wtool io_k8s_kubernetes in this situation.

@jayconrod
Copy link
Contributor

Good point, Skylark evaluation makes this a lot harder.

@justinsb
Copy link
Author

justinsb commented Mar 9, 2017

Oh thanks for the fast response & the course-correction! The README says:

By default, Gazelle will add external dependencies to your WORKSPACE file. If you prefer to use vendoring, run gazelle with -external vendored. See Vendoring.md.

Not sure if I am parsing that first sentence wrong?

@justinsb
Copy link
Author

justinsb commented Mar 9, 2017

(Trying wtool now though, but any issues there would be a separate issue I'd guess!)

@jayconrod
Copy link
Contributor

You are parsing that sentence correctly; that's my mistake. I had some misunderstanding about that earlier. Will correct today.

@justinsb
Copy link
Author

No worries, and thank you so much @jayconrod . I'll leave this open for you to track, but feel free to close at will.

wtool is much better than the alternative which is how I was doing it before, so thank you for that tool. For me the biggest painpoint was having to match the git versions to the Godeps, but I think we should probably wait for the dep tool at this point. It also got very confused by com_github_go_openapi_jsonpointer and by in_gopkg_yaml_v2, but still a vast improvement over doing it by hand!

@jayconrod
Copy link
Contributor

Migrating old Gazelle issues to the new repository. This one is bazelbuild/bazel-gazelle#56.

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

No branches or pull requests

3 participants