Skip to content

Commit 87b2f43

Browse files
authored
Remove strict_java_deps backwards compatibility (#1033)
* Remove strict_java_deps backwards compatibility * fix * fix
1 parent 8577354 commit 87b2f43

9 files changed

+68
-37
lines changed

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ buildozer 'add deps //some_package:transitive_dependency' //some_other_package:t
266266
```
267267
Note that if you have `buildozer` installed you can just run the last line and have it automatically apply the fix for you.
268268
269+
Note that this option only applies to scala code. Any java code, even that within `scala_library` and other rules_scala rules, is still controlled by the `--strict_java_deps` command-line flag.
270+
269271
### [Experimental] Unused dependency checking
270272
To allow for better caching and faster builds we want to minimize the direct dependencies of our targets. Unused dependency checking
271273
makes sure that all targets specified as direct dependencies are actually used. If `unused_dependency_checker_mode` is set to either
@@ -302,12 +304,6 @@ It can be daunting to turn on strict deps checking or unused dependency mode che
302304
303305
We recommend turning on strict_deps_mode first, as rule `A` might have an entry `B` in its `deps`, and `B` in turn depends on `C`. Meanwhile, the code of `A` only uses `C` but not `B`. Hence, the unused dependency checker, if on, will request that `B` be removed from `A`'s deps. But this will lead to a compile error as `A` can no longer depend on `C`. However, if strict dependency checking was on, then `A`'s deps is guaranteed to have `C` in it.
304306
305-
### [Experimental] Migrating from deprecated configurations
306-
307-
There are a few deprecated configuration methods which we will be removing in the near future.
308-
309-
- The command line argument `--strict_java_deps=WARN/ERROR`. Instead, set `dependency_mode = "transitive"` on the scala toolchain, and if only a warning is desired set `strict_deps_mode = "warn"` on the toolchain. In the future, `strict_java_deps` will no longer affect how scala files are compiled. Note that `strict_java_deps` will still control java compilation.
310-
311307
## Advanced configurable rules
312308
To make the ruleset more flexible and configurable, we introduce a phase architecture. By using a phase architecture, where rule implementations are defined as a list of phases that are executed sequentially, functionality can easily be added (or modified) by adding (or swapping) phases.
313309

scala/private/common_attributes.bzl

-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ common_attrs = {}
4747
common_attrs.update(common_attrs_for_plugin_bootstrapping)
4848

4949
common_attrs.update({
50-
# using stricts scala deps is done by using command line flag called 'strict_java_deps'
51-
# switching mode to "on" means that ANY API change in a target's transitive dependencies will trigger a recompilation of that target,
52-
# on the other hand any internal change (i.e. on code that ijar omits) WON’T trigger recompilation by transitive dependencies
5350
"_dependency_analyzer_plugin": attr.label(
5451
default = Label(
5552
"@io_bazel_rules_scala//third_party/dependency_analyzer/src/main:dependency_analyzer",

scala/scala_toolchain.bzl

+7-13
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@ def _compute_dependency_tracking_method(input_dependency_tracking_method):
1919
return input_dependency_tracking_method
2020

2121
def _scala_toolchain_impl(ctx):
22-
if ctx.fragments.java.strict_java_deps != "default" and ctx.fragments.java.strict_java_deps != "off":
23-
dependency_mode = "transitive"
24-
strict_deps_mode = ctx.fragments.java.strict_java_deps
25-
unused_dependency_checker_mode = "off"
26-
dependency_tracking_method = "high-level"
27-
else:
28-
dependency_mode = ctx.attr.dependency_mode
29-
strict_deps_mode = _compute_strict_deps_mode(
30-
ctx.attr.strict_deps_mode,
31-
dependency_mode,
32-
)
22+
dependency_mode = ctx.attr.dependency_mode
23+
strict_deps_mode = _compute_strict_deps_mode(
24+
ctx.attr.strict_deps_mode,
25+
dependency_mode,
26+
)
3327

34-
unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode
35-
dependency_tracking_method = _compute_dependency_tracking_method(ctx.attr.dependency_tracking_method)
28+
unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode
29+
dependency_tracking_method = _compute_dependency_tracking_method(ctx.attr.dependency_tracking_method)
3630

3731
# Final quality checks to possibly detect buggy code above
3832
if dependency_mode not in ("direct", "plus-one", "transitive"):

test/shell/test_deps.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test_scala_import_expect_failure_on_missing_direct_deps_warn_mode() {
3939
local expected_message1="buildozer 'add deps $dependency_target1' //$test_target"
4040
local expected_message2="buildozer 'add deps $dependency_target2' //$test_target"
4141

42-
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message1}" ${test_target} "--strict_java_deps=warn" "ne" "${expected_message2}"
42+
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message1}" ${test_target} "--extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_warn" "ne" "${expected_message2}"
4343
}
4444

4545
test_plus_one_ast_analyzer_strict_deps() {

test/shell/test_helper.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ test_scala_library_expect_failure_on_missing_direct_deps() {
108108

109109
local expected_message="buildozer 'add deps $dependenecy_target' //$test_target"
110110

111-
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" $test_target "--strict_java_deps=error"
111+
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" $test_target "--extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_error"
112112
}

test/shell/test_scala_library.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test_scala_library_expect_failure_on_missing_direct_deps_warn_mode() {
8585

8686
expected_message="warning: Target '$dependenecy_target' is used but isn't explicitly declared, please add it to the deps"
8787

88-
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" ${test_target} "--strict_java_deps=warn" "ne"
88+
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" ${test_target} "--extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_warn" "ne"
8989
}
9090

9191
test_scala_library_expect_failure_on_missing_direct_deps_warn_mode_java() {
@@ -101,13 +101,13 @@ test_scala_library_expect_failure_on_missing_direct_deps_off_mode() {
101101
expected_message="test_expect_failure/missing_direct_deps/internal_deps/A.scala:[0-9+]: error: not found: value C"
102102
test_target='test_expect_failure/missing_direct_deps/internal_deps:transitive_dependency_user'
103103

104-
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" ${test_target} "--strict_java_deps=off"
104+
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" ${test_target} "--extra_toolchains=//test/toolchains:high_level_direct_deps"
105105
}
106106

107107
test_scala_library_expect_no_recompilation_on_internal_change_of_transitive_dependency() {
108108
set +e
109109
no_recompilation_path="test/src/main/scala/scalarules/test/strict_deps/no_recompilation"
110-
build_command="bazel build //$no_recompilation_path/... --subcommands --strict_java_deps=error"
110+
build_command="bazel build //$no_recompilation_path/... --subcommands --extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_error"
111111

112112
echo "running initial build"
113113
$build_command
@@ -166,7 +166,7 @@ test_scala_library_expect_better_failure_message_on_missing_transitive_dependenc
166166

167167
expected_message="Unknown label of file $transitive_target which came from $direct_target"
168168

169-
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" $test_target "--strict_java_deps=error"
169+
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" $test_target "--extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_error"
170170
}
171171

172172
$runner test_scala_library_suite

test/shell/test_unused_dependency.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ test_succeeds_with_warning() {
3939
test_unused_dependency_checker_mode_warn() {
4040
# this is a hack to invalidate the cache, so that the target actually gets built and outputs warnings.
4141
bazel build \
42-
--strict_java_deps=warn \
42+
--extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_warn \
4343
//test:UnusedDependencyCheckerWarn
4444

4545
test_succeeds_with_warning \
46-
"bazel build --strict_java_deps=off //test:UnusedDependencyCheckerWarn" \
46+
"bazel build --extra_toolchains=//test/toolchains:high_level_direct_deps //test:UnusedDependencyCheckerWarn" \
4747
"warning: Target '//test:UnusedLib' is specified as a dependency to //test:UnusedDependencyCheckerWarn but isn't used, please remove it from the deps."
4848
}
4949

test/toolchains/BUILD.bazel

+45
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,48 @@ toolchain(
5959
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
6060
visibility = ["//visibility:public"],
6161
)
62+
63+
scala_toolchain(
64+
name = "high_level_transitive_deps_strict_deps_warn_impl",
65+
dependency_mode = "transitive",
66+
dependency_tracking_method = "high-level",
67+
strict_deps_mode = "warn",
68+
visibility = ["//visibility:public"],
69+
)
70+
71+
toolchain(
72+
name = "high_level_transitive_deps_strict_deps_warn",
73+
toolchain = "high_level_transitive_deps_strict_deps_warn_impl",
74+
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
75+
visibility = ["//visibility:public"],
76+
)
77+
78+
scala_toolchain(
79+
name = "high_level_transitive_deps_strict_deps_error_impl",
80+
dependency_mode = "transitive",
81+
dependency_tracking_method = "high-level",
82+
strict_deps_mode = "error",
83+
visibility = ["//visibility:public"],
84+
)
85+
86+
toolchain(
87+
name = "high_level_transitive_deps_strict_deps_error",
88+
toolchain = "high_level_transitive_deps_strict_deps_error_impl",
89+
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
90+
visibility = ["//visibility:public"],
91+
)
92+
93+
scala_toolchain(
94+
name = "high_level_direct_deps_impl",
95+
dependency_mode = "direct",
96+
dependency_tracking_method = "high-level",
97+
strict_deps_mode = "off",
98+
visibility = ["//visibility:public"],
99+
)
100+
101+
toolchain(
102+
name = "high_level_direct_deps",
103+
toolchain = "high_level_direct_deps_impl",
104+
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
105+
visibility = ["//visibility:public"],
106+
)

test_rules_scala.sh

+6-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ $runner bazel build test/...
1616
#$runner bazel build "test/... --all_incompatible_changes"
1717
$runner bazel test test/...
1818
$runner bazel test third_party/...
19-
# UnusedDependencyChecker doesn't work with strict_java_deps
20-
$runner bazel build "--strict_java_deps=ERROR -- test/... -test:UnusedDependencyChecker"
21-
$runner bazel build "--extra_toolchains=//scala:minimal_direct_source_deps -- test/... -test:UnusedDependencyChecker"
22-
#$runner bazel build "--strict_java_deps=ERROR --all_incompatible_changes -- test/... -test:UnusedDependencyChecker"
23-
$runner bazel test "--strict_java_deps=ERROR -- test/... -test:UnusedDependencyChecker"
24-
$runner bazel test "--extra_toolchains=//scala:minimal_direct_source_deps -- test/... -test:UnusedDependencyChecker"
25-
$runner bazel build "test_expect_failure/missing_direct_deps/internal_deps/... --strict_java_deps=warn"
19+
$runner bazel build "--extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_error -- test/..."
20+
$runner bazel build "--extra_toolchains=//scala:minimal_direct_source_deps -- test/..."
21+
#$runner bazel build "--extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_error --all_incompatible_changes -- test/..."
22+
$runner bazel test "--extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_error -- test/..."
23+
$runner bazel test "--extra_toolchains=//scala:minimal_direct_source_deps -- test/..."
24+
$runner bazel build "test_expect_failure/missing_direct_deps/internal_deps/... --strict_java_deps=warn --extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_warn"
2625
$runner bazel build //test_expect_failure/proto_source_root/... --strict_proto_deps=off
2726
$runner bazel test //test/... --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps"
2827
. "${test_dir}"/test_build_event_protocol.sh

0 commit comments

Comments
 (0)