Skip to content

Commit

Permalink
Use the release versions of bazel-diff and bazel-differ
Browse files Browse the repository at this point in the history
This simplifies our dependency management, and prevents (particularly Go code)
from treading on dependencies that we need ourselves.
  • Loading branch information
shs96c authored and sitaktif committed Aug 8, 2024
1 parent 7391184 commit acd98d2
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 162 deletions.
32 changes: 32 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,35 @@ gazelle(
name = "gazelle",
mode = "fix",
)

config_setting(
name = "linux_arm64",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:linux",
],
)

config_setting(
name = "linux_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)

config_setting(
name = "macos_arm64",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:macos",
],
)

config_setting(
name = "macos_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
)
47 changes: 30 additions & 17 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

http_archive(
name = "bazel_gazelle",
Expand Down Expand Up @@ -60,8 +60,8 @@ load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

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

maven_install(
artifacts = [
Expand Down Expand Up @@ -96,21 +96,6 @@ load("@bazel_diff_maven//:defs.bzl", bazel_diff_pinned_maven_install = "pinned_m

bazel_diff_pinned_maven_install()

# Pull in bazel_differ for testing
http_archive(
name = "bazel_differ",
sha256 = "c9265836bafcfe2925f6c44029191cda6d4c9267299cbe3a739d859da6b3a0d3",
strip_prefix = "bazel-differ-0.0.5",
url = "https://github.com/ewhauser/bazel-differ/archive/refs/tags/v0.0.5.tar.gz",
)

load("@bazel_differ//:deps.bzl", bazel_differ_deps = "go_dependencies")

# Unfortunately if we don't vendor this file into the repo, gazelle doesn't seem to properly handle its contents.
# gazelle:repository_macro third_party/go/bazel_differ_deps.bzl%go_dependencies
# gazelle:ignore
bazel_differ_deps()

http_archive(
name = "rules_proto",
sha256 = "b9e1268c5bce4bb01ef31730300b8a4f562dc1211088f125c39af716f6f65f60",
Expand All @@ -125,3 +110,31 @@ load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_
rules_proto_dependencies()

rules_proto_toolchains()

##########################################################
# bazel-differ: https://github.com/ewhauser/bazel-differ #
##########################################################

http_file(
name = "bazel_differ_linux_arm64",
sha256 = "7a7166aa526c3688b9fb71dfc8913c35902d4a440a32ff02db55e7b91a97f666",
url = "https://github.com/ewhauser/bazel-differ/releases/download/v0.0.5/bazel-differ-linux-arm64",
)

http_file(
name = "bazel_differ_linux_x86_64",
sha256 = "ce563301a22f41cc111f2966fc77a23e655fbe1140d93b33eb4818f06c40a8d5",
url = "https://github.com/ewhauser/bazel-differ/releases/download/v0.0.5/bazel-differ-linux-x86_64",
)

http_file(
name = "bazel_differ_darwin_arm64",
sha256 = "0bcbfecfb9788764efa63922322b3c2d5a1a9c0da26b2dd8e7565ca60960e231",
url = "https://github.com/ewhauser/bazel-differ/releases/download/v0.0.5/bazel-differ-darwin-arm64",
)

http_file(
name = "bazel_differ_darwin_x86_64",
sha256 = "a18c17f1a5e9830dfadb5ad3df02b453882fc9ec46837e9f8450c655d2cbe214",
url = "https://github.com/ewhauser/bazel-differ/releases/download/v0.0.5/bazel-differ-darwin-x86_64",
)
5 changes: 0 additions & 5 deletions scripts/update-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ set -eufo pipefail

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"

# We don't want gazelle to update this vendored file, so we will need to undo any changes it makes.
cp "${SCRIPT_DIR}"/../third_party/go/bazel_differ_deps.bzl "${SCRIPT_DIR}"/../third_party/go/bazel_differ_deps.bzl.bak

bazel run @go_sdk//:bin/go -- mod tidy
echo -e 'def go_dependencies():\n pass\n' >third_party/go/deps.bzl
bazel run //:gazelle -- update-repos -from_file=go.mod -prune -to_macro "third_party/go/deps.bzl%go_dependencies"
Expand All @@ -17,6 +14,4 @@ if [[ "$(uname)" == "Darwin" ]]; then
fi
"${sed_i[@]}" 's#load("@bazel_gazelle//:deps\.bzl", "go_repository")#load("//:third_party/go/go_repository.bzl", "go_repository")#' third_party/go/deps.bzl

mv "${SCRIPT_DIR}"/../third_party/go/bazel_differ_deps.bzl.bak "${SCRIPT_DIR}"/../third_party/go/bazel_differ_deps.bzl

"${SCRIPT_DIR}"/format
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_jvm_external//:defs.bzl", "artifact")

java_test(
Expand Down Expand Up @@ -28,10 +29,10 @@ java_test(
srcs = [
"BazelDifferIntegrationTest.java",
],
data = ["@bazel_differ//cli:bazel-differ"],
data = [":bazel-differ-binary"],
env_inherit = ["CC"],
jvm_flags = [
"-Dbazel_differ=$(rootpath @bazel_differ//cli:bazel-differ)",
"-Dbazel_differ=$(rootpath :bazel-differ-binary)",
],
tags = ["no-sandbox"],
deps = [
Expand Down Expand Up @@ -120,3 +121,19 @@ java_library(
artifact("org.hamcrest:hamcrest-all"),
],
)

copy_file(
name = "bazel-differ-binary",
src = ":original-bazel-differ",
out = "bazel-differ",
)

alias(
name = "original-bazel-differ",
actual = select({
"//:linux_arm64": "@bazel_differ_linux_arm64//file",
"//:linux_x86_64": "@bazel_differ_linux_x86_64//file",
"//:macos_arm64": "@bazel_differ_darwin_arm64//file",
"//:macos_x86_64": "@bazel_differ_darwin_x86_64//file",
}),
)
138 changes: 0 additions & 138 deletions third_party/go/bazel_differ_deps.bzl

This file was deleted.

Loading

0 comments on commit acd98d2

Please sign in to comment.