-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sc
246 lines (214 loc) · 8.3 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
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
import mill._, scalalib._, scalanativelib._, publish._, scalafmt._
val scala213 = "2.13.10"
val scala3 = "3.2.2"
val scalaNative = "0.4.12"
val dottyCustomVersion = Option(sys.props("dottyVersion"))
def gitVersion = T.input {
os.proc("git", "describe", "--dirty=-SNAPSHOT").call(check = false).out.string.trim
}
val VersionHeader = """## (\d.*)""".r
def releaseVersion = T.input {
val lines = os.read.lines.stream(os.pwd / "CHANGELOG.md")
val version = lines.collectFirst{
case VersionHeader(version) => version
}.getOrElse("<latest version>")
os.write(T.dest / "version", version)
version
}
trait Utest extends ScalaModule with TestModule {
def ivyDeps = Agg(
ivy"com.lihaoyi::utest::0.8.1",
ivy"com.lihaoyi::upickle:3.0.0"
)
def testFramework = "utest.runner.Framework"
}
trait Publish extends PublishModule {
def publishVersion = gitVersion()
def pomSettings = PomSettings(
description = "argparse",
organization = "io.crashbox",
url = "https://github.com/jodersky/scala-argparse",
licenses = Seq(License.MIT),
versionControl = VersionControl.github("jodersky", "scala-argparse"),
developers = Seq(
Developer("jodersky", "Jakob Odersky", "https://github.com/jodersky")
)
)
}
object argparse extends Module {
trait ArgParseModule
extends CrossScalaModule
with ScalafmtModule
with Publish {
def scalacOptions = Seq("-deprecation", "-release", "8")
def ivyDeps = Agg(ivy"com.lihaoyi::os-lib::0.9.1")
def artifactName = "argparse"
}
class JvmModule(val crossScalaVersion: String) extends ArgParseModule { main =>
def millSourcePath = super.millSourcePath / os.up
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / "src-jvm")))
def superOptions = T{super.scalacOptions()}
def scalacOptions = if (crossScalaVersion.startsWith("3")) {
// it's enough to check macros for only one configuration
superOptions() ++ Seq("-Xcheck-macros", "-Ycheck:all")
} else superOptions()
object test extends Tests with Utest {
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / s"src-${crossScalaVersion.head}")))
def scalacOptions = main.superOptions()
}
}
object jvm extends Cross[JvmModule]((Seq(scala213, scala3) ++ dottyCustomVersion):_*)
class NativeModule(val crossScalaVersion: String, val crossScalaNativeVersion: String)
extends ArgParseModule
with ScalaNativeModule {
def scalaNativeVersion = crossScalaNativeVersion
def millSourcePath = super.millSourcePath / os.up / os.up
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / "src-native")))
object test extends Tests with Utest {
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / s"src-${crossScalaVersion.head}")))
}
}
object native extends Cross[NativeModule]((scala213, scalaNative), (scala3, scalaNative))
object sandbox extends ScalaModule {
def moduleDeps = Seq(jvm(scala3))
def scalaVersion = scala3
def scalacOptions = Seq("-Xprint:inline")
}
}
// experimental, typed configuration library
object configparse extends Module {
object core extends Module {
trait CoreConfigParseModule
extends ScalaModule
with ScalafmtModule
with Publish {
def scalaVersion = scala3 // this module is only available for Scala 3
def scalacOptions = Seq("-deprecation", "-release", "8")
def ivyDeps = Agg(ivy"com.lihaoyi::os-lib::0.9.1")
def millSourcePath = super.millSourcePath / os.up
def artifactName = "configparse-core"
}
object jvm extends CoreConfigParseModule {
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / "src-jvm")))
object test extends Tests with Utest
}
object native extends CoreConfigParseModule with ScalaNativeModule {
def scalaNativeVersion = scalaNative
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / "src-native")))
object test extends Tests with Utest
}
}
trait ConfigParseModule
extends ScalaModule
with ScalafmtModule
with Publish {
def scalaVersion = scala3 // this module is only available for Scala 3
def scalacOptions = Seq("-deprecation", "-release", "8")
def ivyDeps = Agg(
ivy"com.lihaoyi::os-lib::0.9.1",
ivy"io.crashbox::yamlesque::0.3.2"
)
def millSourcePath = super.millSourcePath / os.up
def artifactName = "configparse"
}
object jvm extends ConfigParseModule {
def moduleDeps = Seq(core.jvm, argparse.jvm(scala3))
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / "src-jvm")))
object test extends Tests with Utest
}
object native extends ConfigParseModule with ScalaNativeModule {
def moduleDeps = Seq(core.native, argparse.native(scala3, scalaNative))
def scalaNativeVersion = scalaNative
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / "src-native")))
object test extends Tests with Utest
}
}
object ini extends Module {
trait IniModule
extends CrossScalaModule
with ScalafmtModule
with Publish {
def scalacOptions = Seq("-deprecation", "-release", "8")
def ivyDeps = Agg(
ivy"com.lihaoyi::os-lib::0.9.1"
)
def artifactName = "argparse-ini"
}
class JvmModule(val crossScalaVersion: String) extends IniModule {
def millSourcePath = super.millSourcePath / os.up
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / "src-jvm")))
object test extends Tests with Utest
}
object jvm extends Cross[JvmModule]((Seq(scala213, scala3) ++ dottyCustomVersion):_*)
class NativeModule(val crossScalaVersion: String, val crossScalaNativeVersion: String)
extends IniModule
with ScalaNativeModule {
def scalaNativeVersion = crossScalaNativeVersion
def millSourcePath = super.millSourcePath / os.up / os.up
def sources = T.sources(super.sources() ++ Seq(PathRef(millSourcePath / "src-native")))
// object test extends Tests with Utest
}
object native extends Cross[NativeModule]((scala213, scalaNative), (scala3, scalaNative))
}
object testutil extends ScalaNativeModule {
def scalaVersion = scala3
def scalaNativeVersion = scalaNative
def scalacOptions = argparse.native(scala3, scalaNative).scalacOptions
def ivyDeps = Agg(
ivy"com.lihaoyi::utest::0.8.1",
ivy"com.lihaoyi::os-lib::0.9.1"
)
}
object examples extends Module {
trait ExampleApp extends ScalaNativeModule { self =>
def scalaVersion = scala3
def scalaNativeVersion = scalaNative
def scalacOptions = argparse.native(scala3, scalaNative).scalacOptions
def moduleDeps = Seq(argparse.native(scala3, scalaNative))
object test extends Tests with Utest {
def moduleDeps = super.moduleDeps ++ Seq(testutil)
def forkEnv = T {
Map(
"SNIPPET_FILE" -> (self.millSourcePath / "src" / "shell.txt").toString,
"PATH" -> s"${self.nativeLink() / os.up}:${sys.env("PATH")}"
)
}
}
def nativeLink = T {
os.Path(scalaNativeWorker().nativeLink(nativeConfig(), (T.dest / "app").toIO))
}
}
object `annotation-intro` extends ExampleApp
object `annotation-mappings` extends ExampleApp
object `annotation-types` extends ExampleApp
object `annotation-commands` extends ExampleApp
object `annotation-annot` extends ExampleApp
object `annotation-output` extends ExampleApp
object basic extends ExampleApp
object completion1 extends ExampleApp
object completion2 extends ExampleApp
object help extends ExampleApp
object paramdep extends ExampleApp
object paramenv extends ExampleApp
object paramflag extends ExampleApp
object paramnamed extends ExampleApp
object paramopt extends ExampleApp
object paramrep extends ExampleApp
object paramreq extends ExampleApp
object paramreq2 extends ExampleApp
object paramreq3 extends ExampleApp
object paramshort extends ExampleApp
object reader extends ExampleApp
object readme extends ExampleApp
object subparsers extends ExampleApp
}
object book extends Module {
def book = T.input {
val env = Map(
"MDBOOK_BOOK__title" -> s"scala-argparse ${releaseVersion()}"
)
os.proc("mdbook", "build", "--dest-dir", T.dest, millSourcePath).call(env = env, stdout = os.Inherit)
os.copy(argparse.jvm(scala3).docJar().path / os.up / "javadoc", T.dest / "javadoc")
T.dest
}
}