-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sc
240 lines (210 loc) · 8.71 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
// mill plugins
import $ivy.`de.tototec::de.tobiasroeser.mill.integrationtest::0.7.1`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import $ivy.`com.lihaoyi::mill-contrib-scoverage:`
// imports
import de.tobiasroeser.mill.integrationtest._
import de.tobiasroeser.mill.vcs.version.VcsVersion
import mill._
import mill.api.Loose
import mill.contrib.scoverage.ScoverageModule
import mill.define.{Command, Module, TaskModule, Target, Task}
import mill.scalalib._
import mill.scalalib.api.ZincWorkerUtil
import mill.scalalib.publish._
trait Deps {
def kotlinVersion = "1.0.0"
def millPlatform: String
def millVersion: String
def scalaVersion: String = "2.13.15"
def testWithMill: Seq[String]
val kotlinCompiler = ivy"org.jetbrains.kotlin:kotlin-compiler:${kotlinVersion}"
val millMainApi = ivy"com.lihaoyi::mill-main-api:${millVersion}"
val millMain = ivy"com.lihaoyi::mill-main:${millVersion}"
val millScalalib = ivy"com.lihaoyi::mill-scalalib:${millVersion}"
def osLib: Dep
val scalaTest = ivy"org.scalatest::scalatest:3.2.19"
val scoverageVersion = "2.2.1"
val slf4j = ivy"org.slf4j:slf4j-api:1.7.25"
val utilsFunctional = ivy"de.tototec:de.tototec.utils.functional:2.0.1"
}
object Deps_0_11 extends Deps {
override def millVersion = "0.11.0" // scala-steward:off
override def millPlatform = "0.11"
// keep in sync with .github/workflows/build.yml
override def testWithMill = Seq("0.11.8", millVersion)
override val osLib = ivy"com.lihaoyi::os-lib:0.9.1" // scala-steward:off
}
object Deps_0_10 extends Deps {
override def millVersion = "0.10.0" // scala-steward:off
override def millPlatform = "0.10"
// keep in sync with .github/workflows/build.yml
override def testWithMill = Seq("0.10.13", millVersion)
override val osLib = ivy"com.lihaoyi::os-lib:0.8.0" // scala-steward:off
}
object Deps_0_9 extends Deps {
override def millVersion = "0.9.3" // scala-steward:off
override def millPlatform = "0.9"
// keep in sync with .github/workflows/build.yml
override def testWithMill = Seq("0.9.12", millVersion)
override val osLib = ivy"com.lihaoyi::os-lib:0.6.3" // scala-steward:off
}
object Deps_0_7 extends Deps {
override def millVersion = "0.7.0" // scala-steward:off
override def millPlatform = "0.7"
// keep in sync with .github/workflows/build.yml
override def testWithMill = Seq("0.8.0", "0.7.4", "0.7.1", millVersion)
override val osLib = ivy"com.lihaoyi::os-lib:0.6.3" // scala-steward:off
}
val millApiVersions = Seq(Deps_0_11, Deps_0_10, Deps_0_9, Deps_0_7).map(x => x.millPlatform -> x)
val millItestVersions = millApiVersions.flatMap { case (_, d) => d.testWithMill.map(_ -> d) }
lazy val baseDir: os.Path = build.millSourcePath
trait MillKotlinModule extends PublishModule with ScoverageModule with Cross.Module[String] {
def millPlatform: String = crossValue
def deps: Deps = millApiVersions.toMap.apply(millPlatform)
override def scalaVersion = deps.scalaVersion
override def publishVersion: T[String] = VcsVersion.vcsState().format()
override def artifactSuffix: T[String] = s"_mill${millPlatform}_${artifactScalaVersion()}"
override def javacOptions = {
val release =
if (scala.util.Properties.isJavaAtLeast(11)) Seq("-release", "8")
else Seq("-source", "1.8", "-target", "1.8")
release ++ Seq("-encoding", "UTF-8", "-deprecation")
}
override def scalacOptions = Seq("-release:8", "-encoding", "UTF-8", "-deprecation")
override def scoverageVersion = deps.scoverageVersion
def pomSettings = T {
PomSettings(
description = "Kotlin compiler support for Mill",
organization = "de.tototec",
url = "https://github.com/lefou/mill-kotlin",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github("lefou", "mill-kotlin"),
developers = Seq(Developer("lefou", "Tobias Roeser", "https.//github.com/lefou"))
)
}
override def skipIdea: Boolean = millApiVersions.head._2.millPlatform != millPlatform
}
object main extends Cross[MainCross](millApiVersions.map(_._1))
trait MainCross extends MillKotlinModule {
override def artifactName = "de.tobiasroeser.mill.kotlin"
override def moduleDeps: Seq[PublishModule] = Seq(worker)
override def ivyDeps = Agg(
ivy"${scalaOrganization()}:scala-library:${scalaVersion()}"
)
override def sources = T.sources {
val suffixes =
ZincWorkerUtil.matchingVersions(millPlatform) ++
ZincWorkerUtil.versionRanges(millPlatform, millApiVersions.map(_._1))
PathRef(millSourcePath / s"src") +:
suffixes.map(v => PathRef(millSourcePath / ("src-" + v)))
}
override def compileIvyDeps = Agg(
deps.millMain,
deps.millScalalib
)
object test extends ScalaTests with TestModule.ScalaTest {
override def ivyDeps = Agg(
deps.scalaTest
)
}
override def generatedSources: Target[Seq[PathRef]] = T {
super.generatedSources() :+ versionFile()
}
def versionFile: Target[PathRef] = T {
val dest = T.ctx().dest
val body =
s"""package de.tobiasroeser.mill.kotlin
|
|/**
| * Build-time generated versions file.
| */
|object Versions {
| /** The mill-kotlin version. */
| val millKotlinVersion = "${publishVersion()}"
| /** The mill API version used to build mill-kotlin. */
| val buildTimeMillVersion = "${deps.millVersion}"
| /** The ivy dependency holding the mill kotlin worker impl. */
| val millKotlinWorkerImplIvyDep = "${worker.impl.pomSettings().organization}:${worker.impl.artifactId()}:${worker.impl.publishVersion()}"
| /** The default kotlin version used for the compiler. */
| val kotlinCompilerVersion = "${deps.kotlinVersion}"
|}
|""".stripMargin
os.write(dest / "Versions.scala", body)
PathRef(dest)
}
object worker extends MillKotlinModule with CrossValue {
override def artifactName = "de.tobiasroeser.mill.kotlin.worker"
override def compileIvyDeps: T[Agg[Dep]] = Agg(
deps.millMainApi,
deps.osLib
)
object impl extends MillKotlinModule with CrossValue {
override def artifactName = "de.tobiasroeser.mill.kotlin.worker.impl"
override def moduleDeps: Seq[PublishModule] = Seq(worker)
override def compileIvyDeps: T[Agg[Dep]] = Agg(
deps.osLib,
deps.millMainApi,
deps.kotlinCompiler
)
}
}
}
object itest extends Cross[ItestCross](millItestVersions.map(_._1))
trait ItestCross extends MillIntegrationTestModule with Cross.Module[String] {
def millItestVersion = crossValue
val millPlatform = millItestVersions.toMap.apply(millItestVersion).millPlatform
def deps: Deps = millApiVersions.toMap.apply(millPlatform)
override def millTestVersion = millItestVersion
override def pluginsUnderTest = Seq(main(millPlatform))
override def temporaryIvyModules = Seq(main(millPlatform).worker, main(millPlatform).worker.impl)
override def testTargets: T[Seq[String]] = T { Seq("-d", "verify") }
override def testCases: T[Seq[PathRef]] = T {
super.testCases().filter { tc =>
// sys.props("java.version").startsWith("1.8") ||
// (!sys.props("java.version").startsWith("1.") &&
!Seq("kotlin-1.0", "kotlin-1.1", "kotlin-1.2").exists(suffix => tc.path.last.endsWith(suffix))
// )
}
}
override def temporaryIvyModulesDetails: Task[Seq[(PathRef, (PathRef, (PathRef, (PathRef, (PathRef, Artifact)))))]] =
Target.traverse(temporaryIvyModules) { p =>
val jar = p match {
case p: ScoverageModule => p.scoverage.jar
case p => p.jar
}
jar zip (p.sourceJar zip (p.docJar zip (p.pom zip (p.ivy zip p.artifactMetadata))))
}
override def pluginUnderTestDetails: Task[Seq[(PathRef, (PathRef, (PathRef, (PathRef, (PathRef, Artifact)))))]] =
Target.traverse(pluginsUnderTest) { p =>
val jar = p match {
case p: ScoverageModule => p.scoverage.jar
case p => p.jar
}
jar zip (p.sourceJar zip (p.docJar zip (p.pom zip (p.ivy zip p.artifactMetadata))))
}
override def perTestResources = T.sources {
Seq(generatedSharedSrc())
}
def generatedSharedSrc = T {
os.write(
T.dest / "shared.sc",
s"""import $$ivy.`org.scoverage::scalac-scoverage-runtime:${deps.scoverageVersion}`
|import $$ivy.`org.scalatest::scalatest:${deps.scalaTest.dep.version}`
|""".stripMargin
)
PathRef(T.dest)
}
}
object P extends Module {
/**
* Update the millw script.
*/
def millw() = T.command {
val target = mill.util.Util.download("https://raw.githubusercontent.com/lefou/millw/master/millw")
val millw = baseDir / "millw"
os.copy.over(target.path, millw)
os.perms.set(millw, os.perms(millw) + java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE)
target
}
}