Skip to content

Commit 74192b2

Browse files
ianoc-stripejohnynek
authored andcommitted
Make the scala_protobuf aspect based (bazel-contrib#700)
* Run a test with custom javabin * Respect java bin overrides * Try set a different variable * The action_should_fail tests have been broken :( , without assigning the results of the stdout of calling bazel to a variable, bash will try execute it. So the response code here will always have been on the next line -1 * Empty commit to trigger travis * Make the scala_protobuf aspect based * Use default toolchain? * Remove print * Remove prints * Remove println * Import files * Default produce services code * Support dependencies on scala * Add support for blacklisted protos * Remove references to with_java * Provider * Code generator to toolchain * Move the configuration options to the toolchain and add a comment * Remove unused code * Remove unused code, and get the classpath for compiling to not be the transitive compile time one * Remove unused extra generator code for now * Using new bazel this works * Use the google protoc * Add the override generator piping * Show target overriding with a custom code generator * Add 0.23 travis builds * Some cleanup * remove duplicated lines * Remove older targets from travis since they fail, update readme with advice * Review comments * Remove override generator paths
1 parent f3113fb commit 74192b2

File tree

18 files changed

+938
-605
lines changed

18 files changed

+938
-605
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ env:
1919
# See https://github.com/bazelbuild/rules_scala/pull/622
2020
# we want to test the last release
2121
#- V=0.16.1 TEST_SCRIPT=test_lint.sh
22-
- V=0.17.1 TEST_SCRIPT=test_rules_scala.sh
23-
- V=0.22.0 TEST_SCRIPT=test_rules_scala.sh
22+
- V=0.23.1 TEST_SCRIPT=test_rules_scala.sh
2423
#- V=0.14.1 TEST_SCRIPT=test_intellij_aspect.sh
25-
- V=0.17.1 TEST_SCRIPT=test_reproducibility.sh
26-
- V=0.22.0 TEST_SCRIPT=test_reproducibility.sh
24+
- V=0.23.1 TEST_SCRIPT=test_reproducibility.sh
2725

2826
before_install:
2927
- |

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ for an example workspace using another scala version.
8383

8484
## Bazel compatible versions
8585

86-
| bazel | rules_scala gitsha |
87-
|-------|--------------------|
88-
| 0.16.x | HEAD |
86+
| bazel | rules_scala gitsha |
87+
|--------|--------------------|
88+
| 0.23.x | HEAD |
89+
| 0.22.x | f3113fb6e9e35cb8f441d2305542026d98afc0a2 |
90+
| 0.16.x | f3113fb6e9e35cb8f441d2305542026d98afc0a2 |
8991
| 0.15.x | 3b9ab9be31ac217d3337c709cb6bfeb89c8dcbb1 |
9092
| 0.14.x | 3b9ab9be31ac217d3337c709cb6bfeb89c8dcbb1 |
9193
| 0.13.x | 3c987b6ae8a453886759b132f1572c0efca2eca2 |

WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_unused_deps_
114114

115115
scala_register_unused_deps_toolchains()
116116

117+
118+
register_toolchains("@io_bazel_rules_scala//test/proto:scalapb_toolchain")
119+
120+
117121
load("//scala:scala_maven_import_external.bzl", "scala_maven_import_external", "java_import_external")
118122

119123
scala_maven_import_external(

scala_proto/BUILD

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
load("//scala_proto:scala_proto_toolchain.bzl", "scala_proto_toolchain")
2+
3+
toolchain_type(
4+
name = "toolchain_type",
5+
visibility = ["//visibility:public"],
6+
)
7+
8+
scala_proto_toolchain(
9+
name = "default_toolchain_impl",
10+
with_grpc = True,
11+
with_flat_package=False,
12+
with_single_line_to_string=False,
13+
visibility = ["//visibility:public"],
14+
)
15+
16+
toolchain(
17+
name = "default_toolchain",
18+
toolchain = ":default_toolchain_impl",
19+
toolchain_type = "@io_bazel_rules_scala//scala_proto:toolchain_type",
20+
visibility = ["//visibility:public"],
21+
)
22+
23+
24+
scala_proto_toolchain(
25+
name = "enable_all_options_toolchain_impl",
26+
with_grpc = True,
27+
with_flat_package=True,
28+
# with_java=True,
29+
with_single_line_to_string=True,
30+
visibility = ["//visibility:public"],
31+
)
32+
33+
toolchain(
34+
name = "enable_all_options_toolchain",
35+
toolchain = ":enable_all_options_toolchain_impl",
36+
toolchain_type = "@io_bazel_rules_scala//scala_proto:toolchain_type",
37+
visibility = ["//visibility:public"],
38+
)

scala_proto/private/BUILD

Whitespace-only changes.

scala_proto/private/dep_sets.bzl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
SCALAPB_DEPS = [
3+
"//external:io_bazel_rules_scala/dependency/proto/scalapb_runtime",
4+
"//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java",
5+
"//external:io_bazel_rules_scala/dependency/proto/scalapb_lenses",
6+
"//external:io_bazel_rules_scala/dependency/proto/scalapb_fastparse",
7+
]
8+
9+
GRPC_DEPS = [
10+
"//external:io_bazel_rules_scala/dependency/proto/scalapb_runtime_grpc",
11+
"//external:io_bazel_rules_scala/dependency/proto/grpc_core",
12+
"//external:io_bazel_rules_scala/dependency/proto/grpc_stub",
13+
"//external:io_bazel_rules_scala/dependency/proto/grpc_protobuf",
14+
"//external:io_bazel_rules_scala/dependency/proto/grpc_netty",
15+
"//external:io_bazel_rules_scala/dependency/proto/grpc_context",
16+
"//external:io_bazel_rules_scala/dependency/proto/guava",
17+
"//external:io_bazel_rules_scala/dependency/proto/opencensus_api",
18+
"//external:io_bazel_rules_scala/dependency/proto/opencensus_contrib_grpc_metrics",
19+
"//external:io_bazel_rules_scala/dependency/proto/google_instrumentation",
20+
"//external:io_bazel_rules_scala/dependency/proto/netty_codec",
21+
"//external:io_bazel_rules_scala/dependency/proto/netty_codec_http",
22+
"//external:io_bazel_rules_scala/dependency/proto/netty_codec_http2",
23+
"//external:io_bazel_rules_scala/dependency/proto/netty_codec_socks",
24+
"//external:io_bazel_rules_scala/dependency/proto/netty_handler",
25+
"//external:io_bazel_rules_scala/dependency/proto/netty_buffer",
26+
"//external:io_bazel_rules_scala/dependency/proto/netty_transport",
27+
"//external:io_bazel_rules_scala/dependency/proto/netty_resolver",
28+
"//external:io_bazel_rules_scala/dependency/proto/netty_common",
29+
"//external:io_bazel_rules_scala/dependency/proto/netty_handler_proxy",
30+
]
31+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
load(
2+
"//scala/private:common.bzl",
3+
"write_manifest_file",
4+
)
5+
load("//scala/private:rule_impls.bzl", "compile_scala")
6+
load("//scala_proto/private:dep_sets.bzl", "SCALAPB_DEPS", "GRPC_DEPS")
7+
8+
9+
def _root_path(f):
10+
if f.is_source:
11+
return f.owner.workspace_root
12+
return "/".join([f.root.path, f.owner.workspace_root])
13+
14+
15+
def _colon_paths(data):
16+
return ":".join([
17+
f.path
18+
for f in sorted(data)
19+
])
20+
21+
22+
def proto_to_scala_src(ctx, label, code_generator, compile_proto, include_proto, transitive_proto_paths, flags, jar_output):
23+
worker_content = "{output}\n{included_proto}\n{flags_arg}\n{transitive_proto_paths}\n{inputs}\n{protoc}".format(
24+
output = jar_output.path,
25+
included_proto = "-" + ":".join(sorted(["%s,%s" % (f.root.path, f.path) for f in include_proto])),
26+
# Command line args to worker cannot be empty so using padding
27+
flags_arg = "-" + ",".join(flags),
28+
transitive_proto_paths = "-" + ":".join(sorted(transitive_proto_paths)),
29+
# Command line args to worker cannot be empty so using padding
30+
# Pass inputs seprately because they doesn't always match to imports (ie blacklisted protos are excluded)
31+
inputs = _colon_paths(compile_proto),
32+
protoc = ctx.executable._protoc.path
33+
)
34+
argfile = ctx.actions.declare_file(
35+
"%s_worker_input" % label.name,
36+
sibling = jar_output,
37+
)
38+
ctx.actions.write(output = argfile, content = worker_content)
39+
ctx.actions.run(
40+
executable = code_generator.files_to_run,
41+
inputs = compile_proto + include_proto + [argfile, ctx.executable._protoc],
42+
outputs = [jar_output],
43+
mnemonic = "ProtoScalaPBRule",
44+
progress_message = "creating scalapb files %s" % ctx.label,
45+
execution_requirements = {"supports-workers": "1"},
46+
arguments = ["@" + argfile.path],
47+
)
48+
49+

0 commit comments

Comments
 (0)