Skip to content

Commit c24e37c

Browse files
authored
Convert relative path to absolute for coverage options (#1080)
* Convert relative path to absolute for coverage options
1 parent a5cdf7a commit c24e37c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

modules/build/src/main/scala/scala/build/Project.scala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.nio.charset.StandardCharsets
1010
import java.nio.file.Path
1111
import java.util.Arrays
1212

13-
import scala.build.options.Scope
13+
import scala.build.options.{ScalacOpt, Scope, ShadowingSeq}
1414

1515
final case class Project(
1616
workspace: os.Path,
@@ -46,7 +46,7 @@ final case class Project(
4646
}
4747
val scalaConfigOpt = scalaCompiler.map { scalaCompiler0 =>
4848
bloopScalaConfig("org.scala-lang", "scala-compiler", scalaCompiler0.scalaVersion).copy(
49-
options = scalaCompiler0.scalacOptions.toList,
49+
options = updateScalacOptions(scalaCompiler0.scalacOptions).map(_.value),
5050
jars = scalaCompiler0.compilerClassPath.map(_.toNIO).toList
5151
)
5252
}
@@ -72,6 +72,21 @@ final case class Project(
7272
def bloopFile: BloopConfig.File =
7373
BloopConfig.File(BloopConfig.File.LatestVersion, bloopProject)
7474

75+
private def updateScalacOptions(scalacOptions: Seq[String]): List[ScalacOpt] =
76+
ShadowingSeq.from(scalacOptions.map(ScalacOpt(_))).values.map { l =>
77+
// only look at the head, the tail is only values passed to it
78+
l.headOption match {
79+
case Some(opt) if opt.value.startsWith("-coverage-out:") =>
80+
// actual -coverage-out: option
81+
val maybeRelativePath = opt.value.stripPrefix("-coverage-out:")
82+
val absolutePath = os.Path(maybeRelativePath, Os.pwd)
83+
ScalacOpt(s"-coverage-out:$absolutePath") +: l.tail
84+
case _ =>
85+
// not a -coverage-out: option
86+
l
87+
}
88+
}.flatten.toList
89+
7590
private def maybeUpdateInputs(logger: Logger): Boolean = {
7691
val dest = directory / ".bloop" / s"$projectName.inputs.txt"
7792
val onDiskOpt =

modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,27 @@ abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String])
391391
)
392392
}
393393
}
394+
395+
if (actualScalaVersion.startsWith("3"))
396+
test("generate scoverage.coverage file") {
397+
val fileName = "Hello.scala"
398+
val inputs = TestInputs(
399+
Seq(
400+
os.rel / fileName -> // scala version should updated to 3.3 after release
401+
s"""//> using scala "3.2.0-RC1-bin-20220604-13ce496-NIGHTLY"
402+
|//> using options "-coverage-out:."
403+
|
404+
|@main def main = ()
405+
|""".stripMargin
406+
)
407+
)
408+
inputs.fromRoot { root =>
409+
os.proc(TestUtil.cli, "compile", extraOptions, fileName)
410+
.call(cwd = root)
411+
.out.text().trim
412+
413+
val expectedCoverageFilePath = root / "scoverage.coverage"
414+
expect(os.exists(expectedCoverageFilePath))
415+
}
416+
}
394417
}

0 commit comments

Comments
 (0)