-
Notifications
You must be signed in to change notification settings - Fork 22
/
build.mill.scala
257 lines (215 loc) · 9.79 KB
/
build.mill.scala
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
package build
import $meta._
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION`
import com.goyeau.mill.scalafix.ScalafixModule
import com.carlosedp.aliases._
import coursier.maven.MavenRepository
import io.github.davidgregory084.TpolecatModule
import millbuild._
import millbuild.{ Versions => Vers }
import millbuild.crossplatform._
import millbuild.settings._
import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._, scalafmt._
import mill.scalalib.publish.PublishInfo
import mill.scalajslib.api.ModuleKind
import mill.contrib.buildinfo.BuildInfo
import de.tobiasroeser.mill.vcs.version.VcsVersion
object `package` extends RootModule {
implicit val buildSettings: BuildSettings = interp.watchValue(MyBuild.cachedBuildSettings)
def resolvedBuildSettings = T.input(MyBuild.buildSettings())
val scala212 = buildSettings.scala.scala212Version
val scala213 = buildSettings.scala.scala213Version
val scala3x = buildSettings.scala.scala3xVersion
/** The version of Scala natively supported by the toolchain. Morphir itself may provide backends that generate code
* for other Scala versions. We may also directly cross-compile to additional Scla versions.
*/
val morphirScalaVersion: String = interp.watchValue(buildSettings.scala.defaultVersion)
object morphir extends Cross[MorphirModule](buildSettings.scala.crossScalaVersions) {}
trait MorphirModule extends Cross.Module[String] with CrossPlatform {
import DevMode._
trait CommonZioTestModule extends TestModule.ZioTest {
override def ivyDeps = super.ivyDeps() ++ Agg(
Deps.dev.zio.zio,
Deps.dev.zio.`zio-test`,
Deps.dev.zio.`zio-test-sbt`
)
}
trait MorphirCommonModule
extends ScalaModule
with CrossValue
with TpolecatModule
with CommonScalaModule
with CommonCoursierModule {
def semanticDbVersion = T.input(Vers.semanticDb(partialVersion()))
def compilerPluginDependencies(selectedScalaVersion: String) =
Agg.when(selectedScalaVersion.startsWith("3.")) {
Agg(Deps.org.`scala-lang`.`scala3-compiler`(selectedScalaVersion))
}
}
trait MorphirCommonCrossModule extends CrossPlatformScalaModule with CrossValue with CommonCrossScalaModule {
def semanticDbVersion = T.input(Vers.semanticDb(partialVersion()))
def compilerPluginDependencies(selectedScalaVersion: String) =
Agg.when(selectedScalaVersion.startsWith("3.")) {
Agg(Deps.org.`scala-lang`.`scala3-compiler`(selectedScalaVersion))
}
}
trait MorphirJVMModule extends MorphirCommonCrossModule {
def platform = Platform.JVM
}
trait MorphirJSModule extends MorphirCommonCrossModule with ScalaJSModule {
import mill.scalajslib.api._
def platform = Platform.JS
def scalaJSVersion = T(resolvedBuildSettings().js.version)
}
trait MorphirNativeModule extends MorphirCommonCrossModule with ScalaNativeModule {
def platform = Platform.Native
def scalaNativeVersion = T(resolvedBuildSettings().native.version)
}
object ir extends CrossPlatform with CrossValue {
trait Shared extends MorphirCommonCrossModule with MorphirPublishModule {
def ivyDeps = Agg(Deps.io.circe.`circe-core`, Deps.io.circe.`circe-generic`, Deps.io.circe.`circe-parser`)
def platformSpecificModuleDeps: Seq[CrossPlatform] = Seq(sdk.core, sdk.json)
}
object jvm extends Shared with MorphirJVMModule {
object test extends ScalaTests with CommonZioTestModule
}
object js extends Shared with MorphirJSModule {
object test extends ScalaJSTests with CommonZioTestModule {
override def ivyDeps = super.ivyDeps() ++ Agg(
Deps.io.github.cquiroz.`scala-java-time`
)
}
}
object native extends Shared with MorphirNativeModule {
object test extends ScalaNativeTests with CommonZioTestModule
}
}
object sdk extends Module {
object core extends CrossPlatform with CrossValue {
trait Shared extends MorphirCommonCrossModule with MorphirPublishModule {
def ivyDeps = Agg(Deps.org.`scala-lang`.modules.`scala-collection-compat`)
}
object jvm extends Shared with MorphirJVMModule {
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.com.`47Deg`.memeid4s
)
object test extends ScalaTests with CommonZioTestModule
}
object js extends Shared with MorphirJSModule {
object test extends ScalaJSTests with CommonZioTestModule
}
object native extends Shared with MorphirNativeModule {
object test extends ScalaNativeTests with CommonZioTestModule
}
}
object json extends CrossPlatform with CrossValue {
trait Shared extends MorphirCommonCrossModule with MorphirPublishModule {
// Making these compile time only dependencies which is the equivalent to the provided scope in Maven, but I feel we
// should stop doing this. Need to discuss with existing consumers of the SDK to see if this is a problem.
def compileIvyDeps = Agg(
Deps.io.circe.`circe-core`,
Deps.io.circe.`circe-generic`,
Deps.io.circe.`circe-parser`
)
def platformSpecificModuleDeps: Seq[CrossPlatform] = Seq(sdk.core)
}
object jvm extends Shared with MorphirJVMModule {
object test extends ScalaTests with CommonZioTestModule
}
object js extends Shared with MorphirJSModule {
object test extends ScalaJSTests with CommonZioTestModule
}
object native extends Shared with MorphirNativeModule {
object test extends ScalaNativeTests with CommonZioTestModule
}
}
}
}
// -----------------------------------------------------------------------------
// Build settings and common code
// -----------------------------------------------------------------------------
trait MorphirScalaModule extends ScalaModule with TpolecatModule with CommonCoursierModule { self =>
override def scalacOptions = T {
super.scalacOptions().filterNot(Set("-Xlint:nullary-override"))
}
}
trait MorphirScalafixModule extends ScalafixModule
trait MorphirPublishModule extends PublishModule with JavaModule {
import mill.scalalib.publish._
def packageDescription: String = s"The $artifactName package"
def publishAsSnapshot = T.input {
val publishAsSnapshotVar = T.env.getOrElse("PUBLISH_AS_SNAPSHOT", "false")
T.log.info(s"PUBLISH_AS_SNAPSHOT: $publishAsSnapshotVar")
publishAsSnapshotVar match {
case "true" | "1" | "yes" => true
case _ => false
}
}
override def publishVersion: T[String] = T {
val version = VcsVersion.vcsState().format()
if (publishAsSnapshot()) {
s"${version}-SNAPSHOT"
} else {
version
}
}
def pomSettings = PomSettings(
description = packageDescription,
organization = "org.morphir",
url = "https://github.com/finos/morphir-jvm",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github("finos", "morphir-jvm"),
developers = Seq(
Developer(
"DamianReeves",
"Damian Reeves",
"https://github.com/DamianReeves"
),
Developer(
"AttilaMihaly",
"Attila Mihaly",
"https://github.com/AttilaMihaly"
)
)
)
}
import mill.eval.{ Evaluator, EvaluatorPaths }
def bspInstall(jobs: Int = 1) = T.command {
mill.bsp.BSP.install(jobs)
}
def idea(ev: Evaluator.AllBootstrapEvaluators) = T.command {
mill.idea.GenIdea.idea(ev)
}
// def checkFormatAll(evaluator:Evaluator, sources: mill.main.Tasks[Seq[PathRef]])= T.command{
// ScalafmtModule.checkFormatAll(sources)()
// }
// With this we can now just do ./mill reformatAll __.sources
// instead of ./mill -w mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources
def reformatAll(evaluator: Evaluator, @mainargs.arg(short = 's') sources: mill.main.Tasks[Seq[PathRef]]) = T.command {
ScalafmtModule.reformatAll(sources)()
}
def showBuildSettings() = T.command {
MyBuild.showBuildSettings()
}
def crossScalaVersions = T.task {
buildSettings.scala.crossScalaVersions
}
// object MyAliases extends Aliases {
// def fmt = alias("mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources")
// def checkfmt = alias("mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources")
// def ciTestJS = alias("morphir.__.js.__.compile + morphir.__.js.publishArtifacts + morphir.__.js.__.test")
// def ci_test_js_2_12 = morphirAlias(build.scala212)("__.js.__.compile", "__.js.publishArtifacts", "__.js.__.test")
// def ci_test_js_2_13 = morphirAlias(build.scala213)("__.js.__.compile", "__.js.publishArtifacts", "__.js.__.test")
// def ci_test_js_3 = morphirAlias(build.scala3x)("__.js.__.compile", "__.js.publishArtifacts", "__.js.__.test")
// def deps = alias("mill.scalalib.Dependency/showUpdates")
// def testall = alias("__.test")
// def testJVM = alias("morphir.__.jvm.__.test")
// def testJVMCached = alias("morphir.__.jvm.__.testCached")
// def compileall = alias("__.compile")
// def comptestall = alias("__.compile", "__.test")
// def createPublishArtifacts = alias("morphir.__.publishArtifacts")
// def morphirAlias(scalaVersion: String)(tasks: String*) = alias(
// tasks.map(task => s"morphir[$scalaVersion].$task"): _*
// )
// }
}