Skip to content

Commit 61be139

Browse files
committed
ScoverageCompiler refactoring to support SJS
1 parent 585ed58 commit 61be139

File tree

3 files changed

+62
-11
lines changed

3 files changed

+62
-11
lines changed

build.sbt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ lazy val plugin =
161161
.settings(
162162
Test / unmanagedSourceDirectories += (Test / sourceDirectory).value / "scala-2.12+"
163163
)
164-
.dependsOn(domain, reporter % "test->compile", serializer)
164+
.dependsOn(domain, reporter % "test->compile", serializer, buildInfo % Test)
165165

166166
lazy val reporter =
167167
project
@@ -182,6 +182,15 @@ lazy val reporter =
182182
)
183183
.dependsOn(domain, serializer)
184184

185+
lazy val buildInfo =
186+
project
187+
.settings(
188+
buildInfoKeys += BuildInfoKey("scalaJSVersion", scalaJSVersion),
189+
publishArtifact := false,
190+
publishLocal := {}
191+
)
192+
.enablePlugins(BuildInfoPlugin)
193+
185194
lazy val domain =
186195
project
187196
.settings(

plugin/src/test/scala/scoverage/ScoverageCompiler.scala

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import scala.tools.nsc.plugins.PluginComponent
1111
import scala.tools.nsc.transform.Transform
1212
import scala.tools.nsc.transform.TypingTransformers
1313

14+
import buildinfo.BuildInfo
1415
import scoverage.reporter.IOUtils
1516

1617
private[scoverage] object ScoverageCompiler {
@@ -24,9 +25,17 @@ private[scoverage] object ScoverageCompiler {
2425
def classPath: Seq[String] =
2526
getScalaJars.map(
2627
_.getAbsolutePath
27-
) :+ sbtCompileDir.getAbsolutePath :+ runtimeClasses.getAbsolutePath
28+
) :+ sbtCompileDir.getAbsolutePath :+ runtimeClasses("jvm").getAbsolutePath
2829

29-
def settings: Settings = {
30+
def jsClassPath: Seq[String] =
31+
getScalaJsJars.map(
32+
_.getAbsolutePath
33+
) :+ sbtCompileDir.getAbsolutePath :+ runtimeClasses("js").getAbsolutePath
34+
35+
def settings: Settings = settings(classPath)
36+
def jsSettings: Settings = settings(jsClassPath)
37+
38+
def settings(classPath: Seq[String]): Settings = {
3039
val s = new scala.tools.nsc.Settings
3140
s.Xprint.value = List("all", "_")
3241
s.deprecation.value = true
@@ -46,6 +55,11 @@ private[scoverage] object ScoverageCompiler {
4655
new ScoverageCompiler(settings, reporter)
4756
}
4857

58+
def defaultScalaJs: ScoverageCompiler = {
59+
val reporter = new scala.tools.nsc.reporters.ConsoleReporter(jsSettings)
60+
new ScoverageCompiler(jsSettings, reporter)
61+
}
62+
4963
def locationCompiler: LocationCompiler = {
5064
val reporter = new scala.tools.nsc.reporters.ConsoleReporter(settings)
5165
new LocationCompiler(settings, reporter)
@@ -56,6 +70,23 @@ private[scoverage] object ScoverageCompiler {
5670
scalaJars.map(findScalaJar)
5771
}
5872

73+
private def getScalaJsJars: List[File] = {
74+
List(
75+
findJar("org.scala-lang", "scala-compiler", ScalaVersion),
76+
findJar("org.scala-lang", "scala-reflect", ScalaVersion),
77+
findJar(
78+
"org.scala-js",
79+
s"scalajs-compiler_$ScalaVersion",
80+
BuildInfo.scalaJSVersion
81+
),
82+
findJar(
83+
"org.scala-js",
84+
s"scalajs-library_$ScalaVersion",
85+
BuildInfo.scalaJSVersion
86+
)
87+
)
88+
}
89+
5990
private def sbtCompileDir: File = {
6091
val dir = new File(
6192
s"./plugin/target/scala-$ScalaVersion/classes"
@@ -67,20 +98,28 @@ private[scoverage] object ScoverageCompiler {
6798
dir
6899
}
69100

70-
private def runtimeClasses: File = new File(
71-
s"./runtime/jvm/target/scala-$ScalaVersion/classes"
101+
private def runtimeClasses(platform: String): File = new File(
102+
s"./runtime/$platform/target/scala-$ScalaVersion/classes"
72103
)
73104

74105
private def findScalaJar(artifactId: String): File =
75-
findIvyJar("org.scala-lang", artifactId, ScalaVersion)
76-
.orElse(findCoursierJar(artifactId, ScalaVersion))
106+
findJar("org.scala-lang", artifactId, ScalaVersion)
107+
108+
private def findJar(
109+
groupId: String,
110+
artifactId: String,
111+
version: String
112+
): File =
113+
findIvyJar(groupId, artifactId, version)
114+
.orElse(findCoursierJar(groupId, artifactId, version))
77115
.getOrElse {
78116
throw new FileNotFoundException(
79-
s"Could not locate $artifactId/$ScalaVersion"
117+
s"Could not locate $groupId:$artifactId:$version"
80118
)
81119
}
82120

83121
private def findCoursierJar(
122+
groupId: String,
84123
artifactId: String,
85124
version: String
86125
): Option[File] = {
@@ -89,9 +128,10 @@ private[scoverage] object ScoverageCompiler {
89128
".cache/coursier", // Linux
90129
"Library/Caches/Coursier", // MacOSX
91130
"AppData/Local/Coursier/cache" // Windows
92-
).map(loc =>
93-
s"$userHome/$loc/v1/https/repo1.maven.org/maven2/org/scala-lang/$artifactId/$version/$artifactId-$version.jar"
94-
)
131+
).map { loc =>
132+
val gid = groupId.replace('.', '/')
133+
s"$userHome/$loc/v1/https/repo1.maven.org/maven2/$gid/$artifactId/$version/$artifactId-$version.jar"
134+
}
95135
jarPaths.map(new File(_)).find(_.exists())
96136
}
97137

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
66

77
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.33")
88

9+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
10+
911
libraryDependencies += "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.1.0"

0 commit comments

Comments
 (0)