-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbuild.mill
More file actions
264 lines (230 loc) · 9.24 KB
/
Copy pathbuild.mill
File metadata and controls
264 lines (230 loc) · 9.24 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//| mill-version: 1.0.5
//| repositories:
//| - https://oss.sonatype.org/content/repositories/snapshots
//| mvnDeps:
//| - com.github.lolgab::mill-mima::0.2.1
//| - com.goyeau::mill-scalafix::0.6.0
package build
import build.docs
import mill.util.VcsVersion
import com.goyeau.mill.scalafix.ScalafixModule
import mill.*, scalalib.*, publish.*
import os.Path
val scala3 = "3.6.2"
val scala3Simple = "3.7.0"
trait CommonBase extends ScalaModule with PublishModule with ScalafixModule { common =>
def scalaVersion = scala3
def publishVersion = VcsVersion.vcsState().format()
def pomSettings = PomSettings(
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/com-lihaoyi/scalasql",
licenses = Seq(License.MIT),
versionControl = VersionControl.github(
owner = "com-lihaoyi",
repo = "scalasql"
),
developers = Seq(
Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi")
)
)
def scalacOptions = Task {
Seq(
"-Wunused:privates,locals,explicits,implicits,params"
)
}
def semanticDbVersion: T[String] =
// last version that works with Scala 2.13.12
"4.12.3"
trait CommonTest extends ScalaTests with ScalafixModule {
def semanticDbVersion: T[String] = common.semanticDbVersion
def scalacOptions = common.scalacOptions
def mvnDeps = Seq(
mvn"com.github.vertical-blank:sql-formatter:2.0.4",
mvn"com.lihaoyi::mainargs:0.4.0",
mvn"com.lihaoyi::os-lib:0.9.1",
mvn"com.lihaoyi::upickle:4.2.1",
mvn"com.lihaoyi::utest:0.9.5",
mvn"com.h2database:h2:2.2.224",
mvn"org.xerial:sqlite-jdbc:3.43.0.0",
mvn"org.testcontainers:postgresql:1.21.4",
mvn"org.postgresql:postgresql:42.6.0",
mvn"org.testcontainers:mysql:1.21.4",
mvn"mysql:mysql-connector-java:8.0.33",
mvn"org.testcontainers:mssqlserver:1.21.4",
mvn"com.microsoft.sqlserver:mssql-jdbc:12.8.1.jre11",
mvn"com.zaxxer:HikariCP:5.1.0"
)
def recordedTestsFile: String
def recordedSuiteDescriptionsFile: String
def testFramework = "scalasql.UtestFramework"
def forkArgs = Seq("-Duser.timezone=Asia/Singapore")
def forkEnv = Map(
"MILL_WORKSPACE_ROOT" -> mill.api.BuildCtx.workspaceRoot.toString(),
"SCALASQL_RECORDED_TESTS_NAME" -> recordedTestsFile,
"SCALASQL_RECORDED_SUITE_DESCRIPTIONS_NAME" -> recordedSuiteDescriptionsFile
)
}
}
object `scalasql-simple` extends CommonBase {
def scalaVersion: T[String] = scala3Simple
def moduleDir: Path = scalasql.moduleDir / "simple"
def moduleDeps: Seq[PublishModule] = Seq(scalasql)
// override def scalacOptions: Target[Seq[String]] = Task {
// super.scalacOptions() :+ "-Xprint:inlining"
// }
object test extends CommonTest {
def resources = scalasql.test.resources
def moduleDeps = super.moduleDeps ++ Seq(scalasql, scalasql.test)
def recordedTestsFile: String = "recordedTestsNT.json"
def recordedSuiteDescriptionsFile: String = "recordedSuiteDescriptionsNT.json"
}
}
object scalasql extends CommonBase { common =>
def moduleDeps = Seq(query, operations)
def mvnDeps = Seq.empty[Dep]
override def consoleScalacOptions: T[Seq[String]] = Seq("-Xprint:typer")
object test extends CommonTest {
def recordedTestsFile: String = "recordedTests.json"
def recordedSuiteDescriptionsFile: String = "recordedSuiteDescriptions.json"
}
private def indent(code: Iterable[String]): String =
code.map(_.split("\n").map(" " + _).mkString("\n")).mkString("\n")
object core extends CommonBase {
def mvnDeps = Seq(
mvn"com.lihaoyi::geny:1.0.0",
mvn"com.lihaoyi::sourcecode:0.4.2",
mvn"com.lihaoyi::pprint:0.8.1"
)
def generatedSources = Task {
def commaSep0(i: Int, f: Int => String) = Range.inclusive(1, i).map(f).mkString(", ")
val queryableRowDefs = for (i <- Range.inclusive(2, 22)) yield {
def commaSep(f: Int => String) = commaSep0(i, f)
s"""implicit def Tuple${i}Queryable[${commaSep(j => s"Q$j")}, ${commaSep(j => s"R$j")}](
| implicit
| ${commaSep(j => s"q$j: Queryable.Row[Q$j, R$j]")}
|): Queryable.Row[(${commaSep(j => s"Q$j")}), (${commaSep(j => s"R$j")})] = {
| new Queryable.Row.TupleNQueryable(
| Seq(${commaSep(j => s"q$j.walkLabels()")}),
| t => Seq(${commaSep(j => s"q$j.walkExprs(t._$j)")}),
| construct0 = rsi => (${commaSep(j => s"q$j.construct(rsi)")}),
| deconstruct0 = { is => (${commaSep(j => s"""q$j.deconstruct(is._$j)""")}) }
| )
|}""".stripMargin
}
os.write(
Task.dest / "Generated.scala",
s"""package scalasql.core.generated
|import scalasql.core.Queryable
|trait QueryableRow{
|${indent(queryableRowDefs)}
|}
|""".stripMargin
)
Seq(PathRef(Task.dest / "Generated.scala"))
}
}
object operations extends CommonBase {
def moduleDeps = Seq(core)
}
object query extends CommonBase {
def moduleDeps = Seq(core)
def generatedSources = Task {
def commaSep0(i: Int, f: Int => String) = Range.inclusive(1, i).map(f).mkString(", ")
def defs(isImpl: Boolean) = {
for (i <- Range.inclusive(2, 22)) yield {
def commaSep(f: Int => String) = commaSep0(i, f)
val impl =
if (!isImpl) ""
else
s"""= newInsertValues(
| this,
| columns = Seq(${commaSep(j => s"f$j(expr)")}),
| valuesLists = items.map(t => Seq(${commaSep(j => s"t._$j")}))
| )
|
|""".stripMargin
s"""def batched[${commaSep(j => s"T$j")}](${commaSep(j =>
s"f$j: V[Column] => Column[T$j]"
)})(
| items: (${commaSep(j => s"Expr[T$j]")})*
|)(implicit qr: Queryable[V[Column], R]): scalasql.query.InsertColumns[V, R] $impl""".stripMargin
}
}
val queryableRowDefs = for (i <- Range.inclusive(2, 22)) yield {
def commaSep(f: Int => String) = commaSep0(i, f)
s"""implicit def Tuple${i}Queryable[${commaSep(j => s"Q$j")}, ${commaSep(j => s"R$j")}](
| implicit
| ${commaSep(j => s"q$j: Queryable.Row[Q$j, R$j]")}
|): Queryable.Row[(${commaSep(j => s"Q$j")}), (${commaSep(j => s"R$j")})] = {
| new Queryable.Row.TupleNQueryable(
| Seq(${commaSep(j => s"q$j.walkLabels()")}),
| t => Seq(${commaSep(j => s"q$j.walkExprs(t._$j)")}),
| construct0 = rsi => (${commaSep(j => s"q$j.construct(rsi)")}),
| deconstruct0 = { is => (${commaSep(j => s"""q$j.deconstruct(is._$j)""")}) }
| )
|}""".stripMargin
}
val joinAppendDefs = for (i <- Range.inclusive(2, 21)) yield {
def commaSep(f: Int => String) = commaSep0(i, f)
val commaSepQ = commaSep(j => s"Q$j")
val commaSepR = commaSep(j => s"R$j")
val joinAppendType =
s"scalasql.query.JoinAppend[($commaSepQ), QA, ($commaSepQ, QA), ($commaSepR, RA)]"
s"""
|implicit def append$i[$commaSepQ, QA, $commaSepR, RA](
| implicit qr0: Queryable.Row[($commaSepQ, QA), ($commaSepR, RA)],
| @annotation.nowarn("msg=never used") qr20: Queryable.Row[QA, RA]): $joinAppendType = new $joinAppendType {
| override def appendTuple(t: ($commaSepQ), v: QA): ($commaSepQ, QA) = (${commaSep(j =>
s"t._$j"
)}, v)
|
| def qr: Queryable.Row[($commaSepQ, QA), ($commaSepR, RA)] = qr0
|}""".stripMargin
}
os.write(
Task.dest / "Generated.scala",
s"""package scalasql.generated
|import scalasql.core.{Queryable, Expr}
|import scalasql.query.Column
|trait Insert[V[_[_]], R]{
|${indent(defs(false))}
|}
|trait InsertImpl[V[_[_]], R] extends Insert[V, R]{ this: scalasql.query.Insert[V, R] =>
| def newInsertValues[R](
| insert: scalasql.query.Insert[V, R],
| columns: Seq[Column[?]],
| valuesLists: Seq[Seq[Expr[?]]]
| )(implicit qr: Queryable[V[Column], R]): scalasql.query.InsertColumns[V, R]
|${indent(defs(true))}
|}
|
|trait QueryableRow{
|${indent(queryableRowDefs)}
|}
|
|trait JoinAppend extends scalasql.query.JoinAppendLowPriority{
|${indent(joinAppendDefs)}
|}
|""".stripMargin
)
Seq(PathRef(Task.dest / "Generated.scala"))
}
}
}
val generatedCodeHeader = "[//]: # (GENERATED SOURCES, DO NOT EDIT DIRECTLY)"
def generateTutorial() = Task.Command {
docs.generateTutorial(
mill.api.BuildCtx.workspaceRoot / "scalasql" / "test" / "src" / "WorldSqlTests.scala",
mill.api.BuildCtx.workspaceRoot / "docs" / "tutorial.md"
)
}
def generateReference() = Task.Command {
docs.generateReference(
mill.api.BuildCtx.workspaceRoot / "docs" / "reference.md",
(sources, config) =>
mill.scalalib.scalafmt.ScalafmtWorkerModule
.worker()
.reformat(sources.map(PathRef(_)), PathRef(config))
)
}