Tinder / bazel-diff

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

feat: Consider putting this module to Bazel Central Registry #232

Closed honnix closed 1 month ago

honnix commented 1 month ago

Since this repo has moved to bzlmod, maybe it is a good time to add it to BCR, so it would be easier for people to use source from their projects.

The current instructions Build from source in your Bazel Project does not work anymore since migrated to bzlmod, because WORKSPACE is now empty, so there are a few things missing, mostly around rules_kotlin.

BTW, I figured out a way to build from source from our project and I think it might be worth noting.

WORKSPACE:

http_archive(
    name = "rules_kotlin",
    sha256 = "d9898c3250e0442436eeabde4e194c30d6c76a4a97f517b18cefdfd4e345725a",
    url = "https://github.com/bazelbuild/rules_kotlin/releases/download/v1.9.1/rules_kotlin-v1.9.1.tar.gz",
)

load("@rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")

kotlin_repositories()

load("@rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()

http_archive(
    name = "bazel_diff",
    patch_args = ["-p1"],
    patches = [
        "//tools/bazel_diff:cli.patch",
    ],
    sha256 = "9059cc0fe833f69c946aee9603c12122e9d40373af3f5de8ad9949cfb2ecfba2",
    strip_prefix = "bazel-diff-ba464a41076a719ffcdc1ff52240ad59c5f2a3f2",
    url = "https://github.com/Tinder/bazel-diff/archive/ba464a41076a719ffcdc1ff52240ad59c5f2a3f2.tar.gz",
)

load("@bazel_diff//:repositories.bzl", "bazel_diff_dependencies")

bazel_diff_dependencies()

load("@bazel_diff//:artifacts.bzl", "BAZEL_DIFF_MAVEN_ARTIFACTS")

maven_install(
    name = "bazel_diff_maven",
    artifacts = BAZEL_DIFF_MAVEN_ARTIFACTS,
    maven_install_json = "@bazel_diff//:maven_install.json",
    repositories = [...],
)

load("@bazel_diff_maven//:defs.bzl", bazel_diff_pinned_maven_install = "pinned_maven_install")

bazel_diff_pinned_maven_install()

cli.patch (this is needed because we don't have STABLE_GIT_TAG):

diff --git a/cli/BUILD b/cli/BUILD
index 6a0b1be..4573286 100644
--- a/cli/BUILD
+++ b/cli/BUILD
@@ -13,7 +13,7 @@ genrule(
     srcs = [],
     outs = ["version"],
     cmd_bash = """
-        version_tag=$$(grep ^STABLE_GIT_TAG bazel-out/stable-status.txt | cut -d' ' -f2); \
+        version_tag=$$(grep ^STABLE_GIT_TAG bazel-out/stable-status.txt || echo "unknown" | cut -d' ' -f2); \
         printf '%s' $$version_tag > $@;
     """,
     stamp = 1,

Even with cli.patch in place, bazel run @bazel_diff//:bazel-diff -- -V still doesn't work because it seems rules_kotlin does not handle resources well, so we end up with having a bad resources jar: ../bazel_diff/cli/version is the file packed in the jar. But this is not critical at all.

tinder-maxwellelliott commented 1 month ago

I think this is a great idea, ill need to research how to get this added

honnix commented 1 month ago

I think this is a great idea, ill need to research how to get this added

Awesome! I have never tried that myself, so no idea where to start. https://github.com/bazelbuild/bazel-central-registry/blob/main/docs/README.md this looks promising.

maxwellE commented 1 month ago

This is in progress https://github.com/bazelbuild/bazel-central-registry/pull/2893

honnix commented 1 month ago

This is in progress bazelbuild/bazel-central-registry#2893

Great this has been merged! Maybe next step is trying to make the build less setup depended, e.g. the version_tag thing.

tinder-maxwellelliott commented 1 month ago

This is in progress bazelbuild/bazel-central-registry#2893

Great this has been merged! Maybe next step is trying to make the build less setup depended, e.g. the version_tag thing.

This has been solved using the module_version Bazel native method

honnix commented 1 month ago

This is in progress bazelbuild/bazel-central-registry#2893

Great this has been merged! Maybe next step is trying to make the build less setup depended, e.g. the version_tag thing.

This has been solved using the module_version Bazel native method

Ah, I completely missed #235. That looks great. Thank you!