From 52d663234454864bfd8edc9805a225dd4455049d Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Wed, 23 Mar 2022 09:43:41 +0100 Subject: [PATCH 1/5] Fix incorrect module traversal for BSP classpath retrieval --- scalalib/src/JavaModule.scala | 4 ++-- scalalib/src/ScalaModule.scala | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scalalib/src/JavaModule.scala b/scalalib/src/JavaModule.scala index c32da6decca..b683fd25230 100644 --- a/scalalib/src/JavaModule.scala +++ b/scalalib/src/JavaModule.scala @@ -318,9 +318,9 @@ trait JavaModule j: JavaModule, pathsResolver: Task[EvaluatorPathsResolver] ): Task[Seq[PathRef]] = { - val cl = bspCompileClassesPath(pathsResolver) + val cl = j.bspCompileClassesPath(pathsResolver) T.task { - resources() ++ Seq(cl()) + j.resources() ++ Seq(cl()) } } diff --git a/scalalib/src/ScalaModule.scala b/scalalib/src/ScalaModule.scala index 296dbcb4fb6..7dff8eba1e4 100644 --- a/scalalib/src/ScalaModule.scala +++ b/scalalib/src/ScalaModule.scala @@ -191,7 +191,7 @@ trait ScalaModule extends JavaModule { outer => )() } - // Keep in sync with [[bspCompileClassesInfo]] + // Keep in sync with [[bspCompileClassesPath]] override def compile: T[CompilationResult] = T.persistent { val sv = scalaVersion() if (sv == "2.12.4") T.log.error( @@ -244,6 +244,7 @@ trait ScalaModule extends JavaModule { outer => val compileCp = Seq( "-classpath", compileClasspath() + .iterator .filter(_.path.ext != "pom") .map(_.path) .mkString(java.io.File.pathSeparator) From 71410ced7d3d28a192cf0908229e27855d925b5d Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 24 Mar 2022 11:29:16 +0100 Subject: [PATCH 2/5] Cleaned existing BSP test --- bsp/test/resources/bsp-install/build.sc | 49 ++++--------------------- bsp/test/src/BspInstallTests.scala | 7 ++-- 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/bsp/test/resources/bsp-install/build.sc b/bsp/test/resources/bsp-install/build.sc index 07ccbc6a5af..f40f1b4e381 100644 --- a/bsp/test/resources/bsp-install/build.sc +++ b/bsp/test/resources/bsp-install/build.sc @@ -1,49 +1,14 @@ +import mill._ import mill.api.PathRef -import mill.scalalib -import mill.define.Command -import mill.scalalib.GenIdeaModule._ +import mill.scalalib._ -trait HelloWorldModule extends scalalib.ScalaModule { - def scalaVersion = "2.12.4" - object test extends super.Tests { - def testFrameworks = Seq("utest.runner.Framework") - } +trait HelloBspModule extends ScalaModule { + def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) + object test extends super.Tests with TestModule.Utest - def generatedSources = T { + override def generatedSources = T { Seq(PathRef(T.ctx().dest / "classes")) } - - def ideaJavaModuleFacets(ideaConfigVersion: Int): Command[Seq[JavaFacet]] = T.command { - ideaConfigVersion match { - case 4 => - Seq( - JavaFacet("AspectJ", "AspectJ", - Element("configuration", childs = Seq( - Element("projectLibrary", childs = Seq( - Element("option", Map("name" -> "name", "value" -> "/tmp")) - )) - )) - ) - ) - } - } - - override def ideaConfigFiles(ideaConfigVersion: Int): Command[Seq[IdeaConfigFile]] = T.command { - ideaConfigVersion match { - case 4 => - Seq( - IdeaConfigFile( - name = "compiler.xml", - component = "AjcSettings", - config = Seq(Element("option", Map("name" -> "ajcPath", "value" -> "/tmp/aspectjtools.jar")))), - IdeaConfigFile( - name = "compiler.xml", - component = "CompilerConfiguration", - config = Seq(Element("option", Map("name" -> "DEFAULT_COMPILER", "value" -> "ajc"))) - ) - ) - } - } } -object HelloWorld extends HelloWorldModule +object HelloBsp extends HelloBspModule diff --git a/bsp/test/src/BspInstallTests.scala b/bsp/test/src/BspInstallTests.scala index b64a226df1a..a2c4f7e87b6 100644 --- a/bsp/test/src/BspInstallTests.scala +++ b/bsp/test/src/BspInstallTests.scala @@ -9,11 +9,10 @@ object BspInstallTests extends ScriptTestSuite(false) { override def scriptSourcePath: Path = os.pwd / "bsp" / "test" / "resources" / workspaceSlug def tests: Tests = Tests { - "BSP install" - { + test("BSP install") { val workspacePath = initWorkspace() - eval("mill.bsp.BSP/install") - - assert(exists(workspacePath / ".bsp" / s"${BSP.serverName}.json")) + eval("mill.bsp.BSP/install") ==> true + exists(workspacePath / ".bsp" / s"${BSP.serverName}.json") ==> true } } } From a35a132ed4bff38bfb6b4d86c0a76c46cf5810b7 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 24 Mar 2022 11:29:32 +0100 Subject: [PATCH 3/5] Removed deprecated API call --- main/test/src/util/ScriptTestSuite.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/test/src/util/ScriptTestSuite.scala b/main/test/src/util/ScriptTestSuite.scala index 7a9e2b670ab..37e8a0c8647 100644 --- a/main/test/src/util/ScriptTestSuite.scala +++ b/main/test/src/util/ScriptTestSuite.scala @@ -2,6 +2,7 @@ package mill.util import java.io.{ByteArrayInputStream, ByteArrayOutputStream, PrintStream} import mainargs.Flag +import mill.define.SelectMode import scala.util.Try import os.Path @@ -100,7 +101,7 @@ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite { } catch { case e: Throwable => false } } def meta(s: String): String = { - val (List(selector), args) = mill.define.ParseArgs.apply(Seq(s), multiSelect = false).right.get + val Seq((List(selector), _)) = mill.define.ParseArgs.apply(Seq(s), SelectMode.Single).getOrElse(???) val segments = selector._2.value.flatMap(_.pathSegments) os.read(wd / "out" / segments.init / s"${segments.last}.json") From 77fa0f9db8f6147f69354068449ce107edc20b41 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 24 Mar 2022 11:29:59 +0100 Subject: [PATCH 4/5] Added test case for BspModule.bspClasspath --- .../mill/scalalib/bsp/BspModuleTests.scala | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala diff --git a/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala b/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala new file mode 100644 index 00000000000..e571f5daec3 --- /dev/null +++ b/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala @@ -0,0 +1,91 @@ +package mill.scalalib.bsp + +import mill.eval.EvaluatorPaths +import mill.{Agg, T} +import mill.scalalib.{DepSyntax, ScalaModule, TestModule} +import mill.util.{TestEvaluator, TestUtil} +import os.{BasePathImpl, FilePath} +import utest.framework.TestPath +import utest.{TestSuite, Tests, test, _} + +object BspModuleTests extends TestSuite { + + val testScalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) + + trait BspBase extends TestUtil.BaseModule { + override def millSourcePath: os.Path = + TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.') + } + + object MultiBase extends BspBase { + object HelloBsp extends ScalaModule { + def scalaVersion = testScalaVersion + override def ivyDeps = Agg(ivy"org.slf4j:slf4j-api:1.7.34") + } + object HelloBsp2 extends ScalaModule { + def scalaVersion = testScalaVersion + override def moduleDeps = Seq(HelloBsp) + override def ivyDeps = Agg(ivy"ch.qos.logback:logback-classic:1.1.10") + } + } + + def workspaceTest[T](m: TestUtil.BaseModule)(t: TestEvaluator => T)(implicit tp: TestPath): T = { + val eval = new TestEvaluator(m) + os.remove.all(m.millSourcePath) + os.remove.all(eval.outPath) + os.makeDir.all(m.millSourcePath / os.up) + t(eval) + } + + override def tests: Tests = Tests { + test("bspClasspath") { + test("single module") { + workspaceTest(MultiBase) { eval => + val Right((result, evalCount)) = eval.apply( + MultiBase.HelloBsp.bspCompileClasspath(T.task(eval.evaluator.pathsResolver)) + ) + + assert( + result.size == 3, + result.map(_.path.last).toSet == Set( + "resources", + "slf4j-api-1.7.34.jar", + s"scala-library-${testScalaVersion}.jar" + ), + evalCount > 0 + ) + } + test("dependent module") { + workspaceTest(MultiBase) { eval => + val Right((result, evalCount)) = eval.apply( + MultiBase.HelloBsp2.bspCompileClasspath(T.task(eval.evaluator.pathsResolver)) + ) + + val relResults: Seq[FilePath] = result.map { p => + val name = p.path.last + if (name.endsWith(".jar")) os.rel / name + else p.path + }.sortBy(_.toString) + + val expected: Seq[FilePath] = Seq( + MultiBase.HelloBsp.millSourcePath / "resources", + MultiBase.HelloBsp2.millSourcePath / "resources", + EvaluatorPaths.resolveDestPaths(eval.outPath, MultiBase.HelloBsp.compile) + .dest / "classes", + os.rel / "slf4j-api-1.7.34.jar", + os.rel / "logback-core-1.1.10.jar", + os.rel / "logback-classic-1.1.10.jar", + os.rel / s"scala-library-${testScalaVersion}.jar" + ).sortBy(_.toString) + + assert( + result.size == 7, + relResults == expected, + evalCount > 0 + ) + } + } + } + } + } +} From d5620961facacbd09912d594df2b6903d481c4b8 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 24 Mar 2022 20:52:30 +0100 Subject: [PATCH 5/5] Renamed test case --- scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala b/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala index e571f5daec3..aa2e32beb5d 100644 --- a/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala +++ b/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala @@ -38,7 +38,7 @@ object BspModuleTests extends TestSuite { } override def tests: Tests = Tests { - test("bspClasspath") { + test("bspCompileClasspath") { test("single module") { workspaceTest(MultiBase) { eval => val Right((result, evalCount)) = eval.apply(