Skip to content

Commit

Permalink
Remove scalaz as a dependency (via coursier)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvican committed Jan 15, 2019
1 parent b764f0b commit 8957aec
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 47 deletions.
33 changes: 22 additions & 11 deletions backend/src/main/scala/bloop/DependencyResolution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ object DependencyResolution {
Repository,
Resolution
}
import coursier.interop.scalaz._
import scalaz.concurrent.Task

/**
Expand All @@ -46,7 +45,9 @@ object DependencyResolution {
version: String,
logger: Logger,
additionalRepositories: Seq[Repository] = Nil
): Array[AbsolutePath] = {
)(implicit ec: scala.concurrent.ExecutionContext): Array[AbsolutePath] = {
import coursier._
import coursier.util.{Gather, Task}
logger.debug(s"Resolving $organization:$module:$version")(DebugFilter.Compilation)
val org = coursier.Organization(organization)
val moduleName = coursier.ModuleName(module)
Expand All @@ -56,20 +57,30 @@ object DependencyResolution {
val baseRepositories = Seq(
Cache.ivy2Local,
MavenRepository("https://repo1.maven.org/maven2"),
MavenRepository("https://dl.bintray.com/scalacenter/releases"))
MavenRepository("https://dl.bintray.com/scalacenter/releases")
)
baseRepositories ++ additionalRepositories
}
val fetch = Fetch.from(repositories, Cache.fetch())
val resolution = start.process.run(fetch).unsafePerformSync
val errors = resolution.errors
if (errors.isEmpty) {
val localArtifacts: List[Either[FileError, File]] =
Task.gatherUnordered(resolution.artifacts().map(Cache.file(_).run)).unsafePerformSync
localArtifacts.collect { case Right(f) => AbsolutePath(f.toPath) }.toArray
val fetch = Fetch.from(repositories, Cache.fetch[Task]())
val resolution = start.process.run(fetch).unsafeRun()
val localArtifacts: Seq[(Boolean, Either[FileError, File])] = {
Gather[Task]
.gather(resolution.artifacts().map { artifact =>
Cache.file[Task](artifact).run.map(artifact.optional -> _)
})
.unsafeRun()
}

val fileErrors = localArtifacts.collect {
case (isOptional, Left(error)) if !isOptional || !error.notFound => error
}
if (fileErrors.isEmpty) {
localArtifacts.collect { case (_, Right(f)) => AbsolutePath(f.toPath) }.toArray
} else {
val moduleInfo = s"$organization:$module:$version"
val prettyFileErrors = fileErrors.map(_.describe).mkString(System.lineSeparator)
sys.error(
s"Resolution of module $moduleInfo failed with: ${errors.mkString("\n =>", "=> \n", "\n")}"
s"Resolution of module $moduleInfo failed with:${System.lineSeparator}${prettyFileErrors}"
)
}
}
Expand Down
12 changes: 8 additions & 4 deletions backend/src/main/scala/bloop/ScalaInstance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ final class ScalaInstance private (

object ScalaInstance {
import bloop.io.AbsolutePath
import scala.concurrent.ExecutionContext

private[ScalaInstance] final val ScalacCompilerName = "scala-compiler"

Expand All @@ -97,12 +98,13 @@ object ScalaInstance {
scalaVersion: String,
allJars: Seq[AbsolutePath],
logger: Logger
): ScalaInstance = {
)(implicit ec: ExecutionContext): ScalaInstance = {
val jarsKey = allJars.map(_.underlying).sortBy(_.toString).toList
if (allJars.nonEmpty) {
def newInstance = {
logger.debug(s"Cache miss for scala instance ${scalaOrg}:${scalaName}:${scalaVersion}.")(
DebugFilter.Compilation)
DebugFilter.Compilation
)
jarsKey.foreach(p => logger.debug(s" => $p")(DebugFilter.Compilation))
new ScalaInstance(scalaOrg, scalaName, scalaVersion, allJars.map(_.toFile).toArray)
}
Expand All @@ -123,7 +125,7 @@ object ScalaInstance {
scalaName: String,
scalaVersion: String,
logger: Logger
): ScalaInstance = {
)(implicit ec: ExecutionContext): ScalaInstance = {
def resolveInstance: ScalaInstance = {
val allPaths = DependencyResolution.resolve(scalaOrg, scalaName, scalaVersion, logger)
val allJars = allPaths.collect {
Expand Down Expand Up @@ -158,7 +160,9 @@ object ScalaInstance {
* happen to be so strict as to prevent getting the location from the protected
* domain.
*/
def scalaInstanceFromBloop(logger: Logger): Option[ScalaInstance] = {
def scalaInstanceFromBloop(
logger: Logger
)(implicit ec: ExecutionContext): Option[ScalaInstance] = {
lazy val tempDirectory = Files.createTempDirectory("bloop-scala-instance")
implicit val filter = DebugFilter.Compilation
def findLocationForClazz(clazz: Class[_], jarName: String): Option[Path] = {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/test/scala/bloop/ScalaInstanceCachingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters

import scala.concurrent.ExecutionContext.Implicits.global

object ScalaInstanceCachingSpec {
val sameVersionPairs = Array("2.10.6", "2.10.1", "2.11.11", "2.12.0", "2.12.4")
val unsharedVersionPairs =
Expand Down
1 change: 1 addition & 0 deletions backend/src/test/scala/bloop/ScalaInstanceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.junit.experimental.categories.Category
@Category(Array(classOf[FastTests]))
class ScalaInstanceSpec {
@Test def testInstanceFromBloop(): Unit = {
import scala.concurrent.ExecutionContext.Implicits.global
val instance0 = ScalaInstance.scalaInstanceFromBloop(new RecordingLogger())
Assert.assertTrue("Scala instance couldn't be created", instance0.isDefined)
val instance = instance0.get
Expand Down
26 changes: 14 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ val benchmarkBridge = project
releaseEarly := { () },
skip in publish := true,
bloopGenerate in Compile := None,
bloopGenerate in Test := None,
bloopGenerate in Test := None
)

/***************************************************************************************************/
Expand All @@ -42,7 +42,6 @@ val backend = project
Dependencies.scalazConcurrent,
Dependencies.coursier,
Dependencies.coursierCache,
Dependencies.coursierScalaz,
Dependencies.libraryManagement,
Dependencies.configDirectories,
Dependencies.sourcecode,
Expand Down Expand Up @@ -71,7 +70,7 @@ val jsonConfig210 = project
Dependencies.circeCore,
Dependencies.circeGeneric,
compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full),
Dependencies.scalacheck % Test,
Dependencies.scalacheck % Test
)
}
)
Expand All @@ -92,7 +91,7 @@ val jsonConfig211 = project
List(
Dependencies.circeParser,
Dependencies.circeDerivation,
Dependencies.scalacheck % Test,
Dependencies.scalacheck % Test
)
}
)
Expand All @@ -113,7 +112,7 @@ val jsonConfig212 = project
List(
Dependencies.circeParser,
Dependencies.circeDerivation,
Dependencies.scalacheck % Test,
Dependencies.scalacheck % Test
)
}
)
Expand All @@ -126,7 +125,6 @@ lazy val launcher: Project = project
libraryDependencies ++= List(
Dependencies.coursier,
Dependencies.coursierCache,
Dependencies.coursierScalaz,
Dependencies.nuprocess,
Dependencies.ipcsocket,
Dependencies.junit % Test,
Expand Down Expand Up @@ -171,7 +169,7 @@ val benchmarks = project
.enablePlugins(BuildInfoPlugin, JmhPlugin)
.settings(benchmarksSettings(frontend))
.settings(
skip in publish := true,
skip in publish := true
)

val integrations = file("integrations")
Expand Down Expand Up @@ -207,14 +205,16 @@ val gradleBloop211 = project
.settings(BuildDefaults.gradlePluginBuildSettings)
.settings(BuildInfoPlugin.buildInfoScopedSettings(Test))
.settings(scalaVersion := Keys.scalaVersion.in(jsonConfig211).value)
.settings(target := (file("integrations") / "gradle-bloop" / "target" / "gradle-bloop-2.11").getAbsoluteFile)
.settings(
target := (file("integrations") / "gradle-bloop" / "target" / "gradle-bloop-2.11").getAbsoluteFile
)
.settings(
sourceDirectories in Test := Nil,
publishLocal := publishLocal.dependsOn(publishLocal.in(jsonConfig211)).value,
bloopGenerate in Test := None,
test in Test := Def.task {
Keys.streams.value.log.error("Run 'gradleBloopTests/test' instead to test the gradle plugin.")
},
}
)

