diff --git a/README.md b/README.md index c5fd31b96..cc2b0e4bc 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,8 @@ With these settings, we also will error on dependencies which are unneeded, and The dependency tracking method `ast` is experimental but so far proves to be better than the default for computing the direct dependencies for `plus-one` mode code. In the future we hope to make this the default for `plus-one` mode and remove the option altogether. +To try it out you can use the following toolchain: `//scala:minimal_direct_source_deps`. + ### [Experimental] Dependency mode There are three dependency modes. The reason for the multiple modes is that often `scalac` depends on jars which seem unnecessary at first glance. Hence, in order to reduce the need to please `scalac`, we provide the following options. diff --git a/scala/BUILD b/scala/BUILD index ebf35506a..55dc0b9d8 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -36,6 +36,22 @@ toolchain( visibility = ["//visibility:public"], ) +scala_toolchain( + name = "ast_plus_one_deps_strict_deps_unused_deps_error_impl", + dependency_mode = "plus-one", + dependency_tracking_method = "ast", + strict_deps_mode = "error", + unused_dependency_checker_mode = "error", + visibility = ["//visibility:public"], +) + +toolchain( + name = "minimal_direct_source_deps", + toolchain = "ast_plus_one_deps_strict_deps_unused_deps_error_impl", + toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type", + visibility = ["//visibility:public"], +) + scala_toolchain( name = "code_coverage_toolchain_impl", enable_code_coverage_aspect = "on", diff --git a/src/java/io/bazel/rulesscala/specs2/BUILD b/src/java/io/bazel/rulesscala/specs2/BUILD index d68cf4a57..211d106f9 100644 --- a/src/java/io/bazel/rulesscala/specs2/BUILD +++ b/src/java/io/bazel/rulesscala/specs2/BUILD @@ -7,6 +7,9 @@ scala_library( "Specs2RunnerBuilder.scala", "package.scala", ], + unused_dependency_checker_ignored_targets = [ + "//external:io_bazel_rules_scala/dependency/scala/scala_xml", + ], visibility = ["//visibility:public"], deps = [ "//external:io_bazel_rules_scala/dependency/junit/junit", diff --git a/src/scala/scripts/BUILD b/src/scala/scripts/BUILD index 89753b1e6..0c7088d1d 100644 --- a/src/scala/scripts/BUILD +++ b/src/scala/scripts/BUILD @@ -31,6 +31,9 @@ scala_library( scala_library( name = "scalapb_generator_lib", srcs = ["ScalaPBGenerator.scala"], + unused_dependency_checker_ignored_targets = [ + "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", + ], visibility = ["//visibility:public"], runtime_deps = [ "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", diff --git a/test/shell/test_deps.sh b/test/shell/test_deps.sh index 746c40cb2..cd298c0da 100755 --- a/test/shell/test_deps.sh +++ b/test/shell/test_deps.sh @@ -50,7 +50,7 @@ test_plus_one_ast_analyzer_strict_deps() { expected_message_error="error: Target '$dependenecy_target' is used but isn't explicitly declared, please add it to the deps" test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message_error}" ${test_target} "--extra_toolchains=//test/toolchains:ast_plus_one_deps_strict_deps_error" "eq" - test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message_error}" ${test_target} "--extra_toolchains=//test/toolchains:ast_plus_one_deps_strict_deps_unused_deps_error" "eq" + test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message_error}" ${test_target} "--extra_toolchains=//scala:minimal_direct_source_deps" "eq" test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message_warn}" ${test_target} "--extra_toolchains=//test/toolchains:ast_plus_one_deps_strict_deps_warn" "ne" } diff --git a/test/shell/test_unused_dependency.sh b/test/shell/test_unused_dependency.sh index 4659004ab..23c75bbdb 100755 --- a/test/shell/test_unused_dependency.sh +++ b/test/shell/test_unused_dependency.sh @@ -56,7 +56,7 @@ test_plus_one_ast_analyzer_unused_deps_error() { } test_plus_one_ast_analyzer_unused_deps_strict_deps_error() { - action_should_fail build --extra_toolchains="//test/toolchains:ast_plus_one_deps_strict_deps_unused_deps_error" //test_expect_failure/plus_one_deps/with_unused_deps:a + action_should_fail build --extra_toolchains="//scala:minimal_direct_source_deps" //test_expect_failure/plus_one_deps/with_unused_deps:a } test_plus_one_ast_analyzer_unused_deps_warn() { diff --git a/test/src/main/scala/scalarules/test/srcjars_with_java/BUILD b/test/src/main/scala/scalarules/test/srcjars_with_java/BUILD index e1a38f695..db2705348 100644 --- a/test/src/main/scala/scalarules/test/srcjars_with_java/BUILD +++ b/test/src/main/scala/scalarules/test/srcjars_with_java/BUILD @@ -10,6 +10,7 @@ scala_library( scala_library( name = "mixed_language_dependent", srcs = ["MixedLanguageDependent.scala"], + unused_dependency_checker_ignored_targets = [":mixed_language_source_jar"], deps = [":mixed_language_source_jar"], ) @@ -23,5 +24,6 @@ scala_library( scala_library( name = "java_dependent", srcs = ["JavaDependent.scala"], + unused_dependency_checker_ignored_targets = [":java_source_jar"], deps = [":java_source_jar"], ) diff --git a/test/toolchains/BUILD.bazel b/test/toolchains/BUILD.bazel index 64a60a4ca..06ce27623 100644 --- a/test/toolchains/BUILD.bazel +++ b/test/toolchains/BUILD.bazel @@ -59,19 +59,3 @@ toolchain( toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type", visibility = ["//visibility:public"], ) - -scala_toolchain( - name = "ast_plus_one_deps_strict_deps_unused_deps_error_impl", - dependency_mode = "plus-one", - dependency_tracking_method = "ast", - strict_deps_mode = "error", - unused_dependency_checker_mode = "error", - visibility = ["//visibility:public"], -) - -toolchain( - name = "ast_plus_one_deps_strict_deps_unused_deps_error", - toolchain = "ast_plus_one_deps_strict_deps_unused_deps_error_impl", - toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type", - visibility = ["//visibility:public"], -) diff --git a/test_rules_scala.sh b/test_rules_scala.sh index c57f62661..ee805baeb 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -18,8 +18,10 @@ $runner bazel test test/... $runner bazel test third_party/... # UnusedDependencyChecker doesn't work with strict_java_deps $runner bazel build "--strict_java_deps=ERROR -- test/... -test:UnusedDependencyChecker" +$runner bazel build "--extra_toolchains=//scala:minimal_direct_source_deps -- test/... -test:UnusedDependencyChecker" #$runner bazel build "--strict_java_deps=ERROR --all_incompatible_changes -- test/... -test:UnusedDependencyChecker" $runner bazel test "--strict_java_deps=ERROR -- test/... -test:UnusedDependencyChecker" +$runner bazel test "--extra_toolchains=//scala:minimal_direct_source_deps -- test/... -test:UnusedDependencyChecker" $runner bazel build "test_expect_failure/missing_direct_deps/internal_deps/... --strict_java_deps=warn" $runner bazel build //test_expect_failure/proto_source_root/... --strict_proto_deps=off $runner bazel test //test/... --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps"