Skip to content

Commit 98dd05e

Browse files
long-stripejohnynek
authored andcommitted
Move scala_binary to its own file (#813)
* add a note about code organization in CONTRIBUTING.md * wip move scala_binary out * fully split out scala_binary properly * _library_outputs is the same thing as common_outputs * fix a bunch more scalac_provider references * rename scala_provider function to get_scalac_provider per review * back to the old variable names
1 parent 3fe7dee commit 98dd05e

File tree

6 files changed

+310
-264
lines changed

6 files changed

+310
-264
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ Before you start working on a larger contribution, you should get in touch
1717
with us first. Use the issue tracker to explain your idea so we can help and
1818
possibly guide you.
1919

20+
### Code organization
21+
22+
Core Scala rules (including their implementations) and macros go in [./scala/private/rules/](./scala/private/rules/)
23+
and [./scala/private/macros/](./scala/private/macros/), respectively, and are re-exported for public use
24+
in [./scala/scala.bzl](./scala/scala.bzl).
25+
2026
### Code reviews and other contributions.
2127
**All submissions, including submissions by project members, require review.**
2228
Please follow the instructions in [the contributors documentation](http://bazel.io/contributing.html).

scala/private/common_attributes.bzl

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
"""Shared attributes for rules"""
2+
3+
load(
4+
"@io_bazel_rules_scala//scala/private:coverage_replacements_provider.bzl",
5+
_coverage_replacements_provider = "coverage_replacements_provider",
6+
)
7+
load(
8+
"@io_bazel_rules_scala//scala:plusone.bzl",
9+
_collect_plus_one_deps_aspect = "collect_plus_one_deps_aspect",
10+
)
11+
12+
common_attrs_for_plugin_bootstrapping = {
13+
"srcs": attr.label_list(allow_files = [
14+
".scala",
15+
".srcjar",
16+
".java",
17+
]),
18+
"deps": attr.label_list(
19+
aspects = [
20+
_collect_plus_one_deps_aspect,
21+
_coverage_replacements_provider.aspect,
22+
],
23+
providers = [[JavaInfo]],
24+
),
25+
"plugins": attr.label_list(allow_files = [".jar"]),
26+
"runtime_deps": attr.label_list(providers = [[JavaInfo]]),
27+
"data": attr.label_list(allow_files = True),
28+
"resources": attr.label_list(allow_files = True),
29+
"resource_strip_prefix": attr.string(),
30+
"resource_jars": attr.label_list(allow_files = True),
31+
"scalacopts": attr.string_list(),
32+
"javacopts": attr.string_list(),
33+
"jvm_flags": attr.string_list(),
34+
"scalac_jvm_flags": attr.string_list(),
35+
"javac_jvm_flags": attr.string_list(),
36+
"expect_java_output": attr.bool(
37+
default = True,
38+
mandatory = False,
39+
),
40+
"print_compile_time": attr.bool(
41+
default = False,
42+
mandatory = False,
43+
),
44+
}
45+
46+
common_attrs = {}
47+
48+
common_attrs.update(common_attrs_for_plugin_bootstrapping)
49+
50+
common_attrs.update({
51+
# using stricts scala deps is done by using command line flag called 'strict_java_deps'
52+
# switching mode to "on" means that ANY API change in a target's transitive dependencies will trigger a recompilation of that target,
53+
# on the other hand any internal change (i.e. on code that ijar omits) WON’T trigger recompilation by transitive dependencies
54+
"_dependency_analyzer_plugin": attr.label(
55+
default = Label(
56+
"@io_bazel_rules_scala//third_party/dependency_analyzer/src/main:dependency_analyzer",
57+
),
58+
allow_files = [".jar"],
59+
mandatory = False,
60+
),
61+
"unused_dependency_checker_mode": attr.string(
62+
values = [
63+
"warn",
64+
"error",
65+
"off",
66+
"",
67+
],
68+
mandatory = False,
69+
),
70+
"_unused_dependency_checker_plugin": attr.label(
71+
default = Label(
72+
"@io_bazel_rules_scala//third_party/unused_dependency_checker/src/main:unused_dependency_checker",
73+
),
74+
allow_files = [".jar"],
75+
mandatory = False,
76+
),
77+
"unused_dependency_checker_ignored_targets": attr.label_list(default = []),
78+
"_code_coverage_instrumentation_worker": attr.label(
79+
default = "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/coverage/instrumenter",
80+
allow_files = True,
81+
executable = True,
82+
cfg = "host",
83+
),
84+
})
85+
86+
implicit_deps = {
87+
"_singlejar": attr.label(
88+
executable = True,
89+
cfg = "host",
90+
default = Label("@bazel_tools//tools/jdk:singlejar"),
91+
allow_files = True,
92+
),
93+
"_zipper": attr.label(
94+
executable = True,
95+
cfg = "host",
96+
default = Label("@bazel_tools//tools/zip:zipper"),
97+
allow_files = True,
98+
),
99+
"_java_toolchain": attr.label(
100+
default = Label("@bazel_tools//tools/jdk:current_java_toolchain"),
101+
),
102+
"_host_javabase": attr.label(
103+
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
104+
cfg = "host",
105+
),
106+
"_java_runtime": attr.label(
107+
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
108+
),
109+
"_scalac": attr.label(
110+
default = Label(
111+
"@io_bazel_rules_scala//src/java/io/bazel/rulesscala/scalac",
112+
),
113+
),
114+
"_exe": attr.label(
115+
executable = True,
116+
cfg = "host",
117+
default = Label("@io_bazel_rules_scala//src/java/io/bazel/rulesscala/exe:exe"),
118+
),
119+
}
120+
121+
launcher_template = {
122+
"_java_stub_template": attr.label(
123+
default = Label("@io_bazel_rules_scala//java_stub_template/file"),
124+
),
125+
}
126+
127+
# Single dep to allow IDEs to pickup all the implicit dependencies.
128+
resolve_deps = {
129+
"_scala_toolchain": attr.label_list(
130+
default = [
131+
Label(
132+
"//external:io_bazel_rules_scala/dependency/scala/scala_library",
133+
),
134+
],
135+
allow_files = False,
136+
),
137+
}

scala/private/common_outputs.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Common outputs used in rule outputs"""
2+
3+
common_outputs = {
4+
"jar": "%{name}.jar",
5+
"deploy_jar": "%{name}_deploy.jar",
6+
"manifest": "%{name}_MANIFEST.MF",
7+
"statsfile": "%{name}.statsfile",
8+
}

0 commit comments

Comments
 (0)