lazy val gradleBloop212 = project
Expand All @@ -225,7 +225,9 @@ lazy val gradleBloop212 = project
.settings(BuildDefaults.gradlePluginBuildSettings, testSettings)
.settings(BuildInfoPlugin.buildInfoScopedSettings(Test))
.settings(scalaVersion := Keys.scalaVersion.in(jsonConfig212).value)
.settings(target := (file("integrations") / "gradle-bloop" / "target" / "gradle-bloop-2.12").getAbsoluteFile)
.settings(
target := (file("integrations") / "gradle-bloop" / "target" / "gradle-bloop-2.12").getAbsoluteFile
)
.settings(
publishLocal := publishLocal.dependsOn(publishLocal.in(jsonConfig212)).value
)
Expand Down Expand Up @@ -290,7 +292,7 @@ lazy val nativeBridge = project
name := "bloop-native-bridge",
libraryDependencies += Dependencies.scalaNativeTools,
javaOptions in Test ++= jvmOptions,
fork in Test := true,
fork in Test := true
)

/* This project has the only purpose of forcing the resolution of some artifacts that fail spuriously to be fetched. */
Expand Down Expand Up @@ -362,7 +364,7 @@ addCommandAlias(
s"${jsBridge10.id}/$publishLocalCmd",
s"${launcher.id}/$publishLocalCmd",
"createLocalHomebrewFormula",
"createLocalScoopFormula",
"createLocalScoopFormula"
).mkString(";", ";", "")
)

