forked from disneystreaming/smithy-translate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sc
380 lines (305 loc) · 9.97 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
import $file.buildSetup
import $file.buildDeps
import mill._
import buildSetup._
import buildSetup.ScalaVersions._
import coursier.maven.MavenRepository
import mill.contrib.scalapblib.ScalaPBModule
import mill.contrib.buildinfo
import mill.define.Sources
import mill.define.Task
import mill.scalalib.Assembly
import mill.util.Jvm
import mill.scalajslib.ScalaJSModule
import mill.scalalib._
import mill.scalalib.publish._
import mill.contrib.buildinfo.BuildInfo
import scala.Ordering.Implicits._
object `compiler-core` extends Cross[CompilerCoreModule](scalaVersions)
trait CompilerCoreModule
extends CrossScalaModule
with BaseScalaModule
with BasePublishModule {
def publishArtifactName = "smithytranslate-compiler-core"
def moduleDeps = Seq(traits)
def ivyDeps = Agg(
ivy"com.fasterxml.jackson.core:jackson-databind:2.16.2",
buildDeps.smithy.model,
buildDeps.smithy.build,
buildDeps.cats.mtl,
buildDeps.ciString,
buildDeps.slf4j,
buildDeps.alloy.core,
buildDeps.collectionsCompat
)
}
object `json-schema` extends Cross[JsonSchemaModule](scalaVersions)
trait JsonSchemaModule
extends CrossScalaModule
with BaseScalaModule
with BasePublishModule {
def moduleDeps = Seq(`compiler-core`())
def publishArtifactName = "smithytranslate-json-schema"
def ivyDeps = Agg(
buildDeps.circe.jawn,
buildDeps.everit.jsonSchema,
buildDeps.collectionsCompat
)
object tests extends this.ScalaTests with BaseMunitTests {
def ivyDeps = super.ivyDeps() ++ Agg(
buildDeps.smithy.build,
buildDeps.lihaoyi.oslib
)
}
}
object openapi extends Cross[OpenApiModule](scalaVersions)
trait OpenApiModule
extends CrossScalaModule
with BaseScalaModule
with BasePublishModule {
def publishArtifactName = "smithytranslate-openapi"
def moduleDeps = Seq(`compiler-core`())
def ivyDeps =
buildDeps.swagger.parser
object tests extends this.ScalaTests with BaseMunitTests {
def ivyDeps = super.ivyDeps() ++ Agg(
buildDeps.smithy.build,
buildDeps.smithy.diff,
buildDeps.scalaJavaCompat
)
}
}
object cli
extends BaseScala213Module
with buildinfo.BuildInfo
with BasePublishModule {
def publishArtifactName = "smithytranslate-cli"
def moduleDeps =
Seq(
openapi(scala213),
proto(scala213),
`json-schema`(scala213),
formatter.jvm(scala213)
)
def ivyDeps = Agg(
buildDeps.decline,
buildDeps.coursier,
buildDeps.lihaoyi.oslib,
buildDeps.lihaoyi.ujson,
buildDeps.smithy.build
)
object tests extends this.ScalaTests with BaseMunitTests {
def ivyDeps =
super.ivyDeps() ++ Agg(buildDeps.lihaoyi.oslib, buildDeps.lihaoyi.ujson)
}
def buildInfoPackageName = "smithytranslate.cli.internal"
def buildInfoMembers = Seq(
BuildInfo.Value("alloyVersion", buildDeps.alloy.alloyVersion),
BuildInfo.Value("cliVersion", publishVersion().toString)
)
def runProtoAux = T.task { (inputs: List[os.Path], output: os.Path) =>
val inputArgs = inputs.flatMap { p =>
"--input" :: p.toString() :: Nil
}.toList
val cmd = List("smithy-to-proto")
val args = cmd ++ inputArgs ++ List(output.toString)
mill.util.Jvm.runSubprocess(
finalMainClass(),
runClasspath().map(_.path),
mainArgs = args
)
}
}
object formatter extends BaseModule { outer =>
val deps = Agg(
ivy"org.typelevel::cats-parse::1.1.0",
buildDeps.collectionsCompat
)
object jvm extends Cross[JvmModule](scalaVersions)
trait JvmModule
extends CrossScalaModule
with BaseScalaModule
with BasePublishModule { jvmOuter =>
def publishArtifactName = "smithytranslate-formatter"
override def ivyDeps = T { super.ivyDeps() ++ deps }
override def millSourcePath = outer.millSourcePath
object tests extends this.ScalaTests with BaseMunitTests {
def ivyDeps = super.ivyDeps() ++ Agg(
buildDeps.smithy.build,
buildDeps.lihaoyi.oslib
)
}
object `parser-test` extends BaseScalaModule {
def scalaVersion = jvmOuter.scalaVersion
def moduleDeps = Seq(jvmOuter)
override def millSourcePath = outer.millSourcePath / "parser-test"
def ivyDeps = Agg(
buildDeps.decline,
buildDeps.lihaoyi.oslib
)
}
object shaded extends BaseJavaModule with BasePublishModule {
override def millSourcePath = outer.millSourcePath / "shaded"
def publishArtifactName = "smithytranslate-formatter-shaded"
override def localClasspath: T[Seq[PathRef]] =
jvmOuter.localClasspath()
override def resolvedRunIvyDeps: T[Agg[PathRef]] =
jvmOuter.resolvedRunIvyDeps()
override def publishXmlDeps = T.task { Agg.empty[Dependency] }
override def assemblyRules: Seq[Assembly.Rule] =
super.assemblyRules ++ Seq(
Assembly.Rule
.Relocate("smithytranslate.**", "smithyfmt.smithytranslate.@1"),
Assembly.Rule.Relocate("scala.**", "smithyfmt.scala.@1"),
Assembly.Rule.Relocate("cats.**", "smithyfmt.cats.@1")
)
override def jar: T[PathRef] = assembly
}
object `java-api` extends BaseJavaModule with BasePublishModule {
def publishArtifactName = "smithytranslate-formatter-java-api"
override def unmanagedClasspath = T {
super.unmanagedClasspath() ++ Agg(jvmOuter.shaded.jar())
}
override def publishXmlDeps = T.task {
Agg(
mill.scalalib.publish.Dependency(
jvmOuter.shaded.publishSelfDependency(),
Scope.Compile
)
)
}
override def millSourcePath = outer.millSourcePath / "java-api"
}
}
object js extends Cross[JsModule](scalaVersions)
trait JsModule extends CrossScalaModule with BaseScalaJSModule {
def publishArtifactName = "smithytranslate-formatter"
override def ivyDeps = T { super.ivyDeps() ++ deps }
override def millSourcePath = outer.millSourcePath
def jsSources = T { PathRef(millSourcePath / "src-js") }
override def sources = T {
super.sources() :+ jsSources()
}
}
}
object traits extends BaseJavaModule with BasePublishModule {
def publishArtifactName = "smithytranslate-traits"
def ivyDeps = Agg(
buildDeps.smithy.model
)
/** Exclude smithy file from source jars to avoid conflict with smithy files
* packaged into the main jar (happens when scanning the classpath via the
* ModelAssembler if sources jars were resolved).
*/
override def sourceJar: T[PathRef] = T {
def underMetaInfSmithy(p: os.RelPath): Boolean =
Seq("META-INF", "smithy").forall(p.segments.contains)
Jvm.createJar(
(allSources() ++ resources())
.map(_.path)
.filter(os.exists),
manifest(),
fileFilter = (_, relPath) => !underMetaInfSmithy(relPath)
)
}
object tests extends Cross[TestsModule](scalaVersions)
trait TestsModule
extends CrossScalaModule
with JavaModuleTests
with BaseMunitTests
}
object `readme-validator` extends BaseScala213Module {
def moduleDeps =
Seq(openapi(scala213), proto(scala213), `json-schema`(scala213))
def ivyDeps = Agg(
buildDeps.cats.parse,
buildDeps.lihaoyi.oslib
)
def readmeFile = T.sources { os.pwd / "README.md" }
def validate() = T.command {
val args = Seq(readmeFile().head.path.toString)
mill.util.Jvm.runSubprocess(
finalMainClass(),
runClasspath().map(_.path),
mainArgs = args
)
}
}
object proto extends Cross[ProtoModule](scalaVersions)
trait ProtoModule
extends CrossScalaModule
with BaseScalaModule
with BasePublishModule {
def publishArtifactName = "smithytranslate-proto"
def ivyDeps = Agg(
buildDeps.smithy.model,
buildDeps.alloy.core,
buildDeps.collectionsCompat
)
def moduleDeps = Seq(traits, transitive())
object tests extends this.ScalaTests with BaseMunitTests with ScalaPBModule {
def ivyDeps = super.ivyDeps() ++ Agg(
buildDeps.smithy.build,
buildDeps.scalapb.compilerPlugin,
buildDeps.scalapb.protocCache.withDottyCompat(scalaVersion()),
buildDeps.alloy.protobuf
)
def scalaPBVersion = buildDeps.scalapb.version
// There are no sources to generate in this module.
// We use scalaPB to unpack some files.
// Changes in the 0.10.10 version mill removed a check
// that ensures the directory existed before running the
// compiler and that breaks this build.
// See: https://github.com/com-lihaoyi/mill/pull/2126/files
def compileScalaPB = T {
val out = T.dest
PathRef(out)
}
override def scalaPBOptions = "scala3_sources"
def protobufDefinitions = T.sources { Seq(scalaPBUnpackProto()) }
def resources = T.sources {
super.resources() ++ protobufDefinitions()
}
}
}
object `proto-examples` extends BaseScala213Module with ScalaPBModule {
def scalaPBVersion = buildDeps.scalapb.version
def smithyFiles = T.sources {
os.walk(millSourcePath / "smithy", skip = !_.last.endsWith(".smithy"))
.map(p => PathRef(p))
}
def cliRunOutput = millSourcePath / "protobuf"
def scalaPBSources = T.sources { runCli()() }
// required to include wrappers proto definitions
def scalaPBIncludePath = T.sources { Seq(scalaPBUnpackProto()) }
def runCli() = T.command {
os.remove.all(cliRunOutput)
os.makeDir.all(cliRunOutput)
val input = smithyFiles().toList.map(_.path)
val f = cli.runProtoAux()
f(input, cliRunOutput)
cliRunOutput
}
def ivyDeps = Agg(
buildDeps.grpc.netty,
buildDeps.grpc.services,
buildDeps.scalapb.runtimeGrpc
)
}
object transitive extends Cross[TransitiveModule](scalaVersions)
trait TransitiveModule
extends CrossScalaModule
with BaseScalaModule
with BasePublishModule {
def publishArtifactName = "smithytranslate-transitive"
def ivyDeps = Agg(
buildDeps.smithy.model,
buildDeps.smithy.build,
buildDeps.collectionsCompat
)
object tests extends ScalaTests with BaseMunitTests {
def ivyDeps = super.ivyDeps() ++ Agg(
buildDeps.scalaJavaCompat
)
}
}