Skip to content

Commit

Permalink
add silent_annotations option to da_scala bazel functions (#7668)
Browse files Browse the repository at this point in the history
* add silent_annotations option to da scala bazel functions

* use silent_annotations for several scala targets

* use silencer_plugin instead when the lib isn't used

* use silent_annotations for several more scala targets

* use silencer_lib for strange indirect requirement for running tests

* no changelog

CHANGELOG_BEGIN
CHANGELOG_END

* silent_annotations support for scaladoc
  • Loading branch information
S11001001 authored Oct 13, 2020
1 parent 1a2afd5 commit bafde51
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 111 deletions.
39 changes: 28 additions & 11 deletions bazel_tools/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ default_compile_arguments = {
"unused_dependency_checker_mode": "error",
}

silencer_plugin = "@maven//:com_github_ghik_silencer_plugin_2_12_12"
silencer_lib = "@maven//:com_github_ghik_silencer_lib_2_12_12"

default_initial_heap_size = "128m"
default_max_heap_size = "1g"
default_scalac_stack_size = "2m"
Expand Down Expand Up @@ -173,11 +176,24 @@ def _set_jvm_flags(
})
return result

def _wrap_rule(rule, name = "", scalacopts = [], plugins = [], generated_srcs = [], **kwargs):
def _wrap_rule(
rule,
name = "",
scalacopts = [],
plugins = [],
generated_srcs = [], # hiding from the underlying rule
deps = [],
silent_annotations = False,
**kwargs):
if silent_annotations:
scalacopts = ["-P:silencer:checkUnused"] + scalacopts
plugins = [silencer_plugin] + plugins
deps = [silencer_lib] + deps
rule(
name = name,
scalacopts = common_scalacopts + plugin_scalacopts + scalacopts,
plugins = common_plugins + plugins,
deps = deps,
**kwargs
)

