Tinder / bazel-diff

Performs Bazel Target Diffing between two revisions in Git, allowing for Test Target Selection and Selective Building
Other
402 stars 59 forks source link

bzlmod using local repositories #196

Open SimonVleugels opened 1 year ago

SimonVleugels commented 1 year ago

Hi, I'm trying to use bazel-diff with bzlmod enabled using only local_repositories (no connection to bcr). I'm getting unknown repo errors:

ERROR: /repo/bazel-test-repo/BUILD.bazel:9:6: error loading package '@bazel_diff~override//cli': 
Unable to find package for @[unknown repo 'rules_jvm_external' requested from @bazel_diff~override]//:defs.bzl: 
The repository '@[unknown repo 'rules_jvm_external' requested from @bazel_diff~override]' could not be resolved: 
No repository visible as '@rules_jvm_external' from repository '@bazel_diff~override'. and referenced by '//:bazel-diff'

Bazel command:

./bazel-6.3.2 run \
--override_repository=bazel_diff=/repo/bazel-test-repo/build/bazel_diff \
--override_repository=io_bazel_rules_kotlin=/repo/bazel-test-repo/build/io_bazel_rules_kotlin \
--override_repository=rules_jvm_external=/repo/bazel-test-repo/build/rules_jvm_external \
--override_repository=rules_kotlin=/repo/bazel-test-repo/build/rules_kotlin \
--override_repository=rules_proto=/repo/bazel-test-repo/build/rules_proto \
--enable_bzlmod //:bazel-diff

Not sure what I'm doing wrong.

BUILD.bazel

alias(
    name = "bazel-diff",
    actual = "@bazel_diff//cli:bazel-diff",
)

MODULE.bazel

bazel_dep(name = "rules_proto")
local_path_override(
    module_name = "rules_proto",
    path = "/repo/bazel-test-repo/build/rules_proto",
)

bazel_dep(name = "bazel_skylib")
local_path_override(
    module_name = "bazel_skylib",
    path = "/repo/bazel-test-repo/build/bazel_skylib",
)

bazel_dep(name = "io_bazel_rules_kotlin")
local_path_override(
    module_name = "io_bazel_rules_kotlin",
    path = "/repo/bazel-test-repo/build/io_bazel_rules_kotlin",
)

bazel_dep(name = "rules_jvm_external")
local_path_override(
    module_name = "rules_jvm_external",
    path = "/repo/bazel-test-repo/build/rules_jvm_external",
)

bazel_dep(name = "bazel_diff")
local_path_override(
    module_name = "bazel_diff",
    path = "/repo/bazel-test-repo/build/bazel_diff",
)

WORKSPACE

#empty
tinder-maxwellelliott commented 1 year ago

I have not tested bazel-diff with bazelmod at all yet. I likely need to add support

Venyi commented 8 months ago

Hi, @tinder-maxwellelliott , any plan to test bzlmod?

honnix commented 1 month ago

Any plan to support bzlmod? Not entirely sure but I think we have seen bazel-diff not able to find any impacted targets for a bzlmod project. I can try to prepare a repro.

honnix commented 1 month ago

Any plan to support bzlmod? Not entirely sure but I think we have seen bazel-diff not able to find any impacted targets for a bzlmod project. I can try to prepare a repro.

I put up a repro here https://github.com/honnix/bazel-diff-bzlmod-repro.

It seems to be the --useCquery being problematic.

honnix commented 1 month ago

I did some debugging and I think the problem might boil down to the canonical repo name.

compatibleTargetSet here has @@//:BUILD.bazel, @@//:hello and @@//:hello.py, while cqueryResult here has //:BUILD.bazel, //:hello and //:hello.py instead.

The canonical repo name is one of the changes made in bzlmod as I remember I read it somewhere.

Found https://docs.google.com/document/d/1N81qfCa8oskCk5LqTW-LNthy6EBrDot7bdUsjz6JFC4/edit#heading=h.5mcn15i0e1ch

honnix commented 1 month ago

I did a naive hack cqueryResult.resultsList.filter { it.target.rule.name in compatibleTargetSet || "@@${it.target.rule.name}" in compatibleTargetSet }.map { it.target } and this could give the expected impacted target.

honnix commented 1 month ago

224 might be a better fix.