bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.38k stars 656 forks source link

bug(nogo): false positive dependency cycle issues #4073

Closed tyler-french closed 1 month ago

tyler-french commented 1 month ago

Create

Test in providers depends on test package library: providers/BUILD.bazel

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "go_default_library",
    srcs = [... ],
    importpath = "providers",
    visibility = ["//visibility:public"],
    deps = [... ],
)

go_test(
    name = "go_default_test",
    srcs = [...],
    embed = [":go_default_library"],
    deps = [
        "//src/code.uber.internal/.../test:go_default_library",
        ...
    ],
)

test library depends on providers library target: test/BUILD.bazel:

load("@io_bazel_rules_go//go:def.bzl", "go_library")

filegroup(
    name = "test",
    srcs = glob(["**"]),
    visibility = ["//visibility:public"],
)

go_library(
    name = "go_default_library",
    srcs = [...],
    importpath = "test",
    visibility = ["//visibility:public"],
    deps = [
        "//src/code.uber.internal/.../providers:go_default_library",
    ],
)

package providers test:

package providers_test

import (
    "testing"

    "code.uber.internal/test"
    "code.uber.internal/providers"
)

Expected: no failure since there is not actually a cycle in the graph.

Error:


ERROR: /home/testuser/go-code/src/code.uber.internal/.../BUILD.bazel:175:8: Running nogo on //src/code.uber.internal/...:go_default_test failed: (Exit 1): builder failed: error executing RunNogo command (from target //src/code.uber.internal/...:go_default_test) bazel-out/k8-opt-exec-ST-a828a81199fe/bin/external/go_sdk/builder_reset/builder ... (remaining 1 argument skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
nogo: dependency cycle detected between "code.uber.internal/.../providers" and "code.uber.internal/.../test" in file "src/code.uber.internal/...providers/adjust_fare_to_target_test.go"
INFO: Elapsed time: 128.960s, Critical Path: 43.32s
INFO: 21054 processes: 12694 remote cache hit, 2961 internal, 2805 linux-sandbox, 2594 processwrapper-sandbox.
ERROR: Build did NOT complete successfully
FAILED: