forked from com-lihaoyi/PPrint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sc
134 lines (122 loc) · 4.29 KB
/
build.sc
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import mill._, scalalib._, scalajslib._, scalanativelib._, publish._
trait PPrintModule extends PublishModule {
def artifactName = "pprint"
def publishVersion = "0.5.9"
def pomSettings = PomSettings(
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/lihaoyi/PPrint",
licenses = Seq(License.MIT),
scm = SCM(
"git://github.com/lihaoyi/PPrint.git",
"scm:git://github.com/lihaoyi/PPrint.git"
),
developers = Seq(
Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi")
)
)
}
trait PPrintMainModule extends CrossScalaModule {
def millSourcePath = super.millSourcePath / offset
def ivyDeps = Agg(
ivy"com.lihaoyi::fansi::0.2.9",
ivy"com.lihaoyi::sourcecode::0.2.1"
)
def compileIvyDeps = Agg(
ivy"org.scala-lang:scala-reflect:${scalaVersion()}",
ivy"org.scala-lang:scala-compiler:${scalaVersion()}"
)
def offset: os.RelPath = os.rel
def sources = T.sources(
super.sources()
.flatMap(source =>
Seq(
PathRef(source.path / os.up / source.path.last),
PathRef(source.path / os.up / os.up / source.path.last),
)
)
)
def generatedSources = T{
val dir = T.ctx().dest
val file = dir/"pprint"/"TPrintGen.scala"
val typeGen = for(i <- 2 to 22) yield {
val ts = (1 to i).map("T" + _).mkString(", ")
val tsBounded = (1 to i).map("T" + _ + ": Type").mkString(", ")
val tsGet = (1 to i).map("get[T" + _ + "](cfg)").mkString(" + \", \" + ")
s"""
implicit def F${i}TPrint[$tsBounded, R: Type] = make[($ts) => R](cfg =>
"(" + $tsGet + ") => " + get[R](cfg)
)
implicit def T${i}TPrint[$tsBounded] = make[($ts)](cfg =>
"(" + $tsGet + ")"
)
"""
}
val output = s"""
package pprint
trait TPrintGen[Type[_], Cfg]{
def make[T](f: Cfg => String): Type[T]
def get[T: Type](cfg: Cfg): String
implicit def F0TPrint[R: Type] = make[() => R](cfg => "() => " + get[R](cfg))
implicit def F1TPrint[T1: Type, R: Type] = {
make[T1 => R](cfg => get[T1](cfg) + " => " + get[R](cfg))
}
${typeGen.mkString("\n")}
}
""".stripMargin
os.write(file, output, createFolders = true)
Seq(PathRef(file))
}
}
trait PPrintTestModule extends ScalaModule with TestModule {
def crossScalaVersion: String
def testFrameworks = Seq("utest.runner.Framework")
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.7.4")
def offset: os.RelPath = os.rel
def millSourcePath = super.millSourcePath / os.up
def sources = T.sources(
super.sources()
.++(CrossModuleBase.scalaVersionPaths(crossScalaVersion, s => millSourcePath / s"src-$s" ))
.flatMap(source =>
Seq(
PathRef(source.path / os.up / "test" / source.path.last),
PathRef(source.path / os.up / os.up / "test" / source.path.last),
)
)
.distinct
)
}
object pprint extends Module {
object jvm extends Cross[JvmPPrintModule]("2.12.8", "2.13.0")
class JvmPPrintModule(val crossScalaVersion: String)
extends PPrintMainModule with ScalaModule with PPrintModule {
object test extends Tests with PPrintTestModule{
val crossScalaVersion = JvmPPrintModule.this.crossScalaVersion
}
}
object js extends Cross[JsPPrintModule](
("2.12.8", "0.6.31"), ("2.13.0", "0.6.31"),
("2.12.8", "1.0.0"), ("2.13.0", "1.0.0")
)
class JsPPrintModule(val crossScalaVersion: String, crossJSVersion: String)
extends PPrintMainModule with ScalaJSModule with PPrintModule {
def offset = os.up
def scalaJSVersion = crossJSVersion
object test extends Tests with PPrintTestModule{
def offset = os.up
val crossScalaVersion = JsPPrintModule.this.crossScalaVersion
}
}
object native extends Cross[NativePPrintModule](
("2.11.12", "0.3.9"), ("2.11.12", "0.4.0-M2")
)
class NativePPrintModule(val crossScalaVersion: String, crossScalaNativeVersion: String)
extends PPrintMainModule with ScalaNativeModule with PPrintModule {
def offset = os.up
def scalaNativeVersion = crossScalaNativeVersion
object test extends Tests with PPrintTestModule{
def offset = os.up
val crossScalaVersion = NativePPrintModule.this.crossScalaVersion
}
}
}