Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import %workspace%/tools/preset.bazelrc
common --@protobuf//bazel/toolchains:prefer_prebuilt_protoc

# Cause a build failure when files in the source tree don't match their generated counterparts.
common --@diff.bzl//diff:validate_diffs

# Don’t want to push a rules author to update their deps if not needed.
# https://bazel.build/reference/command-line-reference#flag--check_direct_dependencies
Expand Down
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ bazel_dep(name = "bazel_lib", version = "3.0.0")
bazel_dep(name = "diffutils", version = "3.12", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1", dev_dependency = True)
bazel_dep(name = "bazelrc-preset.bzl", version = "1.6.0", dev_dependency = True)
bazel_dep(name = "protobuf", version = "33.4", dev_dependency = True)
bazel_dep(name = "rules_go", version = "0.60.0", dev_dependency = True)

register_toolchains(
"//tools/toolchains:all",
Expand Down
187 changes: 185 additions & 2 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions diff/private/diff.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ def _diff_rule_impl(ctx):

# If both inputs are generated, there's no writable file to patch.
is_copy_to_source = ctx.file.file1.is_source or ctx.file.file2.is_source
outputs = [ctx.outputs.patch, ctx.outputs.exit_code]
ctx.actions.run_shell(
inputs = [ctx.file.file1, ctx.file.file2] + diffinfo.tool_files,
outputs = outputs,
outputs = [ctx.outputs.patch, ctx.outputs.exit_code],
command = command,
mnemonic = "DiffutilsDiff",
mnemonic = "Diff",
Comment thread
alexeagle marked this conversation as resolved.
Outdated
progress_message = "Diffing %{input} to %{output}",
)

Expand All @@ -82,11 +81,11 @@ def _diff_rule_impl(ctx):
ERROR: diff command exited with non-zero status.

To accept the diff, run:
patch -d \\$(bazel info workspace) -p0 < {patch}
""".format(patch = ctx.outputs.patch.path)))
patch -d \\$(bazel info workspace) -p0 < \\$(bazel info bazel-bin)/{patch}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for my understanding) what case does this fix?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's when your current working directory is not the repository root.
perhaps it should be $(bazel info workspace) still, since there are multiple bin dirs under transitions

""".format(patch = ctx.outputs.patch.short_path)))

return [
DefaultInfo(files = depset(outputs)),
DefaultInfo(files = depset([ctx.file.file1])),
Comment thread
alexeagle marked this conversation as resolved.
OutputGroupInfo(
_validation = depset(validation_outputs),
# By reading the Build Events, a Bazel wrapper can identify this diff output group and apply the patch.
Expand Down
Empty file added examples/.bazelrc
Empty file.
38 changes: 38 additions & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load("@diff.bzl", "diff")
load("@protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_go//go:def.bzl", "go_test")
load("@rules_go//proto:def.bzl", "go_proto_library")

proto_library(
name = "foo_proto",
srcs = ["foo.proto"],
)

go_proto_library(
name = "foo_go_proto",
importpath = "github.com/kormide/diff.bzl/examples/foo_go_proto",
proto = "foo_proto",
)

filegroup(
name = "go_codegen",
srcs = [":foo_go_proto"],
output_group = "go_generated_srcs",
)

diff(
name = "go_codegen_diff",
args = ["--unified"],
file1 = ":foo.pb.go",
file2 = ":go_codegen",
)

go_test(
name = "foo_usage_test",
srcs = ["foo_test.go"],
# we want to trigger the validation action to ensure this test can't run
# if the generated code is not up to date
# This is an awkward way to do this, maybe improve
data = [":go_codegen_diff"],
deps = [":foo_go_proto"],
)
Loading
Loading