forked from com-lihaoyi/mill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sc
1700 lines (1494 loc) · 58.2 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::0.4.0`
import $ivy.`com.github.lolgab::mill-mima::0.0.23`
import $ivy.`net.sourceforge.htmlcleaner:htmlcleaner:2.25`
// imports
import com.github.lolgab.mill.mima.{CheckDirection, ProblemFilter, Mima}
import coursier.maven.MavenRepository
import de.tobiasroeser.mill.vcs.version.VcsVersion
import mill._
import mill.api.JarManifest
import mill.eval.Evaluator
import mill.scalalib._
import mill.scalalib.publish._
import mill.util.Jvm
import mill.resolve.SelectMode
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:`
import mill.contrib.buildinfo.BuildInfo
import mill.scalalib.api.Versions
import mill.T
import mill.define.Cross
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://mill-build.com"
// 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")
}
object Deps {
// The Scala version to use
val scalaVersion = "2.13.11"
// 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 {
def 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.8"
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.4"
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 jline = ivy"org.jline:jline:3.21.0"
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.4"
val scalametaVersion = "4.7.8"
val scalametaTrees = ivy"org.scalameta::trees:${scalametaVersion}"
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.10"
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:${scalametaVersion}"
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.9.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.12.18",
/*"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",
"2.13.11"
)
val buildBridgeScalaVersions = if (!buildAllCompilerBridges) Seq() else bridgeScalaVersions
trait MillJavaModule extends JavaModule {
// Test setup
def testDep = T { (s"com.lihaoyi-${artifactId()}", testDepPaths().map(_.path).mkString("\n")) }
// Workaround for Zinc/JNA bug
// https://github.com/sbt/sbt/blame/6718803ee6023ab041b045a6988fafcfae9d15b5/main/src/main/scala/sbt/Main.scala#L130
def testArgs: T[Seq[String]] = T { Seq("-Djna.nosys=true") }
def testDepPaths = T { upstreamAssemblyClasspath() ++ Seq(compile().classes) ++ resources() }
def testTransitiveDeps: T[Map[String, String]] = T {
val upstream = T.traverse(moduleDeps ++ compileModuleDeps) {
case m: MillJavaModule => m.testTransitiveDeps.map(Some(_))
case _ => T.task(None)
}().flatten.flatten
val current = Seq(testDep())
upstream.toMap ++ current
}
def repositoriesTask = T.task {
super.repositoriesTask() ++
Seq(MavenRepository("https://oss.sonatype.org/content/repositories/releases"))
}
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 MillPublishJavaModule extends MillJavaModule with PublishModule {
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")
)
)
}
def artifactName = "mill-" + super.artifactName()
def publishVersion = millVersion()
def publishProperties = super.publishProperties() ++ Map(
"info.releaseNotesURL" -> Settings.changelogUrl
)
def pomSettings = commonPomSettings(artifactName())
def javacOptions = Seq("-source", "1.8", "-target", "1.8", "-encoding", "UTF-8")
}
/**
* Some custom scala settings and test convenience
*/
trait MillScalaModule extends ScalaModule with MillJavaModule { outer =>
def scalaVersion = Deps.scalaVersion
def scalacOptions = super.scalacOptions() ++ Seq("-deprecation", "-P:acyclic:force", "-feature")
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()
def scalacPluginIvyDeps =
super.scalacPluginIvyDeps() ++
Agg(Deps.acyclic) ++
Agg.when(scalaVersion().startsWith("2.13."))(Deps.millModuledefsPlugin)
def mandatoryIvyDeps =
super.mandatoryIvyDeps() ++
Agg.when(scalaVersion().startsWith("2.13."))(Deps.millModuledefs)
/** Default tests module. */
lazy val test: MillScalaTests = new MillScalaTests {}
trait MillScalaTests extends ScalaTests with MillBaseTestsModule {
def runClasspath = super.runClasspath() ++ writeLocalTestOverrides()
def forkArgs = super.forkArgs() ++ outer.testArgs()
def moduleDeps = outer.testModuleDeps
def ivyDeps = super.ivyDeps() ++ outer.testIvyDeps()
}
}
trait MillBaseTestsModule extends MillJavaModule with TestModule {
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}",
s"-DTEST_ZINC_VERSION=${Deps.zinc.dep.version}"
)
}
def testFramework = "mill.UTestFramework"
}
/** Published module which does not contain strictly handled API. */
trait MillPublishScalaModule extends MillScalaModule with MillPublishJavaModule
/** Publishable module which contains strictly handled API. */
trait MillStableScalaModule extends MillPublishScalaModule with Mima {
def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions
def mimaPreviousArtifacts: T[Agg[Dep]] = T {
Agg.from(
Settings.mimaBaseVersions
.filter(v => !skipPreviousVersions().contains(v))
.map(version =>
ivy"${pomSettings().organization}:${artifactId()}:${version}"
)
)
}
def mimaExcludeAnnotations = Seq("mill.api.internal", "mill.api.experimental")
def mimaCheckDirection = CheckDirection.Backward
def skipPreviousVersions: T[Seq[String]] = T(Seq.empty[String])
}
object bridge extends Cross[BridgeModule](buildBridgeScalaVersions)
trait BridgeModule extends MillPublishJavaModule with CrossScalaModule {
def scalaVersion = crossScalaVersion
def publishVersion = bridgeVersion
def artifactName = "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}").map(bindDependency())
},
sources = true
)()
val bridgeJar = grepJar(
resolvedJars,
s"compiler-bridge_${scalaBinaryVersion(scalaVersion())}",
Deps.zinc.dep.version,
true
)
mill.api.IO.unpackZip(bridgeJar.path, os.rel)
Seq(PathRef(T.dest))
}
}
object main extends MillStableScalaModule with BuildInfo {
def moduleDeps = Seq(eval, resolve, client)
def ivyDeps = Agg(
Deps.windowsAnsi,
Deps.mainargs,
Deps.coursierInterface,
Deps.requests
)
def compileIvyDeps = Agg(Deps.scalaReflect(scalaVersion()))
def buildInfoPackageName = "mill.main"
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."
)
)
object api extends MillStableScalaModule with BuildInfo {
def buildInfoPackageName = "mill.api"
def buildInfoMembers = Seq(
BuildInfo.Value("millVersion", millVersion(), "Mill version."),
BuildInfo.Value("millDocUrl", Settings.docUrl, "Mill documentation url.")
)
def ivyDeps = Agg(
Deps.osLib,
Deps.upickle,
Deps.pprint,
Deps.fansi,
Deps.sbtTestInterface
)
}
object util extends MillStableScalaModule {
def moduleDeps = Seq(api, client)
def ivyDeps = Agg(Deps.coursier, Deps.jline)
}
object define extends MillStableScalaModule {
def moduleDeps = Seq(api, util)
def compileIvyDeps = Agg(Deps.scalaReflect(scalaVersion()))
def ivyDeps = Agg(
Deps.millModuledefs,
Deps.scalametaTrees,
// Necessary so we can share the JNA classes throughout the build process
Deps.jna,
Deps.jnaPlatform,
Deps.jarjarabrams,
Deps.mainargs,
Deps.scalaparse
)
}
object eval extends MillStableScalaModule {
def moduleDeps = Seq(define)
}
object resolve extends MillStableScalaModule {
def moduleDeps = Seq(define)
}
object client extends MillPublishJavaModule with BuildInfo {
def buildInfoPackageName = "mill.main.client"
def buildInfoMembers = Seq(BuildInfo.Value("millVersion", millVersion(), "Mill version."))
def ivyDeps = Agg(Deps.junixsocket)
object test extends JavaModuleTests with TestModule.Junit4 {
def ivyDeps = Agg(Deps.junitInterface, Deps.lambdaTest)
}
}
object graphviz extends MillPublishScalaModule {
def moduleDeps = Seq(main, scalalib)
def ivyDeps = Agg(Deps.graphvizJava, Deps.jgraphtCore)
}
object testkit extends MillPublishScalaModule {
def moduleDeps = Seq(eval, util, main)
}
def testModuleDeps = super.testModuleDeps ++ Seq(testkit)
}
object testrunner extends MillPublishScalaModule {
object entrypoint extends MillPublishJavaModule
def moduleDeps = Seq(scalalib.api, main.util, entrypoint)
}
object scalalib extends MillStableScalaModule {
def moduleDeps = Seq(main, scalalib.api, testrunner)
def ivyDeps = Agg(Deps.scalafmtDynamic)
def testIvyDeps = super.testIvyDeps() ++ Agg(Deps.scalaCheck)
def testTransitiveDeps = super.testTransitiveDeps() ++ Seq(worker.testDep())
object backgroundwrapper extends MillPublishJavaModule with MillJavaModule {
def ivyDeps = Agg(Deps.sbtTestInterface)
}
object api extends MillStableScalaModule with BuildInfo {
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 MillPublishScalaModule with BuildInfo {
def moduleDeps = Seq(scalalib.api)
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 MillStableScalaModule with BuildInfo {
def moduleDeps = Seq(scalalib, scalajslib.`worker-api`)
def testTransitiveDeps = 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 MillPublishScalaModule {
def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("1")
trait WorkerModule extends MillPublishScalaModule with Cross.Module[String] {
def scalajsWorkerVersion = crossValue
def millSourcePath: os.Path = super.millSourcePath / scalajsWorkerVersion
def testDepPaths = T { Seq(compile().classes) }
def moduleDeps = Seq(scalajslib.`worker-api`, main.client, main.api)
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 Module {
def contribModules: Seq[ContribModule] =
millInternal.modules.collect { case m: ContribModule => m }
trait ContribModule extends MillPublishScalaModule {
def readme = T.source(millSourcePath / "readme.adoc")
}
object testng extends JavaModule with ContribModule {
def testTransitiveDeps =
super.testTransitiveDeps() ++
Seq(scalalib.testDep(), scalalib.worker.testDep(), testrunner.entrypoint.testDep())
// pure Java implementation
def artifactSuffix: T[String] = ""
def scalaLibraryIvyDeps: T[Agg[Dep]] = T { Agg.empty[Dep] }
def ivyDeps = Agg(Deps.sbtTestInterface)
def compileIvyDeps = Agg(Deps.testng)
def runIvyDeps = Agg(Deps.testng)
def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
def docJar: T[PathRef] = super[JavaModule].docJar
}
object twirllib extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
object playlib extends ContribModule {
def moduleDeps = Seq(twirllib, playlib.api)
def compileModuleDeps = Seq(scalalib)
def testTransitiveDeps =
super.testTransitiveDeps() ++ T.traverse(Deps.play.keys.toSeq)(worker(_).testDep)()
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}"
)
}
def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
object api extends MillPublishJavaModule
object worker extends Cross[WorkerModule](Deps.play.keys.toSeq)
trait WorkerModule extends MillPublishScalaModule with Cross.Module[String] {
def playBinary = crossValue
def millSourcePath: os.Path = super.millSourcePath / playBinary
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()
}
def scalaVersion = Deps.play(playBinary).scalaVersion
def moduleDeps = Seq(playlib.api)
def ivyDeps = Agg(Deps.osLib, Deps.play(playBinary).routesCompiler)
}
}
object scalapblib extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def testModuleDeps = super.testModuleDeps ++ Seq(scalalib)
}
object scoverage extends ContribModule {
object api extends MillPublishScalaModule {
def compileModuleDeps = Seq(main.api)
}
def moduleDeps = Seq(scoverage.api)
def compileModuleDeps = Seq(scalalib)
def testTransitiveDeps =
super.testTransitiveDeps() ++ Seq(worker.testDep(), worker2.testDep())
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
def testModuleDeps =
super.testModuleDeps ++
Seq(scalalib, scalajslib, scalanativelib, contrib.buildinfo)
// Worker for Scoverage 1.x
object worker extends MillPublishScalaModule {
def compileModuleDeps = Seq(main.api)
def moduleDeps = Seq(scoverage.api)
def testDepPaths = T { Seq(compile().classes) }
// compile-time only, need to provide the correct scoverage version at runtime
def compileIvyDeps = Agg(Deps.scalacScoveragePlugin)
def scalaVersion = Deps.scalaVersionForScoverageWorker1
}
// Worker for Scoverage 2.0
object worker2 extends MillPublishScalaModule {
def compileModuleDeps = Seq(main.api)
def moduleDeps = Seq(scoverage.api)
def testDepPaths = T { Seq(compile().classes) }
def compileIvyDeps = T {
Agg(
// compile-time only, need to provide the correct scoverage version at runtime
Deps.scalacScoverage2Plugin,
Deps.scalacScoverage2Reporter,
Deps.scalacScoverage2Domain,
Deps.scalacScoverage2Serializer
)
}
}
}
object buildinfo extends ContribModule {
def compileModuleDeps = Seq(scalalib, scalajslib, scalanativelib)
def testModuleDeps = super.testModuleDeps ++ Seq(scalalib, scalajslib, scalanativelib)
}
object proguard extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def testModuleDeps = super.testModuleDeps ++ Seq(scalalib)
}
object flyway extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def ivyDeps = Agg(Deps.flywayCore)
def testModuleDeps = super.testModuleDeps ++ Seq(scalalib)
}
object docker extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def testModuleDeps = super.testModuleDeps ++ Seq(scalalib)
}
object bloop extends ContribModule with BuildInfo {
def compileModuleDeps = Seq(scalalib, scalajslib, scalanativelib)
def ivyDeps = Agg(Deps.bloopConfig.exclude("*" -> s"jsoniter-scala-core_2.13"))
def testModuleDeps = super.testModuleDeps ++ Seq(
scalalib,
scalajslib,
scalanativelib
)
def buildInfoPackageName = "mill.contrib.bloop"
def buildInfoObjectName = "Versions"
def buildInfoMembers = Seq(BuildInfo.Value("bloop", Deps.bloopConfig.dep.version))
}
object artifactory extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def ivyDeps = Agg(Deps.requests)
}
object codeartifact extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def ivyDeps = Agg(Deps.requests)
}
object versionfile extends ContribModule {
def compileModuleDeps = Seq(scalalib)
}
object bintray extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def ivyDeps = Agg(Deps.requests)
}
object gitlab extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def ivyDeps = Agg(Deps.requests, Deps.osLib)
def testModuleDeps = super.testModuleDeps ++ Seq(scalalib)
}
object jmh extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def testModuleDeps = super.testModuleDeps ++ Seq(scalalib)
}
}
object scalanativelib extends MillStableScalaModule {
def moduleDeps = Seq(scalalib, scalanativelib.`worker-api`)
def testTransitiveDeps = super.testTransitiveDeps() ++ Seq(worker("0.4").testDep())
object `worker-api` extends MillPublishScalaModule {
def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("0.4")
trait WorkerModule extends MillPublishScalaModule with Cross.Module[String] {
def scalaNativeWorkerVersion = crossValue
def millSourcePath: os.Path = super.millSourcePath / scalaNativeWorkerVersion
def testDepPaths = T { Seq(compile().classes) }
def moduleDeps = Seq(scalanativelib.`worker-api`)
def ivyDeps = scalaNativeWorkerVersion match {
case "0.4" =>
Agg(
Deps.osLib,
Deps.Scalanative_0_4.scalanativeTools,
Deps.Scalanative_0_4.scalanativeUtil,
Deps.Scalanative_0_4.scalanativeNir,
Deps.Scalanative_0_4.scalanativeTestRunner
)
}
}
}
object bsp extends MillPublishScalaModule with BuildInfo {
def compileModuleDeps = Seq(scalalib)
def testModuleDeps = super.testModuleDeps ++ compileModuleDeps
def buildInfoPackageName = "mill.bsp"
def buildInfoMembers = T {
val workerDep = worker.publishSelfDependency()
Seq(
BuildInfo.Value(
"bsp4jVersion",
Deps.bsp4j.dep.version,
"BSP4j version (BSP Protocol version)."
)
)
}
override lazy val test: MillScalaTests = new Test {}
trait Test extends MillScalaTests {
def forkEnv: T[Map[String, String]] = T {
// We try to fetch this dependency with coursier in the tests
bsp.worker.publishLocal()()
super.forkEnv()
}
def forkArgs = super.forkArgs() ++ Seq(s"-DBSP4J_VERSION=${Deps.bsp4j.dep.version}")
}
object worker extends MillPublishScalaModule {
def compileModuleDeps = Seq(bsp, scalalib, testrunner, runner)
def ivyDeps = Agg(Deps.bsp4j, Deps.sbtTestInterface)
}
}
val DefaultLocalMillReleasePath =
s"target/mill-release${if (scala.util.Properties.isWin) ".bat" else ""}"
// We compile the test code once and then offer multiple modes to
// test it in the `test` CrossModule. We pass `test`'s sources to `lib` to
// and pass `lib`'s compile output back to `test`
trait IntegrationTestModule extends MillScalaModule {
def repoSlug: String
def scalaVersion = integration.scalaVersion()
def moduleDeps = Seq(main.test, integration)
def sources = T.sources(millSourcePath / "test" / "src")
def testRepoRoot: T[PathRef] = T.source(millSourcePath / "repo")
trait ModeModule extends ScalaModule with MillBaseTestsModule {
def mode: String = millModuleSegments.parts.last
def scalaVersion = integration.scalaVersion()
def forkEnv =
super.forkEnv() ++
IntegrationTestModule.this.forkEnv() ++
Map(
"MILL_INTEGRATION_TEST_MODE" -> mode,
"MILL_INTEGRATION_TEST_SLUG" -> repoSlug,
"MILL_INTEGRATION_REPO_ROOT" -> testRepoRoot().path.toString
) ++
testReleaseEnv()
def workspaceDir = T.persistent { PathRef(T.dest) }
def forkArgs = T {
super.forkArgs() ++
dev.forkArgs() ++
Seq(s"-DMILL_WORKSPACE_PATH=${workspaceDir().path}")
}
def testReleaseEnv =
if (mode == "local") T { Map("MILL_TEST_LAUNCHER" -> dev.launcher().path.toString()) }
else T { Map("MILL_TEST_LAUNCHER" -> integration.testMill().path.toString()) }
def compile = IntegrationTestModule.this.compile()
def moduleDeps = Seq(IntegrationTestModule.this)
}
}
trait IntegrationTestCrossModule extends IntegrationTestModule with Cross.Module[String] {
def repoSlug = crossValue
def millSourcePath = super.millSourcePath / repoSlug
object local extends ModeModule
object fork extends ModeModule
object server extends ModeModule
}
def listIn(path: os.Path) = interp.watchValue(os.list(path).map(_.last))
object example extends MillScalaModule {
def exampleModules: Seq[ExampleCrossModule] =
millInternal.modules.collect { case m: ExampleCrossModule => m }
def moduleDeps = Seq(integration)
object basic extends Cross[ExampleCrossModule](listIn(millSourcePath / "basic"))
object scalabuilds extends Cross[ExampleCrossModule](listIn(millSourcePath / "scalabuilds"))
object scalamodule extends Cross[ExampleCrossModule](listIn(millSourcePath / "scalamodule"))
object tasks extends Cross[ExampleCrossModule](listIn(millSourcePath / "tasks"))
object cross extends Cross[ExampleCrossModule](listIn(millSourcePath / "cross"))
object misc extends Cross[ExampleCrossModule](listIn(millSourcePath / "misc"))
object web extends Cross[ExampleCrossModule](listIn(millSourcePath / "web"))
trait ExampleCrossModule extends IntegrationTestCrossModule {
def testRepoRoot: T[PathRef] = T.source(millSourcePath)
def compile = example.compile()
def forkEnv = super.forkEnv() ++ Map("MILL_EXAMPLE_PARSED" -> upickle.default.write(parsed()))
def parsed = T {
val states = collection.mutable.Buffer("scala")
val chunks = collection.mutable.Buffer(collection.mutable.Buffer.empty[String])
for (line <- os.read.lines(testRepoRoot().path / "build.sc")) {
val (newState, restOpt) = line match {
case s"/** Usage" => ("example", None)
case s"/** See Also: $path */" =>
(s"see:$path", Some(os.read(os.Path(path, testRepoRoot().path))))
case s"*/" => ("scala", None)
case s"//$rest" => ("comment", Some(rest.stripPrefix(" ")))
case l => (if (states.last == "comment") "scala" else states.last, Some(l))
}
if (newState != states.last) {
states.append(newState)
chunks.append(collection.mutable.Buffer.empty[String])
}
restOpt.foreach(r => chunks.last.append(r))
}
states.zip(chunks.map(_.mkString("\n").trim)).filter(_._2.nonEmpty)
}
def rendered = T {
var seenCode = false
val examplePath = millSourcePath.subRelativeTo(T.workspace)
os.write(
T.dest / "example.adoc",
parsed()
.filter(_._2.nonEmpty)
.map {
case (s"see:$path", txt) =>
s"""
|.$path ({mill-example-url}/$examplePath/$path[browse])
|[source,scala,subs="attributes,verbatim"]
|----
|$txt
|----""".stripMargin
case ("scala", txt) =>
val title =
if (seenCode) ""
else {
val label = millVersion()
val exampleDashed = examplePath.segments.mkString("-")
val download = s"{mill-download-url}/$label-$exampleDashed.zip[download]"
val browse = s"{mill-example-url}/$examplePath[browse]"
s".build.sc ($download, $browse)"
}
seenCode = true
s"""
|$title
|[source,scala,subs="attributes,verbatim"]
|----
|
|$txt
|----
|""".stripMargin
case ("comment", txt) => txt
case ("example", txt) =>
s"""