Skip to content

Commit 896b18f

Browse files
committed
Gate test-runner injection in ScopedBuildInfo behind a flag
Only inject the JVM test-runner dependency into the Test scope when generating BuildInfo for export --json. The runtime BuildInfo.scala generator (ScopedSources.buildInfo) must not inject it: scala-cli supplies the test-runner at runtime, so users' BuildInfo.Test.dependencies would otherwise contain a dep they never declared, breaking RunTestsDefault."BuildInfo fields should be reachable".
1 parent 16098ba commit 896b18f

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

modules/cli/src/main/scala/scala/cli/exportCmd/JsonProjectDescriptor.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ final case class JsonProjectDescriptor(
2020
val sourcePaths = sources.paths.map(_._1.toString)
2121
val inMemoryPaths = sources.inMemory.flatMap(_.originalPath.toSeq.map(_._2.toString))
2222

23-
ScopedBuildInfo.forScope(options, sourcePaths ++ inMemoryPaths, scope, logger)
23+
ScopedBuildInfo.forScope(
24+
options,
25+
sourcePaths ++ inMemoryPaths,
26+
scope,
27+
logger,
28+
injectTestRunner = true
29+
)
2430

2531
for {
2632
baseBuildInfo <- BuildInfo(optionsMain, workspace)

modules/options/src/main/scala/scala/build/info/ScopedBuildInfo.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ object ScopedBuildInfo {
6262
)
6363
.reduceLeft(_ + _)
6464

65-
/** Build a [[ScopedBuildInfo]] for [[scope]] and inject the JVM test-runner dependency that
66-
* scala-cli silently adds at test time, so consumers of `export --json` see the same classpath
67-
* scala-cli would use.
65+
/** Build a [[ScopedBuildInfo]] for [[scope]]. When [[injectTestRunner]] is true, also inject the
66+
* JVM test-runner dependency that scala-cli silently adds at test time, so consumers of
67+
* `export --json` see the same classpath scala-cli would use. The runtime `BuildInfo.scala`
68+
* generator must leave it false — the test-runner is supplied by scala-cli at runtime, not
69+
* declared by the user.
6870
*
6971
* Injection conditions match [[scala.build.Artifacts.apply]]: scope is Test, the scope is
7072
* non-empty (has sources), the platform is JVM, and the build has a Scala version (i.e. is not
@@ -74,10 +76,11 @@ object ScopedBuildInfo {
7476
options: BuildOptions,
7577
sourcePaths: Seq[String],
7678
scope: Scope,
77-
logger: Logger
79+
logger: Logger,
80+
injectTestRunner: Boolean = false
7881
): ScopedBuildInfo = {
7982
val base = apply(options, sourcePaths)
80-
if scope == Scope.Test && sourcePaths.nonEmpty then
83+
if injectTestRunner && scope == Scope.Test && sourcePaths.nonEmpty then
8184
withJvmTestRunner(base, options, logger)
8285
else base
8386
}

0 commit comments

Comments
 (0)