-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add example with go proto codegen #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
ac531ae
3002f60
48412e4
10d3551
8cf4cb6
75e9a29
3d47766
51d6bf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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", | ||
| progress_message = "Diffing %{input} to %{output}", | ||
| ) | ||
|
|
||
|
|
@@ -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} | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (for my understanding) what case does this fix?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| """.format(patch = ctx.outputs.patch.short_path))) | ||
|
|
||
| return [ | ||
| DefaultInfo(files = depset(outputs)), | ||
| DefaultInfo(files = depset([ctx.file.file1])), | ||
|
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. | ||
|
|
||
| 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"], | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.