diff options
Diffstat (limited to 'scalalib/src/mill/scalalib/MiscModule.scala')
-rw-r--r-- | scalalib/src/mill/scalalib/MiscModule.scala | 79 |
1 files changed, 51 insertions, 28 deletions
diff --git a/scalalib/src/mill/scalalib/MiscModule.scala b/scalalib/src/mill/scalalib/MiscModule.scala index 502ba461..e20fe7be 100644 --- a/scalalib/src/mill/scalalib/MiscModule.scala +++ b/scalalib/src/mill/scalalib/MiscModule.scala @@ -1,11 +1,53 @@ package mill package scalalib +import ammonite.ops.{Path, RelPath} import mill.define.Cross.Resolver import mill.define.{Cross, Task} import mill.eval.{PathRef, Result} import mill.util.Loose.Agg +object CrossModuleBase{ + def scalaVersionPaths(scalaVersion: String, f: String => Path) = { + for(segments <- scalaVersion.split('.').inits.filter(_.nonEmpty)) + yield PathRef(f(segments.mkString("."))) + } +} +trait CrossModuleBase extends mill.Module{ + def crossScalaVersion: String + override def basePath = super.basePath / ammonite.ops.up + implicit def crossSbtModuleResolver: Resolver[CrossModuleBase] = new Resolver[CrossModuleBase]{ + def resolve[V <: CrossModuleBase](c: Cross[V]): V = { + crossScalaVersion.split('.') + .inits + .takeWhile(_.length > 1) + .flatMap( prefix => + c.items.map(_._2).find(_.crossScalaVersion.split('.').startsWith(prefix)) + ) + .collectFirst{case x => x} + .getOrElse( + throw new Exception( + s"Unable to find compatible cross version between $crossScalaVersion and "+ + c.items.map(_._2.crossScalaVersion).mkString(",") + ) + ) + } + } +} +trait CrossScalaModule extends ScalaModule with CrossModuleBase{ outer => + override def sources = T.input{ + super.sources() ++ + CrossModuleBase.scalaVersionPaths(crossScalaVersion, s => basePath / s"src-$s" ) + + } + + trait Tests extends super.Tests { + override def sources = T.input{ + super.sources() ++ + CrossModuleBase.scalaVersionPaths(crossScalaVersion, s => basePath / s"src-$s" ) + } + } +} trait SbtModule extends ScalaModule { outer => override def sources = T.input{ @@ -27,45 +69,26 @@ trait SbtModule extends ScalaModule { outer => } } -trait CrossSbtModule extends SbtModule { outer => - override def basePath = super.basePath / ammonite.ops.up - implicit def crossSbtModuleResolver: Resolver[CrossSbtModule] = new Resolver[CrossSbtModule]{ - def resolve[V <: CrossSbtModule](c: Cross[V]): V = { - crossScalaVersion.split('.') - .inits - .takeWhile(_.length > 1) - .flatMap( prefix => - c.items.map(_._2).find(_.crossScalaVersion.split('.').startsWith(prefix)) - ) - .collectFirst{case x => x} - .getOrElse( - throw new Exception( - s"Unable to find compatible cross version between $crossScalaVersion and "+ - c.items.map(_._2.crossScalaVersion).mkString(",") - ) - ) - } - } +trait CrossSbtModule extends SbtModule with CrossModuleBase{ outer => - def crossScalaVersion: String def scalaVersion = crossScalaVersion override def sources = T.input{ super.sources() ++ - crossScalaVersion.split('.').inits.filter(_.nonEmpty).map(_.mkString(".")).map{ - s => PathRef{ basePath / 'src / 'main / s"scala-$s" } - } + CrossModuleBase.scalaVersionPaths( + crossScalaVersion, + s => basePath / 'src / 'main / s"scala-$s" + ) } - override def resources = T.input{ Agg(PathRef(basePath / 'src / 'main / 'resources)) } trait Tests extends super.Tests { override def basePath = outer.basePath override def sources = T.input{ super.sources() ++ - crossScalaVersion.split('.').inits.filter(_.nonEmpty).map(_.mkString(".")).map{ - s => PathRef{ basePath / 'src / 'test / s"scala-$s" } - } + CrossModuleBase.scalaVersionPaths( + crossScalaVersion, + s => basePath / 'src / 'main / s"scala-$s" + ) } - override def resources = T.input{ Agg(PathRef(basePath / 'src / 'test / 'resources)) } } } |