Expand Down Expand Up @@ -452,20 +468,21 @@ Arguments:
doctitle: title for Scalaadoc's index.html. Typically the name of the library
"""

def _create_scaladoc_jar(**kwargs):
def _create_scaladoc_jar(name, srcs, plugins = [], deps = [], scalacopts = [], generated_srcs = [], silent_annotations = False, **kwargs):
# Limit execution to Linux and MacOS
if is_windows == False:
plugins = []
if "plugins" in kwargs:
plugins = kwargs["plugins"]

if silent_annotations:
# as with _wrap_rule
scalacopts = ["-P:silencer:checkUnused"] + scalacopts
plugins = [silencer_plugin] + plugins
deps = [silencer_lib] + deps
scaladoc_jar(
name = kwargs["name"] + "_scaladoc",
deps = kwargs.get("deps", []),
name = name + "_scaladoc",
deps = deps,
plugins = plugins,
srcs = kwargs["srcs"],
scalacopts = kwargs.get("scalacopts", []),
generated_srcs = kwargs.get("generated_srcs", []),
srcs = srcs,
scalacopts = scalacopts,
generated_srcs = generated_srcs,
tags = ["scaladoc"],
)

Expand Down
5 changes: 1 addition & 4 deletions daml-lf/interpreter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repl")
da_scala_library(
name = "interpreter",
srcs = glob(["src/main/**/*.scala"]),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
],
scalacopts = lf_scalacopts,
silent_annotations = True,
tags = ["maven_coordinates=com.daml:daml-lf-interpreter:__VERSION__"],
visibility = [
"//compiler/repl-service:__subpackages__",
Expand All @@ -30,7 +28,6 @@ da_scala_library(
"//daml-lf/language",
"//daml-lf/transaction",
"//daml-lf/validation",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:io_spray_spray_json_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
Expand Down
7 changes: 2 additions & 5 deletions daml-lf/transaction/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ da_scala_test(
name = "transaction-test",
size = "medium",
srcs = glob(["src/test/**/*.scala"]),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
],
scalacopts = lf_scalacopts + ["-P:silencer:checkUnused"],
scalacopts = lf_scalacopts,
silent_annotations = True,
deps = [
":transaction",
":transaction_java_proto",
Expand All @@ -82,7 +80,6 @@ da_scala_test(
"//daml-lf/transaction-test-lib",
"//libs-scala/scalatest-utils",
"@maven//:com_chuusai_shapeless_2_12",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_scalacheck_scalacheck_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
Expand Down
14 changes: 2 additions & 12 deletions language-support/scala/bindings-akka/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ da_scala_library(
name = "bindings-akka",
srcs = glob(["src/main/**/*.scala"]),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
"@maven//:org_spire_math_kind_projector_2_12",
],
resources = glob(["src/main/resources/**/*"]),
scalacopts = [
"-P:silencer:checkUnused",
],
silent_annotations = True,
tags = ["maven_coordinates=com.daml:bindings-akka:__VERSION__"],
visibility = [
"//visibility:public",
Expand Down Expand Up @@ -52,7 +49,6 @@ da_scala_library(
"@maven//:ch_qos_logback_logback_classic",
"@maven//:ch_qos_logback_logback_core",
"@maven//:com_chuusai_shapeless_2_12",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_github_pureconfig_pureconfig_2_12",
"@maven//:com_google_api_grpc_proto_google_common_protos",
"@maven//:com_typesafe_akka_akka_actor_2_12",
Expand All @@ -74,12 +70,7 @@ da_scala_test_suite(
"src/test/**/*.scala",
],
),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
],
scalacopts = [
"-P:silencer:checkUnused",
],
silent_annotations = True,
visibility = [
"//visibility:public",
],
Expand All @@ -92,7 +83,6 @@ da_scala_test_suite(
"//language-support/scala/bindings-akka-testing",
"//ledger-api/rs-grpc-bridge",
"//ledger/ledger-api-client",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_google_api_grpc_proto_google_common_protos",
"@maven//:com_typesafe_akka_akka_actor_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
Expand Down
4 changes: 1 addition & 3 deletions language-support/scala/bindings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ da_scala_library(
name = "bindings",
srcs = glob(["src/main/**/*.scala"]),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
"@maven//:org_spire_math_kind_projector_2_12",
],
scalacopts = ["-P:silencer:checkUnused"],
silent_annotations = True,
tags = ["maven_coordinates=com.daml:bindings-scala:__VERSION__"],
visibility = [
"//visibility:public",
Expand All @@ -28,7 +27,6 @@ da_scala_library(
deps = [
"//daml-lf/data",
"//ledger-api/grpc-definitions:ledger-api-scalapb",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:io_grpc_grpc_core",
"@maven//:org_scalaz_scalaz_core_2_12",
],
Expand Down
5 changes: 3 additions & 2 deletions language-support/scala/codegen-sample-app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load(
"//bazel_tools:scala.bzl",
"da_scala_library",
"da_scala_test",
"silencer_plugin",
)
load(
"//rules_daml:daml.bzl",
Expand Down Expand Up @@ -47,7 +48,7 @@ da_scala_library(
name = "daml-lf-codegen-sample-app",
srcs = [":MyMain.srcjar"] + glob(["src/main/**/*.scala"]),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
silencer_plugin,
"@maven//:org_spire_math_kind_projector_2_12",
],
scalacopts = [
Expand All @@ -71,7 +72,7 @@ da_scala_library(
"//language-support/scala/bindings",
"//language-support/scala/bindings-akka",
# silencer warns if this is absent, but we don't use it here;
# buildozer errors if you add it
# buildozer errors if you add it, so silent_annotations can't be used
# "@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:org_scalaz_scalaz_core_2_12",
],
Expand Down
8 changes: 1 addition & 7 deletions language-support/scala/codegen-testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,12 @@ da_scala_test_suite(
],
exclude = testing_utils,
),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
],
scalacopts = [
"-P:silencer:checkUnused",
],
silent_annotations = True,
deps = [
":codegen-testing",
":codegen-testing-testing",
"//language-support/scala/bindings",
"@maven//:com_chuusai_shapeless_2_12",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:org_apache_commons_commons_text",
"@maven//:org_scalacheck_scalacheck_2_12",
"@maven//:org_scalatest_scalatest_2_12",
Expand Down
12 changes: 4 additions & 8 deletions ledger-service/db-backend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ load(
"da_scala_library",
"da_scala_test",
"lf_scalacopts",
"silencer_lib",
)

da_scala_library(
name = "db-backend",
srcs = glob(["src/main/scala/**/*.scala"]),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
],
scalacopts = [
"-P:silencer:checkUnused",
] + lf_scalacopts,
scalacopts = lf_scalacopts,
silent_annotations = True,
tags = ["maven_coordinates=com.daml:http-json-db-backend:__VERSION__"],
visibility = [
"//visibility:public",
Expand All @@ -27,7 +24,6 @@ da_scala_library(
],
deps = [
"@maven//:com_chuusai_shapeless_2_12",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_lihaoyi_sourcecode_2_12",
"@maven//:io_spray_spray_json_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
Expand All @@ -54,7 +50,7 @@ da_scala_test(
"//daml-lf/transaction-test-lib",
"@maven//:ch_qos_logback_logback_classic",
"@maven//:com_chuusai_shapeless_2_12",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
silencer_lib,
"@maven//:com_lihaoyi_sourcecode_2_12",
"@maven//:com_typesafe_akka_akka_slf4j_2_12",
"@maven//:com_typesafe_scala_logging_scala_logging_2_12",
Expand Down
5 changes: 2 additions & 3 deletions ledger-service/http-json/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ da_scala_test(
"//ledger/test-common/test-certificates",
],
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
"@maven//:org_spire_math_kind_projector_2_12",
],
resources = glob(["src/it/resources/**/*"]),
scalacopts = hj_scalacopts + ["-P:silencer:checkUnused"],
scalacopts = hj_scalacopts,
silent_annotations = True,
deps = [
":http-json",
"//bazel_tools/runfiles:scala_runfiles",
Expand All @@ -186,7 +186,6 @@ da_scala_test(
"//libs-scala/postgresql-testing",
"//libs-scala/scala-utils",
"@maven//:com_chuusai_shapeless_2_12",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_lihaoyi_sourcecode_2_12",
"@maven//:com_typesafe_akka_akka_http_core_2_12",
"@maven//:com_typesafe_scala_logging_scala_logging_2_12",
Expand Down
6 changes: 1 addition & 5 deletions ledger/ledger-api-client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ da_scala_library(
da_scala_test_suite(
name = "ledger-api-client-tests",
srcs = glob(["src/test/suite/**/*.scala"]),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
],
scalacopts = ["-P:silencer:checkUnused"],
silent_annotations = True,
deps = [
":ledger-api-client",
"//language-support/scala/bindings",
"//ledger-api/rs-grpc-bridge",
"//ledger-api/testing-utils",
"//ledger/caching",
"//libs-scala/concurrent",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_typesafe_akka_akka_actor_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
"@maven//:com_typesafe_akka_akka_stream_testkit_2_12",
Expand Down
4 changes: 1 addition & 3 deletions ledger/ledger-api-common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ da_scala_library(
srcs = glob(["src/main/scala/**/*.scala"]),
plugins = [
"@maven//:org_spire_math_kind_projector_2_12",
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
],
scalacopts = ["-P:silencer:checkUnused"],
silent_annotations = True,
tags = ["maven_coordinates=com.daml:ledger-api-common:__VERSION__"],
visibility = [
"//visibility:public",
Expand All @@ -34,7 +33,6 @@ da_scala_library(
"//ledger/metrics",
"//libs-scala/concurrent",
"//libs-scala/resources",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_typesafe_akka_akka_actor_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
"@maven//:io_dropwizard_metrics_metrics_core",
Expand Down
11 changes: 9 additions & 2 deletions ledger/participant-integration-api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@

load("@os_info//:os_info.bzl", "is_windows")
load("//rules_daml:daml.bzl", "daml_compile")
load("//bazel_tools:scala.bzl", "da_scala_binary", "da_scala_library", "da_scala_test_suite", "scaladoc_jar")
load(
"//bazel_tools:scala.bzl",
"da_scala_binary",
"da_scala_library",
"da_scala_test_suite",
"scaladoc_jar",
"silencer_plugin",
)
load("//bazel_tools:pom_file.bzl", "pom_file")

compile_deps = [
Expand Down Expand Up @@ -228,7 +235,7 @@ scaladoc_jar(
],
doctitle = "DAML participant integration API",
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
silencer_plugin,
],
root_content = "rootdoc.txt",
scalacopts = ["-P:silencer:checkUnused"],
Expand Down
11 changes: 2 additions & 9 deletions ledger/participant-state/kvutils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ load("@os_info//:os_info.bzl", "is_windows")
da_scala_library(
name = "kvutils",
srcs = glob(["src/main/scala/**/*.scala"]),
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
],
scalacopts = ["-P:silencer:checkUnused"],
silent_annotations = True,
tags = ["maven_coordinates=com.daml:participant-state-kvutils:__VERSION__"],
visibility = [
"//visibility:public",
Expand All @@ -50,7 +47,6 @@ da_scala_library(
"//libs-scala/contextualized-logging",
"//libs-scala/resources",
"//libs-scala/timer-utils",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_typesafe_akka_akka_actor_2_12",
Expand Down Expand Up @@ -113,10 +109,8 @@ da_scala_test_suite(
data = [
"//ledger/test-common:model-tests.dar",
],
plugins = [
"@maven//:com_github_ghik_silencer_plugin_2_12_12",
],
resources = glob(["src/test/resources/*"]),
silent_annotations = True,
deps = [
":daml_kvutils_java_proto",
":kvutils",
Expand All @@ -143,7 +137,6 @@ da_scala_test_suite(
"//ledger/participant-state",
"//ledger/participant-state/protobuf:ledger_configuration_java_proto",
"//libs-scala/contextualized-logging",
"@maven//:com_github_ghik_silencer_lib_2_12_12",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_typesafe_akka_akka_actor_2_12",
Expand Down
Loading

0 comments on commit bafde51

Please sign in to comment.