From 60da186e5cf334b7162893a618e0a6c26d771d45 Mon Sep 17 00:00:00 2001 From: Jiuyang Liu Date: Sun, 22 Oct 2023 02:48:29 +0800 Subject: [PATCH] add tests.sc to split tests from common.sc --- build.sc | 34 +++++++++++++--- common.sc | 75 ----------------------------------- tests.sc | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 80 deletions(-) create mode 100644 tests.sc diff --git a/build.sc b/build.sc index 26fb86bd616..74160d3ca82 100644 --- a/build.sc +++ b/build.sc @@ -1,11 +1,11 @@ import mill._ import mill.scalalib._ -import mill.scalalib.TestModule._ import mill.scalalib.publish._ import mill.scalalib.scalafmt._ -import coursier.maven.MavenRepository +import mill.define.Cross import mill.scalalib.api.ZincWorkerUtil.matchingVersions import $file.common +import $file.tests object v { val pluginScalaCrossVersions = Seq( @@ -65,7 +65,7 @@ trait Svsim object firrtlut extends Cross[FirrtlUnitTest](v.scalaCrossVersions) trait FirrtlUnitTest - extends common.FirrtlUnitTestModule + extends tests.FirrtlUnitTestModule with CrossModuleBase with ScalafmtModule { override def millSourcePath = firrtl(crossScalaVersion).millSourcePath @@ -185,7 +185,7 @@ trait Chisel object chiselut extends Cross[ChiselUnitTest](v.scalaCrossVersions) trait ChiselUnitTest - extends common.ChiselUnitTestModule + extends tests.ChiselUnitTestModule with CrossModuleBase with ScalafmtModule { override def millSourcePath = chisel(crossScalaVersion).millSourcePath @@ -256,7 +256,7 @@ trait CIRCTPanamaBinder object bindertest extends Cross[CIRCTPanamaBinderModuleTest](v.scalaCrossVersions) trait CIRCTPanamaBinderModuleTest - extends common.CIRCTPanamaBinderModuleTestModule + extends tests.CIRCTPanamaBinderModuleTestModule with CrossModuleBase with ScalafmtModule { override def millSourcePath = circtpanamabinder(crossScalaVersion).millSourcePath @@ -271,3 +271,27 @@ trait CIRCTPanamaBinderModuleTest Seq(PathRef(millSourcePath / "src" / "test")) } } + +object litutility extends Cross[LitUtility](v.scalaCrossVersions) + +trait LitUtility + extends tests.LitUtilityModule + with CrossModuleBase + with ScalafmtModule { + def millSourcePath = super.millSourcePath / "litutility" + def circtPanamaBinderModule = circtpanamabinder(crossScalaVersion) +} + +object lit extends Cross[Lit](v.scalaCrossVersions) + +trait Lit + extends tests.LitModule + with Cross.Module[String] { + def scalaVersion: T[String] = crossValue + def runClasspath: T[Seq[os.Path]] = T(litutility(crossValue).runClasspath().map(_.path)) + def pluginJars: T[Seq[os.Path]] = T(Seq(litutility(crossValue).circtPanamaBinderModule.pluginModule.jar().path)) + def javaLibraryPath: T[Seq[os.Path]] = T(litutility(crossValue).circtPanamaBinderModule.libraryPaths().map(_.path)) + def javaHome: T[os.Path] = T(os.Path(sys.props("java.home"))) + def chiselLitDir: T[os.Path] = T(millSourcePath) + def litConfigIn: T[PathRef] = T.source(millSourcePath / "tests" / "lit.site.cfg.py.in") +} diff --git a/common.sc b/common.sc index f571bdc09f9..0d0ee87032e 100644 --- a/common.sc +++ b/common.sc @@ -43,46 +43,6 @@ trait SvsimModule extends ScalaModule { } -trait SvsimUnitTestModule - extends TestModule - with ScalaModule - with TestModule.ScalaTest { - def svsimModule: SvsimModule - - def scalatestIvy: Dep - - def scalacheckIvy: Dep - - override def moduleDeps = Seq(svsimModule) - - override def defaultCommandName() = "test" - - override def ivyDeps = super.ivyDeps() ++ Agg( - scalatestIvy, - scalacheckIvy - ) -} - -trait FirrtlUnitTestModule - extends TestModule - with ScalaModule - with TestModule.ScalaTest { - def firrtlModule: FirrtlModule - - def scalatestIvy: Dep - - def scalacheckIvy: Dep - - override def moduleDeps = Seq(firrtlModule) - - override def defaultCommandName() = "test" - - override def ivyDeps = super.ivyDeps() ++ Agg( - scalatestIvy, - scalacheckIvy - ) -} - trait CoreModule extends ScalaModule with HasMacroAnnotations { @@ -158,24 +118,6 @@ trait HasChisel override def moduleDeps = super.moduleDeps ++ Some(chiselModule) } -trait ChiselUnitTestModule - extends TestModule - with ScalaModule - with HasChisel - with HasMacroAnnotations - with TestModule.ScalaTest { - def scalatestIvy: Dep - - def scalacheckIvy: Dep - - override def defaultCommandName() = "test" - - override def ivyDeps = super.ivyDeps() ++ Agg( - scalatestIvy, - scalacheckIvy - ) -} - trait HasJextractGeneratedSources extends JavaModule { def includePaths: T[Seq[PathRef]] @@ -280,20 +222,3 @@ trait HasCIRCTPanamaBinderModule ) } -trait CIRCTPanamaBinderModuleTestModule - extends TestModule - with ScalaModule - with HasCIRCTPanamaBinderModule - with HasMacroAnnotations - with TestModule.ScalaTest { - def scalatestIvy: Dep - - def scalacheckIvy: Dep - - override def defaultCommandName() = "test" - - override def ivyDeps = super.ivyDeps() ++ Agg( - scalatestIvy, - scalacheckIvy - ) -} diff --git a/tests.sc b/tests.sc new file mode 100644 index 00000000000..6742f3810c3 --- /dev/null +++ b/tests.sc @@ -0,0 +1,114 @@ +import mill._ +import mill.api.Result +import mill.scalalib._ +import mill.scalalib.api.CompilationResult +import mill.util.Jvm + +import java.util +import scala.jdk.StreamConverters.StreamHasToScala + +trait SvsimUnitTestModule + extends TestModule + with ScalaModule + with TestModule.ScalaTest { + def svsimModule: common.SvsimModule + + def scalatestIvy: Dep + + def scalacheckIvy: Dep + + override def moduleDeps = Seq(svsimModule) + + override def defaultCommandName() = "test" + + override def ivyDeps = super.ivyDeps() ++ Agg( + scalatestIvy, + scalacheckIvy + ) +} + +trait FirrtlUnitTestModule + extends TestModule + with ScalaModule + with TestModule.ScalaTest { + def firrtlModule: common.FirrtlModule + + def scalatestIvy: Dep + + def scalacheckIvy: Dep + + override def moduleDeps = Seq(firrtlModule) + + override def defaultCommandName() = "test" + + override def ivyDeps = super.ivyDeps() ++ Agg( + scalatestIvy, + scalacheckIvy + ) +} + +trait ChiselUnitTestModule + extends TestModule + with ScalaModule + with common.HasChisel + with common.HasMacroAnnotations + with TestModule.ScalaTest { + def scalatestIvy: Dep + + def scalacheckIvy: Dep + + override def defaultCommandName() = "test" + + override def ivyDeps = super.ivyDeps() ++ Agg( + scalatestIvy, + scalacheckIvy + ) +} + +trait CIRCTPanamaBinderModuleTestModule + extends TestModule + with ScalaModule + with common.HasCIRCTPanamaBinderModule + with common.HasMacroAnnotations + with TestModule.ScalaTest { + def scalatestIvy: Dep + + def scalacheckIvy: Dep + + override def defaultCommandName() = "test" + + override def ivyDeps = super.ivyDeps() ++ Agg( + scalatestIvy, + scalacheckIvy + ) +} + +trait LitUtilityModule + extends ScalaModule + with common.HasCIRCTPanamaBinderModule + with common.HasMacroAnnotations + +trait LitModule + extends Module { + def scalaVersion: T[String] + def runClasspath: T[Seq[os.Path]] + def pluginJars: T[Seq[os.Path]] + def javaLibraryPath: T[Seq[os.Path]] + def javaHome: T[os.Path] + def chiselLitDir: T[os.Path] + def litConfigIn: T[PathRef] + def litConfig: T[PathRef] = T { + os.write( + T.dest / "lit.site.cfg.py", + os.read(litConfigIn().path) + .replaceAll("@SCALA_VERSION@", scalaVersion()) + .replaceAll("@RUN_CLASSPATH@", runClasspath().mkString(",")) + .replaceAll("@SCALA_PLUGIN_JARS@", pluginJars().mkString(",")) + .replaceAll("@JAVA_HOME@", javaHome().toString) + .replaceAll("@JAVA_LIBRARY_PATH@", javaLibraryPath().mkString(",")) + .replaceAll("@CHISEL_LIT_DIR@", chiselLitDir().toString) + ) + PathRef(T.dest) + } + def run(args: String*) = T.command(os.proc("lit", litConfig().path).call(T.dest, stdout = os.ProcessOutput.Readlines(line => T.ctx().log.info("[lit] " + line)))) + }