Skip to content

Latest commit

 

History

History
155 lines (118 loc) · 15.9 KB

scala_with_scalafmt.md

File metadata and controls

155 lines (118 loc) · 15.9 KB

This extension contains copies of the scala_binary, scala_library, and scala_test rules from rules/scala.bzl that provide formatting capabilities via Scalafmt. They're identical to the afformentioned rules, but have two additional attributes:

  • config
  • format

Additionally, for every target created from one of the rules in this extension (e.g. //foo/bar:bizz), you'll find two additional targets:

  • //foo/bar:bizz.format
  • //foo/bar:bizz.format-test

The former runs Scalafmt on the sources of the target, while the latter tests that those sources are formatted.

scala_binary

load("@rules_scala_annex//rules:scala_with_scalafmt.bzl", "scala_binary")

scala_binary(name, deps, srcs, data, resources, deps_unused_whitelist, deps_used_whitelist, format,
             javacopts, jvm_flags, main_class, plugins, resource_jars, resource_strip_prefix,
             runtime_deps, scala_toolchain_name, scalacopts, scalafmt_toolchain_name)

Compiles and links a Scala JVM executable.

Produces the following implicit outputs:

  • <name>_deploy.jar: a single jar that contains all the necessary information to run the program
  • <name>.jar: a jar file that contains the class files produced from the sources
  • <name>-bin: the script that's used to run the program in conjunction with the generated runfiles

To run the program: bazel run <target>

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
deps The JVM library dependencies. List of labels optional []
srcs The source Scala and Java files (and -sources.jar .srcjar -src.jar files of those). List of labels optional []
data The additional runtime files needed by this library. List of labels optional []
resources The files to include as classpath resources. List of labels optional []
deps_unused_whitelist The JVM library dependencies to always consider unused for scala_deps_direct checks. List of labels optional []
deps_used_whitelist The JVM library dependencies to always consider used for scala_deps_used checks. List of labels optional []
format Whether to format the target. If this is False, the formatter and format tester will do nothing. Boolean optional True
javacopts The Javac options. List of strings optional []
jvm_flags The JVM runtime flags. List of strings optional []
main_class The main class. If not provided, it will be inferred by its type signature. String optional ""
plugins The Scalac plugins. List of labels optional []
resource_jars The JARs to merge into the output JAR. List of labels optional []
resource_strip_prefix The path prefix to strip from classpath resources. String optional ""
runtime_deps The JVM runtime-only library dependencies. List of labels optional []
scala_toolchain_name The name of the Scala toolchain to use for this target (as provided to register_*_toolchain) String optional ""
scalacopts The Scalac options. List of strings optional []
scalafmt_toolchain_name The name of the Scalafmt configuration toolchain. String optional ""

scala_library

load("@rules_scala_annex//rules:scala_with_scalafmt.bzl", "scala_library")

scala_library(name, deps, srcs, data, resources, deps_unused_whitelist, deps_used_whitelist,
              exports, format, javacopts, macro, neverlink, plugins, resource_jars,
              resource_strip_prefix, runtime_deps, scala_toolchain_name, scalacopts,
              scalafmt_toolchain_name)

Compiles a Scala JVM library.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
deps The JVM library dependencies. List of labels optional []
srcs The source Scala and Java files (and -sources.jar .srcjar -src.jar files of those). List of labels optional []
data The additional runtime files needed by this library. List of labels optional []
resources The files to include as classpath resources. List of labels optional []
deps_unused_whitelist The JVM library dependencies to always consider unused for scala_deps_direct checks. List of labels optional []
deps_used_whitelist The JVM library dependencies to always consider used for scala_deps_used checks. List of labels optional []
exports The JVM libraries to add as dependencies to any libraries dependent on this one. List of labels optional []
format Whether to format the target. If this is False, the formatter and format tester will do nothing. Boolean optional True
javacopts The Javac options. List of strings optional []
macro Whether this library provides macros. Boolean optional False
neverlink Whether this library should be excluded at runtime. Boolean optional False
plugins The Scalac plugins. List of labels optional []
resource_jars The JARs to merge into the output JAR. List of labels optional []
resource_strip_prefix The path prefix to strip from classpath resources. String optional ""
runtime_deps The JVM runtime-only library dependencies. List of labels optional []
scala_toolchain_name The name of the Scala toolchain to use for this target (as provided to register_*_toolchain) String optional ""
scalacopts The Scalac options. List of strings optional []
scalafmt_toolchain_name The name of the Scalafmt configuration toolchain. String optional ""

scala_test

load("@rules_scala_annex//rules:scala_with_scalafmt.bzl", "scala_test")

scala_test(name, deps, srcs, data, resources, deps_unused_whitelist, deps_used_whitelist, format,
           frameworks, isolation, javacopts, jvm_flags, plugins, resource_jars, resource_strip_prefix,
           runner, runtime_deps, scala_toolchain_name, scalacopts, scalafmt_toolchain_name,
           shared_deps, subprocess_runner)

Compiles and links a collection of Scala tests.

To buid and run all tests: bazel test <target>

To build and run a specific test: bazel test <target> --test_filter=<filter_expression>
(Note: the syntax of the <filter_expression> varies by test framework, and not all test frameworks support the test_filter option at this time.)

More Info

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
deps The JVM library dependencies. List of labels optional []
srcs The source Scala and Java files (and -sources.jar .srcjar -src.jar files of those). List of labels optional []
data The additional runtime files needed by this library. List of labels optional []
resources The files to include as classpath resources. List of labels optional []
deps_unused_whitelist The JVM library dependencies to always consider unused for scala_deps_direct checks. List of labels optional []
deps_used_whitelist The JVM library dependencies to always consider used for scala_deps_used checks. List of labels optional []
format Whether to format the target. If this is False, the formatter and format tester will do nothing. Boolean optional True
frameworks The list of test frameworks to check for. These should conform to the sbt test interface (https://github.com/sbt/test-interface). List of strings optional ["org.scalatest.tools.Framework", "org.scalacheck.ScalaCheckFramework", "org.specs2.runner.Specs2Framework", "minitest.runner.Framework", "utest.runner.Framework", "com.novocode.junit.JUnitFramework"]
isolation The isolation level to apply String optional "none"
javacopts The Javac options. List of strings optional []
jvm_flags The JVM runtime flags. List of strings optional []
plugins The Scalac plugins. List of labels optional []
resource_jars The JARs to merge into the output JAR. List of labels optional []
resource_strip_prefix The path prefix to strip from classpath resources. String optional ""
runner - Label optional "@rules_scala_annex//src/main/scala/higherkindness/rules_scala/workers/zinc/test"
runtime_deps The JVM runtime-only library dependencies. List of labels optional []
scala_toolchain_name The name of the Scala toolchain to use for this target (as provided to register_*_toolchain) String optional ""
scalacopts Options to pass to scalac. List of strings optional []
scalafmt_toolchain_name The name of the Scalafmt configuration toolchain. String optional ""
shared_deps If isolation is "classloader", the list of deps to keep loaded between tests List of labels optional []
subprocess_runner - Label optional "@rules_scala_annex//src/main/scala/higherkindness/rules_scala/common/sbt-testing:subprocess"