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

Bad Gazelle BUILD file for k8s.io/apimachinery #1022

Closed
mattmoor opened this issue Nov 14, 2017 · 7 comments
Closed

Bad Gazelle BUILD file for k8s.io/apimachinery #1022

mattmoor opened this issue Nov 14, 2017 · 7 comments
Assignees

Comments

@mattmoor
Copy link

You should be able to hit this by cloning: https://github.com/mattmoor/rules_k8s (go-todo branch).

This manifests as the bazel build time error:

$ bazel build examples/todocontroller/go/...
ERROR: /home/mattmoor/.cache/bazel/_bazel_mattmoor/052ca0798388734beb518a18dbe118fe/external/io_k8s_apimachinery/pkg/runtime/schema/BUILD:54:1: no such package '@io_k8s_apimachinery//k8s.io/apimachinery/pkg/util/intstr': BUILD file not found on package path and referenced by '@io_k8s_apimachinery//pkg/runtime/schema:schema_go_proto'
ERROR: Analysis of target '//examples/todocontroller/go:controller-deployment' failed; build aborted: no such package '@io_k8s_apimachinery//k8s.io/apimachinery/pkg/util/intstr': BUILD file not found on package path
INFO: Elapsed time: 0.271s
FAILED: Build did NOT complete successfully (0 packages loaded)
    currently loading: @io_k8s_apimachinery//pkg/runtime/serializer

It seems to be a problem synthesizing BUILD rules for some targets within the apimachinery repo:

proto_library(
    name = "schema_proto",
    srcs = ["generated.proto"],
    visibility = ["//visibility:public"],
    # Should be: //pkg/util/intstr:intstr_proto
    deps = ["//k8s.io/apimachinery/pkg/util/intstr:intstr_proto"],
)

go_proto_library(
    name = "schema_go_proto",
    importpath = "k8s.io/apimachinery/pkg/runtime/schema",
    proto = ":schema_proto",
    visibility = ["//visibility:public"],
    # Should be: //pkg/util/intstr:intstr_go_proto
    deps = ["//k8s.io/apimachinery/pkg/util/intstr:go_default_library"],
)
@mattmoor
Copy link
Author

@ixdy @ianthehat @jayconrod FYI

@jayconrod jayconrod self-assigned this Nov 14, 2017
@jayconrod
Copy link
Contributor

I wasn't able to build this on my Linux workstation or on my Mac laptop. I'm getting a bunch of Python errors in repository rules. I guess I need a newer version of Python and maybe some specific system packages installed.

I took a look at k8s.io/apimachinery. There are some BUILD files in here already, but there's no BUILD file in the repository root, so Gazelle will run. Is that intentional? go_repository just checks whether the root BUILD file exists before deciding whether to run Gazelle.

The problematic package you mentioned is //pkg/runtime/schema. This contains a file generated.proto, which imports "k8s.io/apimachinery/pkg/util/intstr/generated.proto". This won't build in Bazel without modification. The import needs to be relative to the repository root.

Since the protos won't build with Bazel and there are already .pb.go files present, you probably want to set Gazelle's proto mode to "legacy" or "disable" for this repository.

go_repository(
    name = "io_k8s_apimachinery",
    commit = "18a564baac720819100827c16fdebcadb05b2d0d",
    importpath = "k8s.io/apimachinery",
    build_file_proto_mode = "disable",
)

@mattmoor
Copy link
Author

Well that got me past the issue. On to the next, thanks!

@jayconrod
Copy link
Contributor

Sure, good luck!

@filmil
Copy link

filmil commented Dec 13, 2018

Hi, folks. I stepped on this issue only now, but the suggested fix does not work in my setup. Asking gazelle to build_file_proto_mode="disable" doesn't seem to remove the broken proto rules.
Did the approach to resolve this change significantly in the past ~year?

@jayconrod
Copy link
Contributor

@filmil Are you seeing a problem building @io_k8s_apimachinery//pkg/runtime/schema:schema_go_proto? If so, could you post a minimal WORKSPACE file that reproduces this? If it's a different rule, please tell me more about your setup.

build_file_proto_mode = "disable" in go_repository prevents Gazelle from generating proto rules when it generates build files for that repository. It won't remove existing rules, but this repository doesn't have any existing build files.

@filmil
Copy link

filmil commented Dec 13, 2018

I also asked on bazel-discuss, so linking here to avoid repetition: https://groups.google.com/forum/?nomobile=true#!topic/bazel-discuss/nIG0qngfjTw

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

No branches or pull requests

3 participants