forked from com-lihaoyi/mill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sc
2089 lines (1863 loc) · 70 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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// plugins and dependencies
import $file.ci.shared
import $file.ci.upload
import $ivy.`org.scalaj::scalaj-http:2.4.2`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version_mill0.10:0.3.1`
import $ivy.`com.github.lolgab::mill-mima_mill0.10:0.0.19`
import $ivy.`net.sourceforge.htmlcleaner:htmlcleaner:2.25`
// imports
import com.github.lolgab.mill.mima
import com.github.lolgab.mill.mima.{
CheckDirection,
DirectMissingMethodProblem,
IncompatibleMethTypeProblem,
IncompatibleSignatureProblem,
ProblemFilter,
ReversedMissingMethodProblem
}
import coursier.maven.MavenRepository
import de.tobiasroeser.mill.vcs.version.VcsVersion
import mill._
import mill.define.{Command, Source, Sources, Target, Task}
import mill.eval.Evaluator
import mill.main.MainModule
import mill.scalalib._
import mill.scalalib.publish._
import mill.modules.Jvm
import mill.define.SelectMode
import scala.util.control.NonFatal
import mill.T
import mill.define.{Discover, ExternalModule, Input, Module, Task}
import mill.api.{Logger, Result}
import os.{CommandResult, SubprocessException}
object Settings {
val pomOrg = "com.lihaoyi"
val githubOrg = "com-lihaoyi"
val githubRepo = "mill"
val projectUrl = s"https://github.com/${githubOrg}/${githubRepo}"
val changelogUrl = s"${projectUrl}#changelog"
val docUrl = "https://com-lihaoyi.github.io/mill"
// the exact branches containing a doc root
val docBranches = Seq()
// the exact tags containing a doc root
val legacyDocTags: Seq[String] = Seq(
"0.9.12",
"0.10.0",
"0.10.12",
"0.11.0-M7"
)
val docTags: Seq[String] = Seq()
val mimaBaseVersions: Seq[String] = Seq("0.11.0-M8")
}
object Deps {
// The Scala version to use
val scalaVersion = "2.13.10"
// Scoverage 1.x will not get releases for newer Scala versions
val scalaVersionForScoverageWorker1 = "2.13.8"
// The Scala 2.12.x version to use for some workers
val workerScalaVersion212 = "2.12.17"
val testScala213Version = "2.13.8"
val testScala212Version = "2.12.6"
val testScala211Version = "2.11.12"
val testScala210Version = "2.10.6"
val testScala30Version = "3.0.2"
val testScala31Version = "3.1.3"
val testScala32Version = "3.2.0"
object Scalajs_1 {
val scalaJsVersion = "1.13.1"
val scalajsEnvJsdomNodejs = ivy"org.scala-js::scalajs-env-jsdom-nodejs:1.1.0"
val scalajsEnvExoegoJsdomNodejs = ivy"net.exoego::scalajs-env-jsdom-nodejs:2.1.0"
val scalajsEnvNodejs = ivy"org.scala-js::scalajs-env-nodejs:1.4.0"
val scalajsEnvPhantomjs = ivy"org.scala-js::scalajs-env-phantomjs:1.0.0"
val scalajsEnvSelenium = ivy"org.scala-js::scalajs-env-selenium:1.1.1"
val scalajsSbtTestAdapter = ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJsVersion}"
val scalajsLinker = ivy"org.scala-js::scalajs-linker:${scalaJsVersion}"
}
object Scalanative_0_4 {
val scalanativeVersion = "0.4.12"
val scalanativeTools = ivy"org.scala-native::tools:${scalanativeVersion}"
val scalanativeUtil = ivy"org.scala-native::util:${scalanativeVersion}"
val scalanativeNir = ivy"org.scala-native::nir:${scalanativeVersion}"
val scalanativeTestRunner = ivy"org.scala-native::test-runner:${scalanativeVersion}"
}
trait Play {
def playVersion: String
def playBinVersion: String = playVersion.split("[.]").take(2).mkString(".")
def routesCompiler = ivy"com.typesafe.play::routes-compiler::$playVersion"
def scalaVersion: String = Deps.scalaVersion
}
object Play_2_6 extends Play {
val playVersion = "2.6.25"
override def scalaVersion: String = Deps.workerScalaVersion212
}
object Play_2_7 extends Play {
val playVersion = "2.7.9"
}
object Play_2_8 extends Play {
val playVersion = "2.8.19"
}
val play = Seq(Play_2_8, Play_2_7, Play_2_6).map(p => (p.playBinVersion, p)).toMap
val acyclic = ivy"com.lihaoyi:::acyclic:0.3.6"
val ammoniteVersion = "3.0.0-M0-6-34034262"
val scalaparse = ivy"com.lihaoyi::scalaparse:3.0.1"
val bloopConfig = ivy"ch.epfl.scala::bloop-config:1.5.5"
val coursier = ivy"io.get-coursier::coursier:2.1.3"
val coursierInterface = ivy"io.get-coursier:interface:1.0.16"
val flywayCore = ivy"org.flywaydb:flyway-core:8.5.13"
val graphvizJava = ivy"guru.nidi:graphviz-java-all-j2v8:0.18.1"
val junixsocket = ivy"com.kohlschutter.junixsocket:junixsocket-core:2.6.2"
val jgraphtCore = ivy"org.jgrapht:jgrapht-core:1.4.0" // 1.5.0+ dont support JDK8
val jna = ivy"net.java.dev.jna:jna:5.13.0"
val jnaPlatform = ivy"net.java.dev.jna:jna-platform:5.13.0"
val junitInterface = ivy"com.github.sbt:junit-interface:0.13.3"
val lambdaTest = ivy"de.tototec:de.tobiasroeser.lambdatest:0.8.0"
val log4j2Core = ivy"org.apache.logging.log4j:log4j-core:2.20.0"
val osLib = ivy"com.lihaoyi::os-lib:0.9.1"
val pprint = ivy"com.lihaoyi::pprint:0.8.1"
val mainargs = ivy"com.lihaoyi::mainargs:0.5.0"
val millModuledefsVersion = "0.10.9"
val millModuledefsString = s"com.lihaoyi::mill-moduledefs:${millModuledefsVersion}"
val millModuledefs = ivy"${millModuledefsString}"
val millModuledefsPlugin =
ivy"com.lihaoyi:::scalac-mill-moduledefs-plugin:${millModuledefsVersion}"
// can't use newer versions, as these need higher Java versions
val testng = ivy"org.testng:testng:7.5.1"
val sbtTestInterface = ivy"org.scala-sbt:test-interface:1.0"
val scalaCheck = ivy"org.scalacheck::scalacheck:1.17.0"
def scalaCompiler(scalaVersion: String) = ivy"org.scala-lang:scala-compiler:${scalaVersion}"
val scalafmtDynamic = ivy"org.scalameta::scalafmt-dynamic:3.7.3"
val scalametaTrees = ivy"org.scalameta::trees:4.7.7"
def scalaReflect(scalaVersion: String) = ivy"org.scala-lang:scala-reflect:${scalaVersion}"
val scalacScoveragePlugin = ivy"org.scoverage:::scalac-scoverage-plugin:1.4.11"
val scoverage2Version = "2.0.8"
val scalacScoverage2Plugin = ivy"org.scoverage:::scalac-scoverage-plugin:${scoverage2Version}"
val scalacScoverage2Reporter = ivy"org.scoverage::scalac-scoverage-reporter:${scoverage2Version}"
val scalacScoverage2Domain = ivy"org.scoverage::scalac-scoverage-domain:${scoverage2Version}"
val scalacScoverage2Serializer =
ivy"org.scoverage::scalac-scoverage-serializer:${scoverage2Version}"
// keep in sync with doc/antora/antory.yml
val semanticDB = ivy"org.scalameta:::semanticdb-scalac:4.7.7"
val semanticDbJava = ivy"com.sourcegraph:semanticdb-java:0.8.18"
val sourcecode = ivy"com.lihaoyi::sourcecode:0.3.0"
val upickle = ivy"com.lihaoyi::upickle:3.1.0"
val utest = ivy"com.lihaoyi::utest:0.8.1"
val windowsAnsi = ivy"io.github.alexarchambault.windows-ansi:windows-ansi:0.0.5"
val zinc = ivy"org.scala-sbt::zinc:1.8.0"
// keep in sync with doc/antora/antory.yml
val bsp4j = ivy"ch.epfl.scala:bsp4j:2.1.0-M4"
val fansi = ivy"com.lihaoyi::fansi:0.4.0"
val jarjarabrams = ivy"com.eed3si9n.jarjarabrams::jarjar-abrams-core:1.8.2"
val requests = ivy"com.lihaoyi::requests:0.8.0"
}
def millVersion: T[String] = T { VcsVersion.vcsState().format() }
def millLastTag: T[String] = T {
VcsVersion.vcsState().lastTag.getOrElse(
sys.error("No (last) git tag found. Your git history seems incomplete!")
)
}
def millBinPlatform: T[String] = T {
val tag = millLastTag()
if (tag.contains("-M")) tag
else {
val pos = if (tag.startsWith("0.")) 2 else 1
tag.split("[.]", pos + 1).take(pos).mkString(".")
}
}
def baseDir = build.millSourcePath
// We limit the number of compiler bridges to compile and publish for local
// development and testing, because otherwise it takes forever to compile all
// of them. Compiler bridges not in this set will get downloaded and compiled
// on the fly anyway. For publishing, we publish everything.
val buildAllCompilerBridges = interp.watchValue(sys.env.contains("MILL_BUILD_COMPILER_BRIDGES"))
val bridgeVersion = "0.0.1"
val bridgeScalaVersions = Seq(
// Our version of Zinc doesn't work with Scala 2.12.0 and 2.12.4 compiler
// bridges. We skip 2.12.1 because it's so old not to matter, and we need a
// non-supported scala versionm for testing purposes. We skip 2.13.0-2 because
// scaladoc fails on windows
/*"2.12.0",*/ /*2.12.1",*/ "2.12.2",
"2.12.3", /*"2.12.4",*/ "2.12.5",
"2.12.6",
"2.12.7",
"2.12.8",
"2.12.9",
"2.12.10",
"2.12.11",
"2.12.12",
"2.12.13",
"2.12.14",
"2.12.15",
"2.12.16",
"2.12.17",
/*"2.13.0", "2.13.1", "2.13.2",*/ "2.13.3",
"2.13.4",
"2.13.5",
"2.13.6",
"2.13.7",
"2.13.8",
"2.13.9",
"2.13.10"
)
val buildBridgeScalaVersions =
if (!buildAllCompilerBridges) Seq()
else bridgeScalaVersions
object bridge extends Cross[BridgeModule](buildBridgeScalaVersions: _*)
class BridgeModule(val crossScalaVersion: String) extends PublishModule with CrossScalaModule {
def scalaVersion = crossScalaVersion
def publishVersion = bridgeVersion
def artifactName = T { "mill-scala-compiler-bridge" }
def pomSettings = commonPomSettings(artifactName())
def crossFullScalaVersion = true
def ivyDeps = Agg(
ivy"org.scala-sbt:compiler-interface:${Versions.zinc}",
ivy"org.scala-lang:scala-compiler:${crossScalaVersion}"
)
def resources = T.sources {
os.copy(generatedSources().head.path / "META-INF", T.dest / "META-INF")
Seq(PathRef(T.dest))
}
def generatedSources = T {
import mill.scalalib.api.ZincWorkerUtil.{grepJar, scalaBinaryVersion}
val resolvedJars = resolveDeps(
T.task { Agg(ivy"org.scala-sbt::compiler-bridge:${Deps.zinc.dep.version}") },
sources = true
)()
val bridgeJar = grepJar(
resolvedJars.map(_.path),
s"compiler-bridge_${scalaBinaryVersion(scalaVersion())}",
Deps.zinc.dep.version,
true
)
mill.api.IO.unpackZip(bridgeJar, os.rel)
Seq(PathRef(T.dest))
}
}
trait BuildInfo extends JavaModule {
/**
* The package name under which the BuildInfo data object will be stored.
*/
def buildInfoPackageName: String
/**
* The name of the BuildInfo data object, defaults to "BuildInfo"
*/
def buildInfoObjectName: String = "BuildInfo"
/**
* Enable to compile the BuildInfo values directly into the classfiles,
* rather than the default behavior of storing them as a JVM resource. Needed
* to use BuildInfo on Scala.js which does not support JVM resources
*/
def buildInfoStaticCompiled: Boolean = false
/**
* A mapping of key-value pairs to pass from the Build script to the
* application code at runtime.
*/
def buildInfoMembers: T[Seq[BuildInfo.Value]] = Seq.empty[BuildInfo.Value]
def resources =
if (buildInfoStaticCompiled) super.resources
else T.sources { super.resources() ++ Seq(buildInfoResources()) }
def buildInfoResources = T {
val p = new java.util.Properties
for (v <- buildInfoMembers()) p.setProperty(v.key, v.value)
val stream = os.write.outputStream(
T.dest / os.SubPath(
buildInfoPackageName.replace('.', '/')
) / s"$buildInfoObjectName.buildinfo.properties",
createFolders = true
)
p.store(
stream,
s"mill.contrib.buildinfo.BuildInfo for ${buildInfoPackageName}.${buildInfoObjectName}"
)
stream.close()
PathRef(T.dest)
}
private def isScala = this.isInstanceOf[ScalaModule]
override def generatedSources = T {
super.generatedSources() ++ buildInfoSources()
}
def buildInfoSources = T {
if (buildInfoMembers().isEmpty) Nil
else {
val code = if (buildInfoStaticCompiled) BuildInfo.staticCompiledCodegen(
buildInfoMembers(),
isScala,
buildInfoPackageName,
buildInfoObjectName
)
else BuildInfo.codegen(
buildInfoMembers(),
isScala,
buildInfoPackageName,
buildInfoObjectName
)
val ext = if (isScala) "scala" else "java"
os.write(
T.dest / buildInfoPackageName.split('.') / s"${buildInfoObjectName}.$ext",
code,
createFolders = true
)
Seq(PathRef(T.dest))
}
}
}
object BuildInfo {
case class Value(key: String, value: String, comment: String = "")
object Value {
implicit val rw: upickle.default.ReadWriter[Value] = upickle.default.macroRW
}
def staticCompiledCodegen(
buildInfoMembers: Seq[Value],
isScala: Boolean,
buildInfoPackageName: String,
buildInfoObjectName: String
): String = {
val bindingsCode = buildInfoMembers
.sortBy(_.key)
.map {
case v =>
if (isScala) s"""${commentStr(v)}val ${v.key} = ${pprint.Util.literalize(v.value)}"""
else s"""${commentStr(
v
)}public static java.lang.String ${v.key} = ${pprint.Util.literalize(v.value)};"""
}
.mkString("\n\n ")
if (isScala) {
val mapEntries = buildInfoMembers
.map { case v => s""""${v.key}" -> ${v.key}""" }
.mkString(",\n")
s"""
|package $buildInfoPackageName
|
|object $buildInfoObjectName {
| $bindingsCode
| val toMap = Map[String, String](
| $mapEntries
| )
|}
""".stripMargin.trim
} else {
val mapEntries = buildInfoMembers
.map { case v => s"""map.put("${v.key}", ${v.key});""" }
.mkString(",\n")
s"""
|package $buildInfoPackageName;
|
|public class $buildInfoObjectName {
| $bindingsCode
|
| public static java.util.Map<String, String> toMap(){
| Map<String, String> map = new HashMap<String, String>();
| $mapEntries
| return map;
| }
|}
""".stripMargin.trim
}
}
def codegen(
buildInfoMembers: Seq[Value],
isScala: Boolean,
buildInfoPackageName: String,
buildInfoObjectName: String
): String = {
val bindingsCode = buildInfoMembers
.sortBy(_.key)
.map {
case v =>
if (isScala)
s"""${commentStr(v)}val ${v.key} = buildInfoProperties.getProperty("${v.key}")"""
else s"""${commentStr(
v
)}public static final java.lang.String ${v.key} = buildInfoProperties.getProperty("${v.key}");"""
}
.mkString("\n\n ")
if (isScala)
s"""
|package ${buildInfoPackageName}
|
|object $buildInfoObjectName {
| private val buildInfoProperties = new java.util.Properties
|
| private val buildInfoInputStream = getClass
| .getResourceAsStream("$buildInfoObjectName.buildinfo.properties")
|
| buildInfoProperties.load(buildInfoInputStream)
|
| $bindingsCode
|}
""".stripMargin.trim
else
s"""
|package ${buildInfoPackageName};
|
|public class $buildInfoObjectName {
| private static java.util.Properties buildInfoProperties = new java.util.Properties();
|
| static {
| java.io.InputStream buildInfoInputStream = $buildInfoObjectName
| .class
| .getResourceAsStream("$buildInfoObjectName.buildinfo.properties");
|
| try{
| buildInfoProperties.load(buildInfoInputStream);
| }catch(java.io.IOException e){
| throw new RuntimeException(e);
| }finally{
| try{
| buildInfoInputStream.close();
| }catch(java.io.IOException e){
| throw new RuntimeException(e);
| }
| }
| }
|
| $bindingsCode
|}
""".stripMargin.trim
}
def commentStr(v: Value) = {
if (v.comment.isEmpty) ""
else {
val lines = v.comment.linesIterator.toVector
lines.length match {
case 1 => s"""/** ${v.comment} */\n """
case _ => s"""/**\n ${lines.map("* " + _).mkString("\n ")}\n */\n """
}
}
}
}
def commonPomSettings(artifactName: String) = {
PomSettings(
description = artifactName,
organization = Settings.pomOrg,
url = Settings.projectUrl,
licenses = Seq(License.MIT),
versionControl = VersionControl.github(Settings.githubOrg, Settings.githubRepo),
developers = Seq(
Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi"),
Developer("lefou", "Tobias Roeser", "https://github.com/lefou")
)
)
}
trait MillPublishModule extends PublishModule {
override def artifactName = "mill-" + super.artifactName()
def publishVersion = millVersion()
override def publishProperties: Target[Map[String, String]] = super.publishProperties() ++ Map(
"info.releaseNotesURL" -> Settings.changelogUrl
)
def pomSettings = commonPomSettings(artifactName())
override def javacOptions = Seq("-source", "1.8", "-target", "1.8", "-encoding", "UTF-8")
}
trait MillCoursierModule extends CoursierModule {
override def repositoriesTask = T.task {
super.repositoriesTask() ++ Seq(
MavenRepository(
"https://oss.sonatype.org/content/repositories/releases"
)
)
}
override def mapDependencies: Task[coursier.Dependency => coursier.Dependency] = T.task {
super.mapDependencies().andThen { dep =>
forcedVersions.find(t =>
t._1 == dep.module.organization.value && t._2 == dep.module.name.value
).map { forced =>
val newDep = dep.withVersion(forced._3)
T.log.debug(s"Forcing version of ${dep.module} from ${dep.version} to ${newDep.version}")
newDep
}.getOrElse(dep)
}
}
val forcedVersions: Seq[(String, String, String)] = Seq(
("org.apache.ant", "ant", "1.10.12"),
("commons-io", "commons-io", "2.11.0"),
("com.google.code.gson", "gson", "2.10.1"),
("com.google.protobuf", "protobuf-java", "3.21.8"),
("com.google.guava", "guava", "31.1-jre"),
("org.yaml", "snakeyaml", "1.33")
)
}
trait MillMimaConfig extends mima.Mima {
def skipPreviousVersions: T[Seq[String]] = T(Seq.empty[String])
override def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions
override def mimaPreviousArtifacts: T[Agg[Dep]] = T {
Agg.from(
Settings.mimaBaseVersions
.filter(v => !skipPreviousVersions().contains(v))
.map(version =>
ivy"${pomSettings().organization}:${artifactId()}:${version}"
)
)
}
override def mimaExcludeAnnotations: T[Seq[String]] = Seq(
"mill.api.internal",
"mill.api.experimental"
)
override def mimaCheckDirection: Target[CheckDirection] = T { CheckDirection.Backward }
override def mimaBinaryIssueFilters: Target[Seq[ProblemFilter]] = T {
issueFilterByModule.getOrElse(this, Seq())
}
lazy val issueFilterByModule: Map[MillMimaConfig, Seq[ProblemFilter]] = Map()
}
/** A Module compiled with applied Mill-specific compiler plugins: mill-moduledefs. */
trait WithMillCompiler extends ScalaModule {
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg(Deps.millModuledefs)
override def scalacPluginIvyDeps: Target[Agg[Dep]] =
super.scalacPluginIvyDeps() ++ Agg(Deps.millModuledefsPlugin)
}
trait AcyclicConfig extends ScalaModule {
override def scalacPluginIvyDeps: Target[Agg[Dep]] = {
super.scalacPluginIvyDeps() ++ Agg(Deps.acyclic)
}
override def scalacOptions: Target[Seq[String]] =
super.scalacOptions() ++ Seq("-P:acyclic:force", "-P:acyclic:warn")
}
/**
* Some custom scala settings and test convenience
*/
trait MillScalaModule extends ScalaModule with MillCoursierModule { outer =>
def scalaVersion = Deps.scalaVersion
override def scalacOptions = T {
super.scalacOptions() ++ Seq("-deprecation")
}
// Test setup
def testDepPaths = T { upstreamAssemblyClasspath() ++ Seq(compile().classes) ++ resources() }
def testDep = T { (s"com.lihaoyi-${artifactName()}", testDepPaths().map(_.path).mkString("\n")) }
def testArgs: T[Seq[String]] = T { Seq("-Djna.nosys=true") }
def testTransitiveDeps: T[Map[String, String]] = T {
val upstream = T.traverse(outer.moduleDeps ++ outer.compileModuleDeps) {
case m: MillScalaModule => m.testTransitiveDeps.map(Some(_))
case _ => T.task(None)
}().flatten.flatten
val current = Seq(outer.testDep())
upstream.toMap ++ current
}
def testIvyDeps: T[Agg[Dep]] = Agg(Deps.utest)
def testModuleDeps: Seq[JavaModule] =
if (this == main) Seq(main)
else Seq(this, main.test)
def writeLocalTestOverrides = T.task {
for ((k, v) <- testTransitiveDeps()) {
os.write(T.dest / "mill" / "local-test-overrides" / k, v, createFolders = true)
}
Seq(PathRef(T.dest))
}
def runClasspath = super.runClasspath() ++ writeLocalTestOverrides()
trait MillScalaModuleTests extends ScalaModuleTests with MillCoursierModule
with WithMillCompiler with BaseMillTestsModule {
def runClasspath = super.runClasspath() ++ writeLocalTestOverrides()
override def forkArgs = super.forkArgs() ++ outer.testArgs()
override def moduleDeps = outer.testModuleDeps
override def ivyDeps: T[Agg[Dep]] = T { super.ivyDeps() ++ outer.testIvyDeps() }
}
trait Tests extends MillScalaModuleTests
}
trait BaseMillTestsModule extends TestModule {
override def forkArgs = T {
Seq(
s"-DMILL_SCALA_2_13_VERSION=${Deps.scalaVersion}",
s"-DMILL_SCALA_2_12_VERSION=${Deps.workerScalaVersion212}",
s"-DTEST_SCALA_2_13_VERSION=${Deps.testScala213Version}",
s"-DTEST_SCALA_2_12_VERSION=${Deps.testScala212Version}",
s"-DTEST_SCALA_2_11_VERSION=${Deps.testScala211Version}",
s"-DTEST_SCALA_2_10_VERSION=${Deps.testScala210Version}",
s"-DTEST_SCALA_3_0_VERSION=${Deps.testScala30Version}",
s"-DTEST_SCALA_3_1_VERSION=${Deps.testScala31Version}",
s"-DTEST_SCALA_3_2_VERSION=${Deps.testScala32Version}",
s"-DTEST_SCALAJS_VERSION=${Deps.Scalajs_1.scalaJsVersion}",
s"-DTEST_SCALANATIVE_VERSION=${Deps.Scalanative_0_4.scalanativeVersion}",
s"-DTEST_UTEST_VERSION=${Deps.utest.dep.version}"
)
}
override def testFramework = "mill.UTestFramework"
}
/** A MillScalaModule with default set up test module. */
trait MillAutoTestSetup extends MillScalaModule {
// instead of `object test` which can't be overridden, we hand-made a val+class singleton
/** Default tests module. */
val test = new Tests(implicitly)
class Tests(ctx0: mill.define.Ctx) extends mill.Module()(ctx0) with super.MillScalaModuleTests
}
/** Published module which does not contain strictly handled API. */
trait MillInternalModule extends MillScalaModule with MillPublishModule
/** Publishable module which contains strictly handled API. */
trait MillApiModule extends MillScalaModule with MillPublishModule with MillMimaConfig
/** Publishable module with tests. */
trait MillModule extends MillApiModule with MillAutoTestSetup with WithMillCompiler
with AcyclicConfig
object main extends MillModule {
override def moduleDeps = Seq(eval, resolve, client)
override def ivyDeps = Agg(
Deps.windowsAnsi,
Deps.mainargs,
Deps.coursierInterface,
Deps.requests
)
override def compileIvyDeps = Agg(
Deps.scalaReflect(scalaVersion())
)
object api extends MillApiModule with BuildInfo with MillAutoTestSetup {
def buildInfoPackageName = "mill.api"
def buildInfoMembers = Seq(BuildInfo.Value("millVersion", millVersion(), "Mill version."))
override def ivyDeps = Agg(
Deps.osLib,
Deps.upickle,
Deps.pprint,
Deps.fansi,
Deps.sbtTestInterface
)
}
object util extends MillApiModule with MillAutoTestSetup {
override def moduleDeps = Seq(api)
override def ivyDeps = Agg(
Deps.fansi
)
}
object define extends MillModule with BuildInfo {
override def moduleDeps = Seq(api, util)
override def compileIvyDeps = Agg(
Deps.scalaReflect(scalaVersion())
)
override def ivyDeps = Agg(
Deps.millModuledefs,
Deps.millModuledefsPlugin,
Deps.scalametaTrees,
Deps.coursier,
// Necessary so we can share the JNA classes throughout the build process
Deps.jna,
Deps.jnaPlatform,
Deps.jarjarabrams,
Deps.mainargs,
Deps.scalaparse
)
def buildInfoPackageName = "mill"
def buildInfoMembers = Seq(
BuildInfo.Value("scalaVersion", scalaVersion(), "Scala version used to compile mill core."),
BuildInfo.Value(
"workerScalaVersion212",
Deps.workerScalaVersion212,
"Scala 2.12 version used by some workers."
),
BuildInfo.Value("millVersion", millVersion(), "Mill version."),
BuildInfo.Value("millBinPlatform", millBinPlatform(), "Mill binary platform version."),
BuildInfo.Value(
"millEmbeddedDeps",
T.traverse(dev.moduleDeps)(_.publishSelfDependency)()
.map(artifact => s"${artifact.group}:${artifact.id}:${artifact.version}")
.mkString(","),
"Dependency artifacts embedded in mill assembly by default."
),
BuildInfo.Value(
"millScalacPluginDeps",
Deps.millModuledefsString,
"Scalac compiler plugin dependencies to compile the build script."
),
BuildInfo.Value("millDocUrl", Settings.docUrl, "Mill documentation url.")
)
}
object eval extends MillModule {
override def moduleDeps = Seq(define)
}
object resolve extends MillModule {
override def moduleDeps = Seq(define)
}
object client extends MillPublishModule with BuildInfo {
def buildInfoPackageName = "mill.main.client"
def buildInfoMembers = Seq(BuildInfo.Value("millVersion", millVersion(), "Mill version."))
override def ivyDeps = Agg(Deps.junixsocket)
object test extends Tests with TestModule.Junit4 {
override def ivyDeps = Agg(Deps.junitInterface, Deps.lambdaTest)
}
}
object graphviz extends MillModule {
override def moduleDeps = Seq(main, scalalib)
override def ivyDeps = Agg(
Deps.graphvizJava,
Deps.jgraphtCore
)
}
object testkit extends MillInternalModule with MillAutoTestSetup {
def moduleDeps = Seq(eval, util, main)
}
def testModuleDeps = super.testModuleDeps ++ Seq(testkit)
}
object testrunner extends MillModule {
override def moduleDeps = Seq(scalalib.api, main.util)
}
object scalalib extends MillModule {
override def moduleDeps = Seq(main, scalalib.api, testrunner)
override def ivyDeps = Agg(
Deps.scalafmtDynamic
)
override def testIvyDeps = super.testIvyDeps() ++ Agg(Deps.scalaCheck)
override def testTransitiveDeps = T {
super.testTransitiveDeps() ++ Seq(worker.testDep())
}
object backgroundwrapper extends MillPublishModule with MillScalaModule {
override def ivyDeps = Agg(Deps.sbtTestInterface)
}
object api extends MillApiModule with BuildInfo {
override def moduleDeps = Seq(main.api)
def buildInfoPackageName = "mill.scalalib.api"
def buildInfoObjectName = "Versions"
def buildInfoMembers = Seq(
BuildInfo.Value("ammonite", Deps.ammoniteVersion, "Version of Ammonite."),
BuildInfo.Value("zinc", Deps.zinc.dep.version, "Version of Zinc"),
BuildInfo.Value("scalafmtVersion", Deps.scalafmtDynamic.dep.version, "Version of Scalafmt"),
BuildInfo.Value("semanticDBVersion", Deps.semanticDB.dep.version, "SemanticDB version."),
BuildInfo.Value(
"semanticDbJavaVersion",
Deps.semanticDbJava.dep.version,
"Java SemanticDB plugin version."
),
BuildInfo.Value(
"millModuledefsVersion",
Deps.millModuledefsVersion,
"Mill ModuleDefs plugins version."
),
BuildInfo.Value("millCompilerBridgeScalaVersions", bridgeScalaVersions.mkString(",")),
BuildInfo.Value("millCompilerBridgeVersion", bridgeVersion),
BuildInfo.Value("millVersion", millVersion(), "Mill version.")
)
}
object worker extends MillInternalModule with BuildInfo {
override def moduleDeps = Seq(scalalib.api)
override def ivyDeps = Agg(
Deps.zinc,
Deps.log4j2Core
)
def buildInfoPackageName = "mill.scalalib.worker"
def buildInfoObjectName = "Versions"
def buildInfoMembers = Seq(BuildInfo.Value("zinc", Deps.zinc.dep.version, "Version of Zinc."))
}
}
object scalajslib extends MillModule with BuildInfo {
override def moduleDeps = Seq(scalalib, scalajslib.`worker-api`)
override def testTransitiveDeps = T {
super.testTransitiveDeps() ++ Seq(worker("1").testDep())
}
def buildInfoPackageName = "mill.scalajslib"
def buildInfoObjectName = "ScalaJSBuildInfo"
def buildInfoMembers = T {
val resolve = resolveCoursierDependency()
def formatDep(dep: Dep) = {
val d = resolve(dep)
s"${d.module.organization.value}:${d.module.name.value}:${d.version}"
}
Seq(
BuildInfo.Value("scalajsEnvNodejs", formatDep(Deps.Scalajs_1.scalajsEnvNodejs)),
BuildInfo.Value("scalajsEnvJsdomNodejs", formatDep(Deps.Scalajs_1.scalajsEnvJsdomNodejs)),
BuildInfo.Value(
"scalajsEnvExoegoJsdomNodejs",
formatDep(Deps.Scalajs_1.scalajsEnvExoegoJsdomNodejs)
),
BuildInfo.Value("scalajsEnvPhantomJs", formatDep(Deps.Scalajs_1.scalajsEnvPhantomjs)),
BuildInfo.Value("scalajsEnvSelenium", formatDep(Deps.Scalajs_1.scalajsEnvSelenium))
)
}
object `worker-api` extends MillInternalModule {
override def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("1")
class WorkerModule(scalajsWorkerVersion: String) extends MillInternalModule {
def testDepPaths = T { Seq(compile().classes) }
override def moduleDeps = Seq(scalajslib.`worker-api`, main.client, main.api)
override def ivyDeps = Agg(
Deps.Scalajs_1.scalajsLinker,
Deps.Scalajs_1.scalajsSbtTestAdapter,
Deps.Scalajs_1.scalajsEnvNodejs,
Deps.Scalajs_1.scalajsEnvJsdomNodejs,
Deps.Scalajs_1.scalajsEnvExoegoJsdomNodejs,
Deps.Scalajs_1.scalajsEnvPhantomjs,
Deps.Scalajs_1.scalajsEnvSelenium
)
}
}
object contrib extends MillModule {
def contribModules: Seq[ContribModule] = millInternal.modules.collect { case m: ContribModule =>
m
}
trait ContribModule extends MillModule {
def readme = T.source(millSourcePath / "readme.adoc")
}
object testng extends JavaModule with ContribModule {
override def testTransitiveDeps =
super.testTransitiveDeps() ++ Seq(scalalib.testDep(), scalalib.worker.testDep())
// pure Java implementation
override def artifactSuffix: T[String] = ""
override def scalaLibraryIvyDeps: Target[Agg[Dep]] = T { Agg.empty[Dep] }
override def ivyDeps = Agg(Deps.sbtTestInterface)
override def compileIvyDeps = Agg(Deps.testng)
override def runIvyDeps = Agg(Deps.testng)
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(
scalalib
)
override def docJar: T[PathRef] = super[JavaModule].docJar
}
object twirllib extends ContribModule {
override def compileModuleDeps = Seq(scalalib)
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
object playlib extends ContribModule {
override def moduleDeps = Seq(twirllib, playlib.api)
override def compileModuleDeps = Seq(scalalib)
override def testTransitiveDeps =
super.testTransitiveDeps() ++ T.traverse(Deps.play.keys.toSeq)(worker(_).testDep)()
override def testArgs = T {
super.testArgs() ++
Seq(
s"-DTEST_PLAY_VERSION_2_6=${Deps.Play_2_6.playVersion}",
s"-DTEST_PLAY_VERSION_2_7=${Deps.Play_2_7.playVersion}",
s"-DTEST_PLAY_VERSION_2_8=${Deps.Play_2_8.playVersion}"
)
}
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
object api extends MillPublishModule
object worker extends Cross[WorkerModule](Deps.play.keys.toSeq: _*)
class WorkerModule(playBinary: String) extends MillInternalModule {
override def sources = T.sources {
// We want to avoid duplicating code as long as the Play APIs allow.
// But if newer Play versions introduce incompatibilities,
// just remove the shared source dir for that worker and implement directly.
Seq(PathRef(millSourcePath / os.up / "src-shared")) ++ super.sources()
}
override def scalaVersion = Deps.play(playBinary).scalaVersion
override def moduleDeps = Seq(playlib.api)
override def ivyDeps = Agg(
Deps.osLib,
Deps.play(playBinary).routesCompiler
)
}
}
object scalapblib extends ContribModule {
override def compileModuleDeps = Seq(scalalib)
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
object scoverage extends ContribModule {
object api extends MillApiModule {
override def compileModuleDeps = Seq(main.api)
}
override def moduleDeps = Seq(scoverage.api)
override def compileModuleDeps = Seq(scalalib)
override def testTransitiveDeps =
super.testTransitiveDeps() ++ Seq(worker.testDep(), worker2.testDep())
override def testArgs = T {
super.testArgs() ++
Seq(
s"-DMILL_SCOVERAGE_VERSION=${Deps.scalacScoveragePlugin.dep.version}",
s"-DMILL_SCOVERAGE2_VERSION=${Deps.scalacScoverage2Plugin.dep.version}",
s"-DTEST_SCALA_2_12_VERSION=2.12.15" // last supported 2.12 version for Scoverage 1.x
)
}
// So we can test with buildinfo in the classpath
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(
scalalib,
contrib.buildinfo
)
// Worker for Scoverage 1.x
object worker extends MillInternalModule {
override def compileModuleDeps = Seq(main.api)
override def moduleDeps = Seq(scoverage.api)
def testDepPaths = T { Seq(compile().classes) }
override def compileIvyDeps = T {
Agg(
// compile-time only, need to provide the correct scoverage version at runtime
Deps.scalacScoveragePlugin,
// provided by mill runtime
Deps.osLib
)
}
override def scalaVersion: Target[String] = Deps.scalaVersionForScoverageWorker1
}
// Worker for Scoverage 2.0
object worker2 extends MillInternalModule {
override def compileModuleDeps = Seq(main.api)
override def moduleDeps = Seq(scoverage.api)
def testDepPaths = T { Seq(compile().classes) }
override def compileIvyDeps = T {
Agg(
// compile-time only, need to provide the correct scoverage version at runtime
Deps.scalacScoverage2Plugin,
Deps.scalacScoverage2Reporter,
Deps.scalacScoverage2Domain,
Deps.scalacScoverage2Serializer,
// provided by mill runtime
Deps.osLib
)
}