Skip to content

Commit a6efeb6

Browse files
smarterbishabosha
authored andcommitted
Slight build refactoring
Replace getExternalDep and findLib by findArtifact, which is safer than getLib was (it doesn't use `contains` to find the name which might yield false positives).
1 parent 9953816 commit a6efeb6

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

project/Build.scala

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ object Build {
267267
/*
268268
scalacOptions ++= {
269269
val cp = (dependencyClasspath in `dotty-library` in Compile).value
270-
val scalaLib = findLib(cp, "scala-library")
270+
val scalaLib = findArtifactPath(cp, "scala-library")
271271
Seq("-Yscala2-unpickler", scalaLib)
272272
},
273273
*/
@@ -279,12 +279,7 @@ object Build {
279279
managedScalaInstance := false,
280280
scalaInstance := {
281281
val externalNonBootstrappedDeps = externalDependencyClasspath.in(`dotty-doc`, Compile).value
282-
def getExternalDep(name: String): File =
283-
externalNonBootstrappedDeps.find(_.get(artifact.key).exists(_.name == name))
284-
.getOrElse(throw new MessageOnlyException(s"Artifact for $name not found in $externalNonBootstrappedDeps"))
285-
.data
286-
287-
val scalaLibrary = getExternalDep("scala-library")
282+
val scalaLibrary = findArtifact(externalNonBootstrappedDeps, "scala-library")
288283

289284
// IMPORTANT: We need to use actual jars to form the ScalaInstance and not
290285
// just directories containing classfiles because sbt maintains a cache of
@@ -357,7 +352,7 @@ object Build {
357352
val dottyInterfaces = jars("dotty-interfaces")
358353
val otherDeps = (dependencyClasspath in Compile).value.map(_.data).mkString(File.pathSeparator)
359354
val externalDeps = externalCompilerClasspathTask.value
360-
dottyLib + File.pathSeparator + findLib(externalDeps, "scala-library-")
355+
dottyLib + File.pathSeparator + findArtifactPath(externalDeps, "scala-library")
361356
}
362357

363358
def dottyDocSettings(implicit mode: Mode) = Seq(
@@ -426,10 +421,15 @@ object Build {
426421
case Bootstrapped => `dotty-doc-bootstrapped`
427422
}
428423

429-
def findLib(classpath: Def.Classpath, name: String) = classpath
430-
.map(_.data.getAbsolutePath)
431-
.find(_.contains(name))
432-
.toList.mkString(File.pathSeparator)
424+
/** Find an artifact with the given `name` in `classpath` */
425+
def findArtifact(classpath: Def.Classpath, name: String): File = classpath
426+
.find(_.get(artifact.key).exists(_.name == name))
427+
.getOrElse(throw new MessageOnlyException(s"Artifact for $name not found in $classpath"))
428+
.data
429+
430+
/** Like `findArtifact` but returns the absolute path of the entry as a string */
431+
def findArtifactPath(classpath: Def.Classpath, name: String): String =
432+
findArtifact(classpath, name).getAbsolutePath
433433

434434
// Settings shared between dotty-compiler and dotty-compiler-bootstrapped
435435
lazy val commonDottyCompilerSettings = Seq(
@@ -517,11 +517,11 @@ object Build {
517517
"-Ddotty.tests.classes.dottyInterfaces=" + jars("dotty-interfaces"),
518518
"-Ddotty.tests.classes.dottyLibrary=" + jars("dotty-library"),
519519
"-Ddotty.tests.classes.dottyCompiler=" + jars("dotty-compiler"),
520-
"-Ddotty.tests.classes.compilerInterface=" + findLib(externalDeps, "compiler-interface"),
521-
"-Ddotty.tests.classes.scalaLibrary=" + findLib(externalDeps, "scala-library-"),
522-
"-Ddotty.tests.classes.scalaAsm=" + findLib(externalDeps, "scala-asm"),
523-
"-Ddotty.tests.classes.jlineTerminal=" + findLib(externalDeps, "jline-terminal"),
524-
"-Ddotty.tests.classes.jlineReader=" + findLib(externalDeps, "jline-reader")
520+
"-Ddotty.tests.classes.compilerInterface=" + findArtifactPath(externalDeps, "compiler-interface"),
521+
"-Ddotty.tests.classes.scalaLibrary=" + findArtifactPath(externalDeps, "scala-library"),
522+
"-Ddotty.tests.classes.scalaAsm=" + findArtifactPath(externalDeps, "scala-asm"),
523+
"-Ddotty.tests.classes.jlineTerminal=" + findArtifactPath(externalDeps, "jline-terminal"),
524+
"-Ddotty.tests.classes.jlineReader=" + findArtifactPath(externalDeps, "jline-reader")
525525
)
526526

527527
jarOpts ::: tuning ::: agentOptions ::: ci_build
@@ -562,7 +562,7 @@ object Build {
562562
val externalDeps = externalCompilerClasspathTask.value
563563
val jars = packageAll.value
564564

565-
val scalaLib = findLib(externalDeps, "scala-library")
565+
val scalaLib = findArtifactPath(externalDeps, "scala-library")
566566
val dottyLib = jars("dotty-library")
567567

568568
def run(args: List[String]): Unit = {
@@ -576,7 +576,7 @@ object Build {
576576
println("Couldn't find scala-library on classpath, please run using script in bin dir instead")
577577
} else if (args.contains("-with-compiler")) {
578578
val args1 = args.filter(_ != "-with-compiler")
579-
val asm = findLib(externalDeps, "scala-asm")
579+
val asm = findArtifactPath(externalDeps, "scala-asm")
580580
val dottyCompiler = jars("dotty-compiler")
581581
val dottyInterfaces = jars("dotty-interfaces")
582582
run(insertClasspathInArgs(args1, List(dottyCompiler, dottyInterfaces, asm).mkString(File.pathSeparator)))
@@ -626,7 +626,7 @@ object Build {
626626
val log = streams.value.log
627627
val externalDeps = externalCompilerClasspathTask.value
628628
val jars = packageAll.value
629-
val scalaLib = findLib(externalDeps, "scala-library-")
629+
val scalaLib = findArtifactPath(externalDeps, "scala-library")
630630
val dottyLib = jars("dotty-library")
631631
val dottyCompiler = jars("dotty-compiler")
632632
val args0: List[String] = spaceDelimited("<arg>").parsed.toList
@@ -652,7 +652,7 @@ object Build {
652652
log.error("-with-compiler should only be used with a bootstrapped compiler")
653653
}
654654
val dottyInterfaces = jars("dotty-interfaces")
655-
val asm = findLib(externalDeps, "scala-asm")
655+
val asm = findArtifactPath(externalDeps, "scala-asm")
656656
extraClasspath ++= Seq(dottyCompiler, dottyInterfaces, asm)
657657
}
658658

0 commit comments

Comments
 (0)