Skip to content

Commit

Permalink
Formatting updates from buildifier and scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
James Judd committed Jul 3, 2024
1 parent ae02e2b commit 80fa4bb
Show file tree
Hide file tree
Showing 36 changed files with 86 additions and 103 deletions.
1 change: 1 addition & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ rewrite.rules = [
PreferCurlyFors,
SortImports
]
trailingCommas = always
5 changes: 1 addition & 4 deletions rules/private/phases/phase_bootstrap_compile.bzl
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
load(
"//rules/common:private/utils.bzl",
_strip_margin = "strip_margin",
)
load(
"//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
_strip_margin = "strip_margin",
)

#
Expand Down
8 changes: 4 additions & 4 deletions rules/private/phases/phase_coverage_jacoco.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ load(
"@rules_scala_annex//rules:providers.bzl",
_CodeCoverageConfiguration = "CodeCoverageConfiguration",
)
load(
"@rules_scala_annex//rules/private:coverage_replacements_provider.bzl",
_coverage_replacements_provider = "coverage_replacements_provider",
)
load(
"@rules_scala_annex//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
)
load(
"@rules_scala_annex//rules/private:coverage_replacements_provider.bzl",
_coverage_replacements_provider = "coverage_replacements_provider",
)

def phase_coverage_jacoco(ctx, g):
if not ctx.configuration.coverage_enabled:
Expand Down
5 changes: 1 addition & 4 deletions rules/private/phases/phase_javainfo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ load(
"find_java_runtime_toolchain",
"find_java_toolchain",
)
load(
"@rules_scala_annex//rules:providers.bzl",
_ScalaInfo = "ScalaInfo",
)
load(
"@rules_scala_annex//rules:providers.bzl",
_ScalaConfiguration = "ScalaConfiguration",
_ScalaInfo = "ScalaInfo",
)
load(
"//rules/common:private/utils.bzl",
Expand Down
3 changes: 0 additions & 3 deletions rules/scala/private/doc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ load(
load(
"//rules/common:private/utils.bzl",
_collect = "collect",
)
load(
"//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
)

Expand Down
5 changes: 1 addition & 4 deletions rules/scala_proto/private/core.bzl
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
load(
"//rules/common:private/utils.bzl",
_safe_name = "safe_name",
)
load(
"//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
_safe_name = "safe_name",
)

scala_proto_library_private_attributes = {}
Expand Down
9 changes: 4 additions & 5 deletions rules/scalafmt/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
load("//rules:scala.bzl", "scala_binary")
load("//rules:scalafmt.bzl", "scala_format_test")
load(
":ext.bzl",
_add_non_default_format_phase_singleton = "add_non_default_format_phase_singleton",
)

filegroup(
name = "runner",
Expand Down Expand Up @@ -40,11 +44,6 @@ filegroup(
visibility = ["//rules:__pkg__"],
)

load(
":ext.bzl",
_add_non_default_format_phase_singleton = "add_non_default_format_phase_singleton",
)

_add_non_default_format_phase_singleton(
name = "add_non_default_format_phase",
visibility = ["//visibility:public"],
Expand Down
8 changes: 4 additions & 4 deletions rules/scalafmt/ext.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ load(
"@rules_scala_annex//rules:providers.bzl",
_ScalaRulePhase = "ScalaRulePhase",
)
load(
"//rules/private:phases.bzl",
_phase_scalafmt_nondefault_outputs = "phase_scalafmt_nondefault_outputs",
)
load(
"//rules/scalafmt:private/test.bzl",
_scala_format_attributes = "scala_format_attributes",
_scala_non_default_format_attributes = "scala_non_default_format_attributes",
)
load(
"//rules/private:phases.bzl",
_phase_scalafmt_nondefault_outputs = "phase_scalafmt_nondefault_outputs",
)

ext_with_non_default_format = {
"attrs": _dicts.add(
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ scala2_global_scalacopts = shared_global_scalacopts + shared_scala2_global_scala
configure_bootstrap_scala(
name = "bootstrap_2_13_14",
compiler_classpath = compiler_classpath_2_13_14,
runtime_classpath = runtime_classpath_2_13_14,
global_scalacopts = scala2_global_scalacopts,
runtime_classpath = runtime_classpath_2_13_14,
version = "2.13.14",
visibility = ["//visibility:public"],
)
Expand Down Expand Up @@ -100,8 +100,8 @@ runtime_classpath_3_4_2 = [
configure_bootstrap_scala(
name = "bootstrap_3_4_2",
compiler_classpath = compiler_classpath_3_4_2,
runtime_classpath = runtime_classpath_3_4_2,
global_scalacopts = shared_global_scalacopts,
runtime_classpath = runtime_classpath_3_4_2,
use_ijar = False,
version = "3.4.2",
visibility = ["//visibility:public"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//rules:scalafmt.bzl", "scala_format_test")
load("//rules:scala.bzl", "scala_library")
load("//rules:scalafmt.bzl", "scala_format_test")

scala_library(
name = "args",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package common.error
final class AnnexWorkerError(
val code: Int,
val message: String = "",
val cause: Throwable = null
val cause: Throwable = null,
) extends Error(message, cause)

object AnnexWorkerError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//rules:scalafmt.bzl", "scala_format_test")
load("//rules:scala.bzl", "scala_library")
load("//rules:scalafmt.bzl", "scala_format_test")

scala_library(
name = "error",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//rules:scalafmt.bzl", "scala_format_test")
load("//rules:scala.bzl", "scala_library")
load("//rules:scalafmt.bzl", "scala_format_test")

_subprocess_srcs = ["SubprocessRunner.scala"]

Expand All @@ -23,11 +23,11 @@ scala_library(
scala_library(
name = "common",
srcs = _common_srcs,
scala = "//src/main/scala:zinc",
visibility = ["//visibility:public"],
deps_used_whitelist = [
"@annex//:org_scala_lang_scala_library",
],
scala = "//src/main/scala:zinc",
visibility = ["//visibility:public"],
deps = [
"@annex//:org_scala_lang_modules_scala_xml_2_13",
"@annex//:org_scala_sbt_test_interface",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ class JUnitXmlReporter(tasksAndEvents: ListBuffer[(String, ListBuffer[Event])])
case Status.Error if e.throwable.isDefined =>
val t = e.throwable.get
s"""<error message="${escape(t.getMessage)}" type="${escape(t.getClass.getName)}">${escape(
trace
trace,
)}</error>"""
case Status.Error =>
s"""<error message="No Exception or message provided"/>"""
case Status.Failure if e.throwable.isDefined =>
val t = e.throwable.get
s"""<failure message="${escape(t.getMessage)}" type="${escape(t.getClass.getName)}">${escape(
trace
trace,
)}</failure>"""
case Status.Failure =>
s"""<failure message="No Exception or message provided"/>"""
case Status.Canceled if e.throwable.isDefined =>
val t = e.throwable.get
s"""<skipped message="${escape(t.getMessage)}" type="${escape(t.getClass.getName)}">${escape(
trace
trace,
)}</skipped>"""
case Status.Canceled =>
s"""<skipped message="No Exception or message provided"/>"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TestFrameworkLoader(loader: ClassLoader, logger: Logger) {

object TestHelper {
def withRunner[A](framework: Framework, scopeAndTestName: String, classLoader: ClassLoader, arguments: Seq[String])(
f: Runner => A
f: Runner => A,
) = {
val options =
if (framework.name == "specs2") {
Expand Down Expand Up @@ -54,7 +54,7 @@ object TestHelper {
test.name,
test.fingerprint,
false,
Array(new TestWildcardSelector(scopeAndTestName.replace("::", " ")))
Array(new TestWildcardSelector(scopeAndTestName.replace("::", " "))),
)
}

Expand Down Expand Up @@ -88,7 +88,7 @@ class TestTaskExecutor(logger: Logger) {
case _ =>
}
},
Array(new PrefixedTestingLogger(logger, " "))
Array(new PrefixedTestingLogger(logger, " ")),
)
tasks.foreach(execute)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class TestRequest(
val scopeAndTestName: String,
val classpath: Seq[String],
val logger: Logger with Serializable,
val testArgs: Seq[String]
val testArgs: Seq[String],
) extends Serializable
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//rules:scalafmt.bzl", "scala_format_test")
load("//rules:scala.bzl", "scala_library")
load("//rules:scalafmt.bzl", "scala_format_test")

scala_library(
name = "worker",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait WorkerMain[S] {
Runtime.getRuntime().availableProcessors(),
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
exceptionHandler,
false
false,
)
implicit val ec = ExecutionContext.fromExecutor(fjp)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ object AnnexScalaInstance {
}

/**
* Convenience function to get a classloader from an Array[File] whose parent
* is the dualClassLoader, so it will handle xsbti correctly.
* Convenience function to get a classloader from an Array[File] whose parent is the dualClassLoader, so it will
* handle xsbti correctly.
*/
private def getClassLoader(jars: Array[File]): URLClassLoader = {
new URLClassLoader(
Expand All @@ -38,7 +38,7 @@ object AnnexScalaInstance {

private final def isScala3CompilerJar(jarName: String): Boolean = {
jarName.startsWith("scala3-compiler") || jarName.startsWith("scala3-interfaces") ||
jarName.startsWith("tasty-core_3") || jarName.startsWith("scala-asm")
jarName.startsWith("tasty-core_3") || jarName.startsWith("scala-asm")
}

private final def isScalaLibraryJar(jarName: String): Boolean = {
Expand All @@ -57,8 +57,8 @@ final class AnnexScalaInstance(override val allJars: Array[File]) extends ScalaI
override val compilerJars: Array[File] = allJars.filter { jar =>
val jarName = jar.getName
AnnexScalaInstance.isScala2CompilerJar(jarName) ||
AnnexScalaInstance.isScala3CompilerJar(jarName) ||
AnnexScalaInstance.isScalaLibraryJar(jarName)
AnnexScalaInstance.isScala3CompilerJar(jarName) ||
AnnexScalaInstance.isScalaLibraryJar(jarName)
}

// Jars for the Scala library classes
Expand All @@ -70,7 +70,8 @@ final class AnnexScalaInstance(override val allJars: Array[File]) extends ScalaI

// Version for this Scala instance
override val actualVersion: String = {
val stream = AnnexScalaInstance.getClassLoader(compilerJars)
val stream = AnnexScalaInstance
.getClassLoader(compilerJars)
.getResourceAsStream("compiler.properties")

try {
Expand All @@ -96,34 +97,28 @@ final class AnnexScalaInstance(override val allJars: Array[File]) extends ScalaI
* Load classes that start with xsbti or jline from the sbt class loader
* - xsbti is for the compiler bridge
* - jline for the sbt provided jline terminal
* Load all other classes from the other loader
* Always get resources from the non-sbt loader
* Load all other classes from the other loader Always get resources from the non-sbt loader
*
* This is necessary, so we can always make sure that the xsbti and jline
* classes needed for compilation and the repl come from the same class loader.
* This is necessary, so we can always make sure that the xsbti and jline classes needed for compilation and the repl
* come from the same class loader.
*
* If the same class is loaded by two separate class loaders you get a linkage
* error in the JVM.
* If the same class is loaded by two separate class loaders you get a linkage error in the JVM.
*
* If you set up a class loader that doesn't contain the xsbti and jline
* classes, then you get an error when you can't find those classes because
* they are needed by Zinc and our ZincRunner.
* If you set up a class loader that doesn't contain the xsbti and jline classes, then you get an error when you can't
* find those classes because they are needed by Zinc and our ZincRunner.
*
* If you set up one class loader for all the things, then you start leaking
* any class loaded during any compilation into any compilation happening in
* the JVM. Considering workers are long lived and handle multiple compilations,
* that could become a problem.
* If you set up one class loader for all the things, then you start leaking any class loaded during any compilation
* into any compilation happening in the JVM. Considering workers are long lived and handle multiple compilations, that
* could become a problem.
*
* Dotty, Bloop, and Zinc all do very similar things. This approach was heavily
* inspired by their approaches. For more details about their approaches see
* the following:
* Dotty, Bloop, and Zinc all do very similar things. This approach was heavily inspired by their approaches. For more
* details about their approaches see the following:
* https://github.com/scala/scala3/blob/7d26a96db6e63aba8db1362b09f4adf521bc8327/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala#L620
* https://github.com/scala/scala3/blob/cd8c5ed1dc5ee8528861e284490534064ba6d3e5/sbt-bridge/src/xsbt/CompilerClassLoader.java#L11
* https://github.com/scalacenter/bloop/blob/c505385edf0bbd420e19401ae1beabae8895df8f/backend/src/main/scala/bloop/ScalaInstanceTopLoader.scala#L30
* https://github.com/sbt/zinc/blob/4eacff2a9bf5c8750bfc5096955065ce67f4e68a/internal/zinc-classpath/src/main/scala/sbt/internal/inc/classpath/DualLoader.scala#L47
*/
class ScalaInstanceDualLoader(sbtClassLoader: ClassLoader, otherLoader: ClassLoader)
extends ClassLoader(otherLoader) {
class ScalaInstanceDualLoader(sbtClassLoader: ClassLoader, otherLoader: ClassLoader) extends ClassLoader(otherLoader) {
override final def loadClass(name: String, resolve: Boolean): Class[_] = {
if (name.startsWith("xsbti.") || name.startsWith("org.jline.")) {
val klass = sbtClassLoader.loadClass(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package higherkindness.rules_scala
package workers.common

import xsbti.{Logger, Problem}
import sbt.internal.inc.{ LoggedReporter => SbtLoggedReporter}
import sbt.internal.inc.{LoggedReporter => SbtLoggedReporter}

class LoggedReporter(logger: Logger, versionString: String) extends SbtLoggedReporter(0, logger) {
// Scala 3 has great error messages, let's leave those alone, but still add color to the Scala 2 messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object JacocoInstrumenter extends WorkerMain[Unit] {
case Array(in, out) => (Paths.get(in), Paths.get(out))
case _ =>
sys.error("expected input=output for argument: " + other)
}
},
)
.toList

Expand Down
Loading

0 comments on commit 80fa4bb

Please sign in to comment.