Expand Down
1 change: 1 addition & 0 deletions frontend/src/main/scala/bloop/data/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ object Project {
}

def fromConfig(file: Config.File, origin: Origin, logger: Logger): Project = {
import bloop.engine.ExecutionContext.ioScheduler
val project = file.project
val scala = project.`scala`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ abstract class ToolchainCompanion[Toolchain] {
private final val BloopVersion = BuildInfo.version
private final val BloopOrg = BuildInfo.organization
private def resolveJars(artifactName: String, logger: Logger): List[Path] = {
import bloop.engine.ExecutionContext.ioScheduler
logger.debug(s"Resolving platform bridge: $BloopOrg:$artifactName:$BloopVersion")(
DebugFilter.Compilation)
DebugFilter.Compilation
)
val files = DependencyResolution.resolve(BloopOrg, artifactName, BloopVersion, logger)
files.iterator.map(_.underlying).filter(_.toString.endsWith(".jar")).toList
}
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/main/scala/bloop/testing/TestInternals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ object TestInternals {

lazy val filteredLoader = {
val filter = new IncludePackagesFilter(
Set("java.", "javax.", "sun.", "sbt.testing.", "org.scalatools.testing.", "org.xml.sax."))
Set("java.", "javax.", "sun.", "sbt.testing.", "org.scalatools.testing.", "org.xml.sax.")
)
new FilteredLoader(getClass.getClassLoader, filter)
}

Expand Down Expand Up @@ -80,6 +81,7 @@ object TestInternals {
testAgentFiles match {
case Some(paths) => paths
case None =>
import bloop.engine.ExecutionContext.ioScheduler
val paths = DependencyResolution.resolve(sbtOrg, testAgentId, testAgentVersion, logger)
testAgentFiles = Some(paths)
paths
Expand Down Expand Up @@ -213,8 +215,9 @@ object TestInternals {
}
}

def getFingerprints(frameworks: Seq[Framework])
: (Set[PrintInfo[SubclassFingerprint]], Set[PrintInfo[AnnotatedFingerprint]]) = {
def getFingerprints(
frameworks: Seq[Framework]
): (Set[PrintInfo[SubclassFingerprint]], Set[PrintInfo[AnnotatedFingerprint]]) = {
val subclasses = mutable.Set.empty[PrintInfo[SubclassFingerprint]]
val annotated = mutable.Set.empty[PrintInfo[AnnotatedFingerprint]]
for {
Expand Down Expand Up @@ -282,7 +285,8 @@ object TestInternals {
private def defined[T <: Fingerprint](
in: Set[PrintInfo[T]],
names: Set[String],
IsModule: Boolean): Set[PrintInfo[T]] = {
IsModule: Boolean
): Set[PrintInfo[T]] = {
in collect { case info @ (name, IsModule, _, _) if names(name) => info }
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/test/scala/bloop/ClasspathHashingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ClasspathHashingSpec {
@Test
def detectsMacrosInClasspath(): Unit = {
val logger = new RecordingLogger()
import bloop.engine.ExecutionContext.ioScheduler
val jars = DependencyResolution
.resolve("ch.epfl.scala", "zinc_2.12", "1.2.1+97-636ca091", logger)
.filter(_.syntax.endsWith(".jar"))
Expand Down
33 changes: 22 additions & 11 deletions frontend/src/test/scala/bloop/CompileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ class CompileSpec {
}
}

def scalaInstance2124(logger: Logger): ScalaInstance = ScalaInstance.resolve(
"org.scala-lang",
"scala-compiler",
"2.12.4",
logger
)
def scalaInstance2124(logger: Logger): ScalaInstance = {
ScalaInstance.resolve(
"org.scala-lang",
"scala-compiler",
"2.12.4",
logger
)(bloop.engine.ExecutionContext.ioScheduler)
}

@Test
def compileScalaAndJavaWithMissingDependency(): Unit = {
Expand Down Expand Up @@ -179,23 +181,29 @@ class CompileSpec {
def compileWithScala2124(): Unit = {
val logger = new RecordingLogger
val scalaInstance =
ScalaInstance.resolve("org.scala-lang", "scala-compiler", "2.12.4", logger)
ScalaInstance.resolve("org.scala-lang", "scala-compiler", "2.12.4", logger)(
bloop.engine.ExecutionContext.ioScheduler
)
simpleProject(scalaInstance)
}

@Test
def compileWithScala2123(): Unit = {
val logger = new RecordingLogger
val scalaInstance =
ScalaInstance.resolve("org.scala-lang", "scala-compiler", "2.12.3", logger)
ScalaInstance.resolve("org.scala-lang", "scala-compiler", "2.12.3", logger)(
bloop.engine.ExecutionContext.ioScheduler
)
simpleProject(scalaInstance)
}

@Test
def compileWithScala21111(): Unit = {
val logger = new RecordingLogger
val scalaInstance =
ScalaInstance.resolve("org.scala-lang", "scala-compiler", "2.11.11", logger)
ScalaInstance.resolve("org.scala-lang", "scala-compiler", "2.11.11", logger)(
bloop.engine.ExecutionContext.ioScheduler
)
simpleProject(scalaInstance)
}

Expand Down Expand Up @@ -577,7 +585,9 @@ class CompileSpec {
def compileWithDotty080RC1(): Unit = {
val logger = new RecordingLogger()
val scalaInstance =
ScalaInstance.resolve("ch.epfl.lamp", "dotty-compiler_0.8", "0.8.0-RC1", logger)
ScalaInstance.resolve("ch.epfl.lamp", "dotty-compiler_0.8", "0.8.0-RC1", logger)(
bloop.engine.ExecutionContext.ioScheduler
)
val structures = Map(RootProject -> Map("Dotty.scala" -> ArtificialSources.`Dotty.scala`))
checkAfterCleanCompilation(structures, Map.empty, scalaInstance = scalaInstance) { state =>
ensureCompilationInAllTheBuild(state)
Expand Down Expand Up @@ -629,7 +639,8 @@ class CompileSpec {
val targetProject = cleanCompiledState.build.getProjectFor(target).get
val newProjects = {
val newTargetProject = targetProject.copy(
scalacOptions = "-Ycache-plugin-class-loader:none" :: targetProject.scalacOptions)
scalacOptions = "-Ycache-plugin-class-loader:none" :: targetProject.scalacOptions
)
newTargetProject :: cleanCompiledState.build.projects.filter(_ != targetProject)
}
val changedState =
Expand Down
1 change: 1 addition & 0 deletions frontend/src/test/scala/bloop/util/TestProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ object TestProject {
.map(d => AbsolutePath(TestUtil.classesDir(baseDir.underlying, d)))
.toList

import bloop.engine.ExecutionContext.ioScheduler
val version = scalaVersion.getOrElse(Properties.versionNumberString)
val instance = scalaVersion
.map(v => ScalaInstance.apply("org.scala-lang", "scala-compiler", v, Nil, NoopLogger))
Expand Down
Loading

0 comments on commit 8957aec

Please sign in to comment.