-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sc
202 lines (170 loc) · 5.94 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
import $ivy.`io.chris-kipp::mill-ci-release::0.1.9`
import $ivy.`software.amazon.smithy:smithy-model:1.27.1`
import $ivy.`software.amazon.smithy:smithy-rules-engine:1.27.1`
import $ivy.`software.amazon.smithy:smithy-build:1.27.1`
import software.amazon.smithy.aws.traits.protocols.AwsProtocolTrait
import $ivy.`software.amazon.smithy:smithy-aws-traits:1.27.1`
import $ivy.`software.amazon.smithy:smithy-aws-iam-traits:1.27.1`
import $ivy.`software.amazon.smithy:smithy-waiters:1.27.1`
import $ivy.`software.amazon.smithy:smithy-aws-cloudformation-traits:1.27.1`
import mill.define.Sources
import software.amazon.smithy.model.transform.ModelTransformer
import software.amazon.smithy.model.shapes._
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.traits._
import java.time.format.DateTimeFormatter
import java.time.DateTimeException
import java.nio.file.Path
import mill._
import mill.scalalib._
import mill.scalalib.publish._
import scala.jdk.CollectionConverters._
import io.kipp.mill.ci.release.CiReleaseModule
import io.kipp.mill.ci.release.SonatypeHost
val smithyVersion = "1.27.1"
val org = "com.disneystreaming.smithy"
def specFolder =
os.pwd / "aws-sdk-js-v3" / "codegen" / "sdk-codegen" / "aws-models"
val allSpecs = os
.list(specFolder)
.map(_.last)
.filter(_.endsWith(".json"))
.map(_.dropRight(".json".length()))
def writeAllSpecs = T {
T.traverse(allSpecs.map(aws(_)))(_.writeForCheckIn())
}
object summary extends BaseModule {
def pomDescription: String =
"Jar containing a summary of published specs for AWS services"
override def artifactName: T[String] = T(s"aws-spec-summary")
def summaryJson = T {
val artifacts = T.traverse(allSpecs.map(aws(_))) { specModule =>
T.task {
ujson.Obj(
"service" -> ujson.Str(specModule.service),
"organization" -> ujson.Str(specModule.pomSettings().organization),
"name" -> ujson.Str(specModule.artifactName()),
"protocol" -> specModule
.protocol()
.map(ujson.Str(_))
.getOrElse(ujson.Null),
"streamingOperations" ->
specModule
.streamingOperations()
.map(ujson.Str(_))
)
}
}()
ujson.Obj(
"version" -> ujson.Str(publishVersion()),
"artifacts" -> artifacts
)
}
def resources: Sources = T.sources {
val target = T.dest / "summary.json"
os.write.over(target, summaryJson(), createFolders = true)
target
}
}
object aws extends Cross[AWSSpec](allSpecs)
trait AWSSpec extends Cross.Module[String] with BaseModule {
val service = crossValue
val pomDescription: String = s"Jar containing smithy spec for $service"
val namespace = service.filter(_.isLetterOrDigit)
val fullFileName = s"com.amazonaws.$namespace.smithy"
val shortFileName = s"$namespace.smithy"
override def artifactName: T[String] = T(s"aws-$service-spec")
override def ivyDeps: T[Agg[Dep]] = Agg(
ivy"software.amazon.smithy:smithy-aws-traits:$smithyVersion",
ivy"software.amazon.smithy:smithy-aws-cloudformation-traits:$smithyVersion",
ivy"software.amazon.smithy:smithy-aws-iam-traits:$smithyVersion",
ivy"software.amazon.smithy:smithy-waiters:$smithyVersion"
)
def writeForCheckIn() = T.task {
os.write(
T.workspace / "specs" / shortFileName,
trimmedModel(),
createFolders = true
)
}
def spec = T.source(specFolder / s"$service.json")
def assembleModel = T.task {
Model
.assembler()
.discoverModels(this.getClass().getClassLoader())
.addImport(spec().path.toNIO)
.assemble()
.unwrap()
}
def protocol: T[Option[String]] = T {
val model = assembleModel()
val protocols = model
.getShapesWithTrait(classOf[ProtocolDefinitionTrait])
.asScala
.filter(_.getId().getNamespace().startsWith("aws"))
.toList
val appliedProtocol = protocols.toList.find { protocolShape =>
!model.getShapesWithTrait(protocolShape).isEmpty
}
appliedProtocol.map(_.toShapeId.getName())
}
def streamingOperations: T[List[String]] = T {
val model = assembleModel()
def memberHasStreaming(shapeId: ShapeId): Boolean = {
model
.expectShape(shapeId)
.members()
.asScala
.map(m => model.expectShape(m.getTarget()))
.exists(_.hasTrait(classOf[StreamingTrait]))
}
model
.getOperationShapes()
.asScala
.filter { op =>
val inputIsStreaming = memberHasStreaming(op.getInputShape())
val outputIsStreaming = memberHasStreaming(op.getOutputShape())
inputIsStreaming || outputIsStreaming
}
.map(_.getId().getName())
.toList
}
def trimmedModel = T {
val model = assembleModel()
val serializer: SmithyIdlModelSerializer = SmithyIdlModelSerializer
.builder()
.shapeFilter(_.getId().getNamespace() != "smithy.rules")
.traitFilter(_.toShapeId().getNamespace() != "smithy.rules")
.build()
val map =
serializer.serialize(model).asScala
map(Path.of(fullFileName))
}
override def resources: Sources = T.sources {
val target = T.dest / "META-INF" / "smithy" / shortFileName
val manifestTarget = T.dest / "META-INF" / "smithy" / "manifest"
os.write.over(target, trimmedModel(), createFolders = true)
os.write.over(manifestTarget, shortFileName, createFolders = true)
Seq(PathRef(T.dest))
}
}
trait BaseModule extends JavaModule with CiReleaseModule {
def pomDescription: String
override def sonatypeHost = Some(SonatypeHost.s01)
def pomSettings: T[PomSettings] = PomSettings(
pomDescription,
"com.disneystreaming.smithy",
licenses = Seq(License.`Apache-2.0`),
url = "http://github.com/disneystreaming/aws-sdk-specs",
versionControl = VersionControl(
Some("https://github.com/disneystreaming/aws-sdk-specs")
),
developers = Seq(
Developer(
"baccata",
"Olivier Mélois",
"https://github.com/baccata"
)
)
)
}