diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-27 20:36:27 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-27 20:37:57 -0800 |
commit | e754ec7d9eafdf13f9a34248295e19d309c7eba4 (patch) | |
tree | 9e05d00caf493b6aa9bbca5d5e91e37378966170 /scalalib | |
parent | 8986f9755a026691d1839bac806b0b75c2e3e74d (diff) | |
download | mill-e754ec7d9eafdf13f9a34248295e19d309c7eba4.tar.gz mill-e754ec7d9eafdf13f9a34248295e19d309c7eba4.tar.bz2 mill-e754ec7d9eafdf13f9a34248295e19d309c7eba4.zip |
First incomplete pass at writing docs
Diffstat (limited to 'scalalib')
-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)) } } } |