Skip to content

Commit 7272b1c

Browse files
committed
Support running the test scope with --spark
1 parent fd9e4ad commit 7272b1c

File tree

3 files changed

+27
-34
lines changed

3 files changed

+27
-34
lines changed

modules/cli/src/main/scala/scala/cli/commands/package0/Package.scala

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -807,38 +807,34 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
807807
* the whole dependency graph.
808808
*/
809809
def providedFiles(
810-
build: Build.Successful,
810+
builds: Seq[Build.Successful],
811811
provided: Seq[dependency.AnyModule],
812812
logger: Logger
813813
): Either[BuildException, Seq[os.Path]] = either {
814814

815815
logger.debug(s"${provided.length} provided dependencies")
816-
val res = build.artifacts.resolution.getOrElse {
816+
val res = builds.map(_.artifacts.resolution.getOrElse {
817817
sys.error("Internal error: expected resolution to have been kept")
818-
}
819-
val modules = value {
818+
})
819+
val modules: Seq[coursier.Module] = value {
820820
provided
821-
.map(_.toCs(build.scalaParams))
821+
.map(_.toCs(builds.head.scalaParams)) // Scala params should be the same for all scopes
822822
.sequence
823823
.left.map(CompositeBuildException(_))
824824
}
825825
val modulesSet = modules.toSet
826826
val providedDeps = res
827-
.dependencyArtifacts
828-
.map(_._1)
827+
.flatMap(_.dependencyArtifacts.map(_._1))
829828
.filter(dep => modulesSet.contains(dep.module))
830-
val providedRes = res.subset(providedDeps)
831-
val fileMap = build.artifacts.detailedRuntimeArtifacts
832-
.map {
833-
case (_, _, artifact, path) =>
834-
artifact -> path
835-
}
829+
val providedRes = res.map(_.subset(providedDeps))
830+
val fileMap = builds.flatMap(_.artifacts.detailedRuntimeArtifacts).distinct
831+
.map { case (_, _, artifact, path) => artifact -> path }
836832
.toMap
837-
val providedFiles = coursier.Artifacts.artifacts(providedRes, Set.empty, None, None, true)
833+
val providedFiles = providedRes
834+
.flatMap(r => coursier.Artifacts.artifacts(r, Set.empty, None, None, true))
835+
.distinct
838836
.map(_._3)
839-
.map { a =>
840-
fileMap.getOrElse(a, sys.error(s"should not happen (missing: $a)"))
841-
}
837+
.map(a => fileMap.getOrElse(a, sys.error(s"should not happen (missing: $a)")))
842838
logger.debug {
843839
val it = Iterator(s"${providedFiles.size} provided JAR(s)") ++
844840
providedFiles.toVector.map(_.toString).sorted.iterator.map(f => s" $f")
@@ -876,7 +872,7 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
876872
val jars =
877873
if (provided.isEmpty) allJars
878874
else {
879-
val providedFilesSet = value(providedFiles(build, provided, logger)).toSet
875+
val providedFilesSet = value(providedFiles(Seq(build), provided, logger)).toSet
880876
allJars.filterNot(providedFilesSet.contains)
881877
}
882878

modules/cli/src/main/scala/scala/cli/commands/run/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
620620
case mode: RunMode.SparkSubmit =>
621621
value {
622622
RunSpark.run(
623-
builds.head, // TODO: handle multiple builds
623+
builds,
624624
mainClass,
625625
args,
626626
mode.submitArgs,

modules/cli/src/main/scala/scala/cli/commands/util/RunSpark.scala

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import scala.util.Properties
1414
object RunSpark {
1515

1616
def run(
17-
build: Build.Successful,
17+
builds: Seq[Build.Successful],
1818
mainClass: String,
1919
args: Seq[String],
2020
submitArgs: Seq[String],
@@ -27,10 +27,10 @@ object RunSpark {
2727
// FIXME Get Spark.sparkModules via provided settings?
2828
val providedModules = Spark.sparkModules
2929
val providedFiles =
30-
value(PackageCmd.providedFiles(build, providedModules, logger)).toSet
31-
val depCp = build.dependencyClassPath.filterNot(providedFiles)
32-
val javaHomeInfo = build.options.javaHome().value
33-
val javaOpts = build.options.javaOptions.javaOpts.toSeq.map(_.value.value)
30+
value(PackageCmd.providedFiles(builds, providedModules, logger)).toSet
31+
val depCp = builds.flatMap(_.dependencyClassPath).distinct.filterNot(providedFiles)
32+
val javaHomeInfo = builds.head.options.javaHome().value
33+
val javaOpts = builds.head.options.javaOptions.javaOpts.toSeq.map(_.value.value)
3434
val ext = if (Properties.isWin) ".cmd" else ""
3535
val submitCommand: String =
3636
EnvVar.Spark.sparkHome.valueOpt
@@ -44,28 +44,25 @@ object RunSpark {
4444
else Seq("--jars", depCp.mkString(","))
4545

4646
scratchDirOpt.foreach(os.makeDir.all(_))
47-
val library = Library.libraryJar(build)
47+
val libraries = builds.map(Library.libraryJar(_))
4848

4949
val finalCommand =
5050
Seq(submitCommand, "--class", mainClass) ++
5151
jarsArgs ++
5252
javaOpts.flatMap(opt => Seq("--driver-java-options", opt)) ++
5353
submitArgs ++
54-
Seq(library.toString) ++
54+
libraries.map(_.toString) ++
5555
args
5656
val envUpdates = javaHomeInfo.envUpdates(sys.env)
57-
if (showCommand)
58-
Left(Runner.envCommand(envUpdates) ++ finalCommand)
57+
if showCommand then Left(Runner.envCommand(envUpdates) ++ finalCommand)
5958
else {
6059
val proc =
61-
if (allowExecve)
60+
if allowExecve then
6261
Runner.maybeExec("spark-submit", finalCommand, logger, extraEnv = envUpdates)
63-
else
64-
Runner.run(finalCommand, logger, extraEnv = envUpdates)
62+
else Runner.run(finalCommand, logger, extraEnv = envUpdates)
6563
Right((
6664
proc,
67-
if (scratchDirOpt.isEmpty) Some(() => os.remove(library, checkExists = true))
68-
else None
65+
if scratchDirOpt.isEmpty then Some(() => libraries.foreach(l => os.remove(l, checkExists = true))) else None
6966
))
7067
}
7168
}
@@ -83,7 +80,7 @@ object RunSpark {
8380

8481
// FIXME Get Spark.sparkModules via provided settings?
8582
val providedModules = Spark.sparkModules
86-
val sparkClassPath = value(PackageCmd.providedFiles(build, providedModules, logger))
83+
val sparkClassPath = value(PackageCmd.providedFiles(Seq(build), providedModules, logger)) // TODO: handle multiple builds
8784

8885
scratchDirOpt.foreach(os.makeDir.all(_))
8986
val library = Library.libraryJar(build)

0 commit comments

Comments
 (0)