blob: c6449d6ef31eb255cec5645f51090cc55736951f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
package mill
package scalalib
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 => os.Path) = {
for(segments <- scalaVersion.split('.').inits.filter(_.nonEmpty))
yield PathRef(f(segments.mkString(".")))
}
}
trait CrossModuleBase extends ScalaModule {
def crossScalaVersion: String
def scalaVersion = T{ crossScalaVersion }
override def millSourcePath = super.millSourcePath / 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.sources{
super.sources() ++
CrossModuleBase.scalaVersionPaths(crossScalaVersion, s => millSourcePath / s"src-$s" )
}
trait Tests extends super.Tests {
override def sources = T.sources{
super.sources() ++
CrossModuleBase.scalaVersionPaths(crossScalaVersion, s => millSourcePath / s"src-$s" )
}
}
}
trait MavenTests extends TestModule{
override def sources = T.sources(
millSourcePath / 'src / 'test / 'scala,
millSourcePath / 'src / 'test / 'java
)
override def resources = T.sources{ millSourcePath / 'src / 'test / 'resources }
}
trait MavenModule extends JavaModule{outer =>
override def sources = T.sources(
millSourcePath / 'src / 'main / 'scala,
millSourcePath / 'src / 'main / 'java
)
override def resources = T.sources{ millSourcePath / 'src / 'main / 'resources }
trait Tests extends super.Tests with MavenTests {
override def millSourcePath = outer.millSourcePath
override def intellijModulePath = outer.millSourcePath / 'src / 'test
}
}
trait SbtModule extends MavenModule with ScalaModule{ outer =>
trait Tests extends super.Tests with MavenTests {
override def millSourcePath = outer.millSourcePath
override def intellijModulePath = outer.millSourcePath / 'src / 'test
}
}
trait CrossSbtModule extends SbtModule with CrossModuleBase{ outer =>
override def sources = T.sources{
super.sources() ++
CrossModuleBase.scalaVersionPaths(
crossScalaVersion,
s => millSourcePath / 'src / 'main / s"scala-$s"
)
}
trait Tests extends super.Tests {
override def millSourcePath = outer.millSourcePath
override def sources = T.sources{
super.sources() ++
CrossModuleBase.scalaVersionPaths(
crossScalaVersion,
s => millSourcePath / 'src / 'test / s"scala-$s"
)
}
}
}
|