Skip to content

Commit

Permalink
Fix classpath regression in Bloop export #1918
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Jun 15, 2024
1 parent 56323c8 commit 6f9c5c0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 20 deletions.
29 changes: 18 additions & 11 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,25 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
// //////////////////////////////////////////////////////////////////////////

val classpath = T.task {
val depModules = (module.compileModuleDepsChecked ++ module.recursiveModuleDeps).distinct
// dep modules ++ ivy deps ++ unmanaged
depModules.map(classes) ++
module.resolvedIvyDeps().map(_.path) ++
module.unmanagedClasspath().map(_.path)
val transitiveCompileClasspath = T.traverse(module.transitiveModuleCompileModuleDeps)(m =>
T.task { m.localCompileClasspath().map(_.path) ++ Agg(classes(m)) }
)().flatten

module.resolvedIvyDeps().map(_.path) ++
transitiveCompileClasspath ++
module.localCompileClasspath().map(_.path)
}

val runtimeClasspath = T.task {
// dep modules ++ ivy deps ++ unmanaged
module.recursiveModuleDeps.map(classes) ++
module.transitiveModuleDeps.map(classes) ++
module.resolvedRunIvyDeps().map(_.path) ++
module.unmanagedClasspath().map(_.path)
}

val resources = T.task(module.resources().map(_.path.toNIO).toList)
val compileResources =
T.task(module.compileResources().map(_.path.toNIO).toList)
val runtimeResources =
T.task(compileResources() ++ module.resources().map(_.path.toNIO).toList)

val platform: Task[BloopConfig.Platform] = module match {
case m: ScalaJSModule =>
Expand Down Expand Up @@ -277,8 +281,11 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
),
mainClass = module.mainClass(),
runtimeConfig = None,
classpath = Some(runtimeClasspath().map(_.toNIO).toList),
resources = Some(module.resources().map(_.path.toNIO).toList)
classpath = module match {
case _: TestModule => None
case _ => Some(runtimeClasspath().map(_.toNIO).toList)
},
resources = Some(runtimeResources())
)
}
}
Expand Down Expand Up @@ -413,7 +420,7 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
classpath = classpath().map(_.toNIO).toList,
out = out(module).toNIO,
classesDir = classes(module).toNIO,
resources = Some(resources()),
resources = Some(compileResources()),
`scala` = scalaConfig(),
java = javaConfig(),
sbt = None,
Expand Down
59 changes: 50 additions & 9 deletions contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ object BloopTests extends TestSuite {

object scalaModule2 extends scalalib.ScalaModule {
def scalaVersion = "2.12.8"
def moduleDeps = Seq(scalaModule)
}
object scalaModule3 extends scalalib.ScalaModule {
def scalaVersion = "2.12.8"
def moduleDeps = Seq(scalaModule2)
}
object scalaModule4 extends scalalib.ScalaModule {
def scalaVersion = "2.12.8"
def compileModuleDeps = Seq(scalaModule3)
}

object scalajsModule extends scalajslib.ScalaJSModule with testBloop.Module {
Expand Down Expand Up @@ -85,6 +94,8 @@ object BloopTests extends TestSuite {
testEvaluator(testBloop.install())
val scalaModuleConfig = readBloopConf("scalaModule.json")
val scalaModule2Config = readBloopConf("scalaModule2.json")
val scalaModule3Config = readBloopConf("scalaModule3.json")
val scalaModule4Config = readBloopConf("scalaModule4.json")
val testModuleConfig = readBloopConf("scalaModule.test.json")
val scalajsModuleConfig = readBloopConf("scalajsModule.json")
// skipped on Windows
Expand All @@ -110,9 +121,11 @@ object BloopTests extends TestSuite {
val options = p.scala.get.options
val version = p.scala.get.version
val compileClasspath = p.classpath.map(_.toString)
val compileResources = p.resources.get.map(_.toString)
val platform = p.platform.get.asInstanceOf[Jvm]
val jvmOptions = platform.config.options
val runtimeClasspath = platform.classpath.get.map(_.toString)
val runtimeResources = platform.resources.get.map(_.toString)
val resolution = p.resolution.get.modules

assert(name == "scalaModule")
Expand All @@ -126,14 +139,11 @@ object BloopTests extends TestSuite {
)
)
assert(compileClasspath.exists(_.contains("reactive-streams-1.0.3.jar")))
assert(
compileClasspath.filterNot(_.contains("reactive-streams-1.0.3.jar")).forall(
runtimeClasspath.contains
)
)
assert(
runtimeClasspath.exists(_.contains("postgresql-42.3.3.jar"))
)
assert(!runtimeClasspath.exists(_.contains("reactive-streams-1.0.3.jar")))

assert(runtimeClasspath.exists(_.contains("postgresql-42.3.3.jar")))
assert(!compileClasspath.exists(_.contains("postgresql-42.3.3.jar")))

assert(platform.name == "jvm")
assert(platform.mainClass.get == "foo.bar.Main")
assert(jvmOptions.contains(s"-Duser.dir=$workdir"))
Expand All @@ -144,6 +154,12 @@ object BloopTests extends TestSuite {
assert(bloopConfigDep.organization == "ch.epfl.scala")
assert(artifacts.map(_.name).distinct == List("bloop-config_2.12"))
assert(artifacts.flatMap(_.classifier).contains("sources"))

assert(compileResources.exists(_.contains("scalaModule/compile-resources")))
assert(!compileResources.exists(_.contains("scalaModule/resources")))

assert(runtimeResources.exists(_.contains("scalaModule/compile-resources")))
assert(runtimeResources.exists(_.contains("scalaModule/resources")))
}
"scalaModuleTest" - {
val p = testModuleConfig.project
Expand All @@ -163,6 +179,7 @@ object BloopTests extends TestSuite {
p.classpath.contains
)
)
assert(p.platform.get.asInstanceOf[Jvm].classpath == None)
}
"configAccessTest" - {
val (accessedConfig, _) =
Expand All @@ -173,6 +190,30 @@ object BloopTests extends TestSuite {
val cp = scalaModule2Config.project.classpath.map(_.toString)
assert(cp.exists(_.contains("scala-library-2.12.8")))
}
"classpath" - {
val cp = scalaModule3Config.project.classpath.map(_.toString)
assert(!cp.exists(_.contains(".bloop/out/scalaModule3/classes")))
assert(cp.exists(_.contains(".bloop/out/scalaModule2/classes")))
assert(cp.exists(_.contains(".bloop/out/scalaModule/classes")))
}
"platform-classpath" - {
val cp = scalaModule3Config.project.platform.get.asInstanceOf[Jvm].classpath.map(_.toString)
assert(cp.exists(_.contains(".bloop/out/scalaModule3/classes")))
assert(cp.exists(_.contains(".bloop/out/scalaModule2/classes")))
assert(cp.exists(_.contains(".bloop/out/scalaModule/classes")))
}
"classpath-compile-module-deps" - {
val cp = scalaModule4Config.project.classpath.map(_.toString)
assert(cp.exists(_.contains(".bloop/out/scalaModule3/classes")))
assert(cp.exists(_.contains(".bloop/out/scalaModule2/classes")))
assert(cp.exists(_.contains(".bloop/out/scalaModule/classes")))
}
"platform-classpath-compile-module-deps" - {
val cp = scalaModule4Config.project.platform.get.asInstanceOf[Jvm].classpath.map(_.toString)
assert(!cp.exists(_.contains(".bloop/out/scalaModule3/classes")))
assert(!cp.exists(_.contains(".bloop/out/scalaModule2/classes")))
assert(!cp.exists(_.contains(".bloop/out/scalaModule/classes")))
}
"scalajsModule" - {
val p = scalajsModuleConfig.project
val name = p.name
Expand Down Expand Up @@ -222,7 +263,7 @@ object BloopTests extends TestSuite {
testEvaluator(testBloop.install())
val bloopDir = workdir / ".bloop"
val files = os.list(bloopDir)
val size = (if (isWin) 4 else 5)
val size = (if (isWin) 5 else 6)
assert(files.size == size)
os.remove.all(bloopDir)
testEvaluator(testBloop.install())
Expand Down

0 comments on commit 6f9c5c0

Please sign in to comment.