-
-
Notifications
You must be signed in to change notification settings - Fork 360
/
build.sc
1633 lines (1509 loc) · 56 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.0`
import $ivy.`com.github.lolgab::mill-mima_mill0.10:0.0.13`
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
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 docTags: Seq[String] = Seq(
"0.9.6",
"0.9.7",
"0.9.8",
"0.9.9",
"0.9.10",
"0.9.11",
"0.9.12",
"0.10.0",
"0.10.1",
"0.10.2",
"0.10.3",
"0.10.4",
"0.10.5",
"0.10.6",
"0.10.7",
"0.10.8",
"0.10.9",
"0.10.10",
"0.10.11",
"0.11.0-M1",
"0.11.0-M2",
"0.11.0-M3"
)
val mimaBaseVersions: Seq[String] = Seq("0.11.0-M3")
}
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.0"
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 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.10"
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.18"
}
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 = "2.5.6"
val ammonite = ivy"com.lihaoyi:::ammonite:${ammoniteVersion}"
val ammoniteTerminal = ivy"com.lihaoyi::ammonite-terminal:${ammoniteVersion}"
val ammoniteReducedDeps = ammonite.exclude(
// Exclude trees here to force the version of the dependencies we have defined ourselves.
// We use this here instead of a `forceVersion()` on scalametaTrees since it's not
// respected in the POM causing issues for Coursier Mill users.
"org.scalameta" -> "trees_2.13",
// only used when ammonite is run with --bsp, which we don't support
"ch.epfl.scala" -> "bsp4j"
)
val asciidoctorj = ivy"org.asciidoctor:asciidoctorj:2.4.3"
val bloopConfig = ivy"ch.epfl.scala::bloop-config:1.5.5"
// avoid version 2.1.0-RC2 for issue https://github.com/coursier/coursier/issues/2603
val coursier = ivy"io.get-coursier::coursier:2.1.0-RC5"
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.1"
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.7.1"
val log4j2Core = ivy"org.apache.logging.log4j:log4j-core:2.19.0"
val osLib = ivy"com.lihaoyi::os-lib:0.9.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}"
val testng = ivy"org.testng:testng:7.5"
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.6.1"
val scalametaTrees = ivy"org.scalameta::trees:4.7.3"
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.7"
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.3"
// when bumping this, also update SemanticDbJavaModule.scala to use -build-tool:mill
// see https://github.com/sourcegraph/scip-java/pull/527
val semanticDbJava = ivy"com.sourcegraph:semanticdb-java:0.8.10"
val sourcecode = ivy"com.lihaoyi::sourcecode:0.3.0"
val upickle = ivy"com.lihaoyi::upickle:3.0.0-M1"
val utest = ivy"com.lihaoyi::utest:0.8.1"
val windowsAnsi = ivy"io.github.alexarchambault.windows-ansi:windows-ansi:0.0.4"
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-M3"
val fansi = ivy"com.lihaoyi::fansi:0.4.0"
val jarjarabrams = ivy"com.eed3si9n.jarjarabrams::jarjar-abrams-core:1.8.1"
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
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 = 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")
)
)
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")
)
}
trait MillMimaConfig extends mima.Mima {
override def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions
override def mimaPreviousArtifacts =
if (Settings.mimaBaseVersions.isEmpty) T { Agg[Dep]() }
else super.mimaPreviousArtifacts
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")
}
override def ammoniteVersion = Deps.ammonite.dep.version
// Test setup
def testArgs = T { Seq.empty[String] }
def testIvyDeps: T[Agg[Dep]] = Agg(Deps.utest)
def testModuleDeps: Seq[JavaModule] =
if (this == main) Seq(main)
else Seq(this, main.test)
trait MillScalaModuleTests extends ScalaModuleTests with MillCoursierModule
with WithMillCompiler {
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}"
) ++ outer.testArgs()
}
override def moduleDeps = outer.testModuleDeps
override def ivyDeps: T[Agg[Dep]] = T { super.ivyDeps() ++ outer.testIvyDeps() }
override def testFramework = "mill.UTestFramework"
}
trait Tests extends MillScalaModuleTests
}
/** 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(core, client)
override def ivyDeps = Agg(
Deps.windowsAnsi
)
override def compileIvyDeps = Agg(
Deps.scalaReflect(scalaVersion())
)
override def testArgs = Seq(
"-DMILL_VERSION=" + publishVersion()
)
object api extends MillApiModule {
override def ivyDeps = Agg(
Deps.osLib,
Deps.upickle,
Deps.sbtTestInterface
)
}
object util extends MillApiModule with MillAutoTestSetup {
override def moduleDeps = Seq(api)
override def ivyDeps = Agg(
Deps.ammoniteTerminal,
Deps.fansi
)
}
object core extends MillModule {
override def moduleDeps = Seq(api, util)
override def compileIvyDeps = Agg(
Deps.scalaReflect(scalaVersion())
)
override def ivyDeps = Agg(
Deps.millModuledefs,
Deps.millModuledefsPlugin,
Deps.ammoniteReducedDeps,
Deps.scalametaTrees,
Deps.coursier,
// Necessary so we can share the JNA classes throughout the build process
Deps.jna,
Deps.jnaPlatform,
Deps.jarjarabrams
)
override def generatedSources = T {
val dest = T.ctx.dest
writeBuildInfo(
dir = dest,
scalaVersion = scalaVersion(),
millVersion = publishVersion(),
millBinPlatform = millBinPlatform(),
artifacts = T.traverse(dev.moduleDeps)(_.publishSelfDependency)()
)
Seq(PathRef(dest))
}
def writeBuildInfo(
dir: os.Path,
scalaVersion: String,
millVersion: String,
millBinPlatform: String,
artifacts: Seq[Artifact]
) = {
val code =
s"""
|package mill
|
|/** Generated by mill. */
|object BuildInfo {
| /** Scala version used to compile mill core. */
| val scalaVersion = "$scalaVersion"
| /** Scala 2.12 version used by some workers. */
| val workerScalaVersion212 = "${Deps.workerScalaVersion212}"
| /** Mill version. */
| val millVersion = "$millVersion"
| /** Mill binary platform version. */
| val millBinPlatform = "$millBinPlatform"
| /** Dependency artifacts embedded in mill assembly by default. */
| val millEmbeddedDeps = ${artifacts.map(artifact =>
s""""${artifact.group}:${artifact.id}:${artifact.version}""""
)}
| /** Scalac compiler plugin dependencies to compile the build script. */
| val millScalacPluginDeps = Seq(
| "${Deps.millModuledefsString}"
| )
| /** Mill documentation url. */
| val millDocUrl = "${Settings.docUrl}"
|}
""".stripMargin.trim
os.write(dir / "mill" / "BuildInfo.scala", code, createFolders = true)
}
}
object client extends MillPublishModule {
override def ivyDeps = Agg(
Deps.junixsocket
)
def generatedBuildInfo: T[Seq[PathRef]] = T {
val dest = T.dest
val code =
s"""package mill.main.client;
|
|/** Generated by mill. */
|public class BuildInfo {
| /** Mill version. */
| public static String millVersion() { return "${millVersion()}"; }
|}
|""".stripMargin
os.write(dest / "mill" / "main" / "client" / "BuildInfo.java", code, createFolders = true)
Seq(PathRef(dest))
}
override def generatedSources: T[Seq[PathRef]] =
super.generatedSources() ++ generatedBuildInfo()
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
)
override def testArgs = Seq(
"-DMILL_GRAPHVIZ=" + runClasspath().map(_.path).mkString(",")
)
}
object testkit extends MillInternalModule with MillAutoTestSetup {
def moduleDeps = Seq(core, util)
}
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
)
def genTask(m: ScalaModule) = T.task {
Seq(m.jar(), m.sourceJar()) ++
m.runClasspath()
}
override def generatedSources = T {
val dest = T.ctx.dest
val artifacts = T.traverse(dev.moduleDeps)(_.publishSelfDependency)()
os.write(
dest / "Versions.scala",
s"""package mill.scalalib
|
|/**
| * Dependency versions as they where defined at Mill compile time.
| * Generated from mill in build.sc.
| */
|object Versions {
| /** Version of Ammonite. */
| val ammonite = "${Deps.ammonite.dep.version}"
| /** Version of Zinc. */
| val zinc = "${Deps.zinc.dep.version}"
| /** SemanticDB version. */
| val semanticDBVersion = "${Deps.semanticDB.dep.version}"
| /** Java SemanticDB plugin version. */
| val semanticDbJavaVersion = "${Deps.semanticDbJava.dep.version}"
|}
|
|""".stripMargin
)
super.generatedSources() ++ Seq(PathRef(dest))
}
override def testIvyDeps = super.testIvyDeps() ++ Agg(Deps.scalaCheck)
def testArgs = T {
val genIdeaArgs =
// genTask(main.moduledefs)() ++
genTask(main.core)() ++
genTask(main)() ++
genTask(scalalib)() ++
genTask(scalajslib)() ++
genTask(scalanativelib)()
worker.testArgs() ++
main.graphviz.testArgs() ++
Seq(
"-Djna.nosys=true",
"-DMILL_BUILD_LIBRARIES=" + genIdeaArgs.map(_.path).mkString(","),
"-DMILL_SCALA_LIB=" + runClasspath().map(_.path).mkString(","),
s"-DTEST_SCALAFMT_VERSION=${Deps.scalafmtDynamic.dep.version}"
)
}
object backgroundwrapper extends MillPublishModule {
override def ivyDeps = Agg(
Deps.sbtTestInterface
)
def testArgs = T {
Seq(
"-DMILL_BACKGROUNDWRAPPER=" + runClasspath().map(_.path).mkString(",")
)
}
}
object api extends MillApiModule {
override def moduleDeps = Seq(main.api)
}
object worker extends MillInternalModule {
override def moduleDeps = Seq(scalalib.api)
override def ivyDeps = Agg(
Deps.zinc,
Deps.log4j2Core
)
def testArgs = T {
Seq(
"-DMILL_SCALA_WORKER=" + runClasspath().map(_.path).mkString(",")
)
}
override def generatedSources = T {
val dest = T.ctx.dest
val artifacts = T.traverse(dev.moduleDeps)(_.publishSelfDependency)()
os.write(
dest / "Versions.scala",
s"""package mill.scalalib.worker
|
|/**
| * Dependency versions.
| * Generated from mill in build.sc.
| */
|object Versions {
| /** Version of Zinc. */
| val zinc = "${Deps.zinc.dep.version}"
|}
|
|""".stripMargin
)
super.generatedSources() ++ Seq(PathRef(dest))
}
}
}
object scalajslib extends MillModule {
override def moduleDeps = Seq(scalalib, scalajslib.`worker-api`)
override def testArgs = T {
val mapping = Map(
"MILL_SCALAJS_WORKER_1" -> worker("1").compile().classes.path
)
Seq("-Djna.nosys=true") ++
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
(for ((k, v) <- mapping.to(Seq)) yield s"-D$k=$v")
}
def generatedBuildInfo = T {
val dir = T.dest
val resolve = resolveCoursierDependency()
val packageNames = Seq("mill", "scalajslib")
val className = "ScalaJSBuildInfo"
def formatDep(dep: Dep) = {
val d = resolve(dep)
s"${d.module.organization.value}:${d.module.name.value}:${d.version}"
}
val content =
s"""package ${packageNames.mkString(".")}
|/** Generated by mill at built-time. */
|object ${className} {
| object Deps {
| @deprecated("No longer a dependency. To be removed.", since = "mill 0.10.9")
| val jettyWebsocket = "org.eclipse.jetty:jetty-websocket:8.2.0.v20160908"
| @deprecated("No longer a dependency. To be removed.", since = "mill 0.10.9")
| val jettyServer = "org.eclipse.jetty:jetty-server:8.2.0.v20160908"
| @deprecated("No longer a dependency. To be removed.", since = "mill 0.10.9")
| val javaxServlet = "org.eclipse.jetty.orbit:javax.servlet:3.0.0.v201112011016"
| val scalajsEnvNodejs = "${formatDep(Deps.Scalajs_1.scalajsEnvNodejs)}"
| val scalajsEnvJsdomNodejs = "${formatDep(Deps.Scalajs_1.scalajsEnvJsdomNodejs)}"
| val scalajsEnvExoegoJsdomNodejs = "${formatDep(
Deps.Scalajs_1.scalajsEnvExoegoJsdomNodejs
)}"
| val scalajsEnvPhantomJs = "${formatDep(Deps.Scalajs_1.scalajsEnvPhantomjs)}"
| }
|}
|""".stripMargin
os.write(dir / packageNames / s"${className}.scala", content, createFolders = true)
PathRef(dir)
}
override def generatedSources: Target[Seq[PathRef]] = Seq(generatedBuildInfo())
object `worker-api` extends MillInternalModule {
override def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("1")
class WorkerModule(scalajsWorkerVersion: String) extends MillInternalModule {
override def moduleDeps = Seq(scalajslib.`worker-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
)
}
}
object contrib extends MillModule {
object testng extends JavaModule with MillModule {
// 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 testArgs = T {
Seq(
"-DMILL_SCALA_LIB=" + scalalib.runClasspath().map(_.path).mkString(","),
"-DMILL_TESTNG_LIB=" + runClasspath().map(_.path).mkString(",")
) ++ scalalib.worker.testArgs()
}
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(
scalalib
)
override def docJar: T[PathRef] = super[JavaModule].docJar
}
object twirllib extends MillModule {
override def compileModuleDeps = Seq(scalalib)
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
object playlib extends MillModule {
override def moduleDeps = Seq(twirllib, playlib.api)
override def compileModuleDeps = Seq(scalalib)
override def testArgs = T {
val mapping = Map(
"MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_6" -> worker("2.6").assembly().path,
"MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_7" -> worker("2.7").assembly().path,
"MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_8" -> worker("2.8").assembly().path,
"TEST_PLAY_VERSION_2_6" -> Deps.Play_2_6.playVersion,
"TEST_PLAY_VERSION_2_7" -> Deps.Play_2_7.playVersion,
"TEST_PLAY_VERSION_2_8" -> Deps.Play_2_8.playVersion
)
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
(for ((k, v) <- mapping.to(Seq)) yield s"-D$k=$v")
}
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 MillModule {
override def compileModuleDeps = Seq(scalalib)
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
object scoverage extends MillModule {
object api extends MillApiModule {
override def compileModuleDeps = Seq(main.api)
}
override def moduleDeps = Seq(scoverage.api)
override def compileModuleDeps = Seq(scalalib)
override def testArgs = T {
val mapping = Map(
"MILL_SCOVERAGE_REPORT_WORKER" -> worker.compile().classes.path,
"MILL_SCOVERAGE2_REPORT_WORKER" -> worker2.compile().classes.path,
"MILL_SCOVERAGE_VERSION" -> Deps.scalacScoveragePlugin.dep.version,
"MILL_SCOVERAGE2_VERSION" -> Deps.scalacScoverage2Plugin.dep.version,
"TEST_SCALA_2_12_VERSION" -> "2.12.15" // last supported 2.12 version for Scoverage 1.x
)
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
(for ((k, v) <- mapping) yield s"-D$k=$v")
}
// 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)
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)
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
)
}
}
}
object buildinfo extends MillModule {
override def compileModuleDeps = Seq(scalalib)
// why do I need this?
override def testArgs = T {
Seq("-Djna.nosys=true") ++
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs()
}
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
object proguard extends MillModule {
override def compileModuleDeps = Seq(scalalib)
override def testArgs = T {
Seq(
"-DMILL_SCALA_LIB=" + scalalib.runClasspath().map(_.path).mkString(","),
"-DMILL_PROGUARD_LIB=" + runClasspath().map(_.path).mkString(",")
) ++ scalalib.worker.testArgs()
}
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
object flyway extends MillModule {
override def compileModuleDeps = Seq(scalalib)
override def ivyDeps = Agg(Deps.flywayCore)
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
object docker extends MillModule {
override def compileModuleDeps = Seq(scalalib)
override def testArgs = T {
Seq("-Djna.nosys=true") ++
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs()
}
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
object bloop extends MillModule {
override def compileModuleDeps = Seq(scalalib, scalajslib, scalanativelib)
override def ivyDeps = Agg(
Deps.bloopConfig.exclude("*" -> s"jsoniter-scala-core_2.13")
)
override def testArgs = T(scalanativelib.testArgs())
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(
scalalib,
scalajslib,
scalanativelib
)
def generateBuildinfo = T {
os.write(
T.dest / "Versions.scala",
s"""package mill.contrib.bloop
|
|object Versions {
| val bloop = "${Deps.bloopConfig.dep.version}"
|}
|""".stripMargin
)
PathRef(T.dest)
}
override def generatedSources = T {
super.generatedSources() ++ Seq(generateBuildinfo())
}
}
object artifactory extends MillModule {
override def compileModuleDeps = Seq(scalalib)
override def ivyDeps = T { Agg(Deps.requests) }
}
object codeartifact extends MillModule {
override def compileModuleDeps = Seq(scalalib)
override def ivyDeps = T { Agg(Deps.requests) }
}
object versionfile extends MillModule {
override def compileModuleDeps = Seq(scalalib)
}
object bintray extends MillModule {
override def compileModuleDeps = Seq(scalalib)
override def ivyDeps = T { Agg(Deps.requests) }
}
object gitlab extends MillInternalModule with MillAutoTestSetup {
override def compileModuleDeps = Seq(scalalib)
override def ivyDeps = T { Agg(Deps.requests, Deps.osLib) }
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(
scalalib
)
}
object jmh extends MillInternalModule with MillAutoTestSetup with WithMillCompiler {
override def compileModuleDeps = Seq(scalalib)
override def testArgs = T {
Seq(
"-DMILL_SCALA_LIB=" + scalalib.runClasspath().map(_.path).mkString(",")
) ++ scalalib.worker.testArgs()
}
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}
}
object scalanativelib extends MillModule {
override def moduleDeps = Seq(scalalib, scalanativelib.`worker-api`)
override def testArgs = T {
val mapping = Map(
"MILL_SCALANATIVE_WORKER_0_4" -> worker("0.4").compile().classes.path
)
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
(for ((k, v) <- mapping.to(Seq)) yield s"-D$k=$v")
}
object `worker-api` extends MillInternalModule {
override def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("0.4")
class WorkerModule(scalaNativeWorkerVersion: String)
extends MillInternalModule {
override def moduleDeps = Seq(scalanativelib.`worker-api`)
override 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 MillModule {
override def compileModuleDeps = Seq(scalalib)
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ compileModuleDeps
def generatedBuildInfo: T[Seq[PathRef]] = T {
val workerDep = worker.publishSelfDependency()
val code =
s"""// Generated by Mill
|package mill.bsp
|
|/** Build-time information. */
|object BuildInfo {
| /** BSP4j version (BSP Protocol version). */
| val bsp4jVersion = "${Deps.bsp4j.dep.version}"
| /** BSP worker dependency. */
| val millBspWorkerDep = "${workerDep.group}:${workerDep.id}:${workerDep.version}"
|}
|""".stripMargin.trim
os.write(T.dest / "mill" / "bsp" / "BuildInfo.scala", code, createFolders = true)
Seq(PathRef(T.dest))
}
override def generatedSources: T[Seq[PathRef]] =
super.generatedSources() ++ generatedBuildInfo()
override val test = new Test(implicitly)
class Test(ctx0: mill.define.Ctx) extends Tests(ctx0) {
override def forkEnv: Target[Map[String, String]] = T {
// We try to fetch this dependency with coursier in the tests
bsp.worker.publishLocal()()
super.forkEnv()
}
}
object worker extends MillInternalModule {
override def compileModuleDeps = Seq(bsp, scalalib, testrunner)
override def ivyDeps = Agg(
Deps.bsp4j,
Deps.sbtTestInterface
)
def generatedBuildInfo: T[Seq[PathRef]] = T {
val workerDep = worker.publishSelfDependency()
val code =
s"""// Generated by Mill
|package mill.bsp.worker
|
|/** Build-time information. */
|object BuildInfo {
| /** BSP4j version (BSP Protocol version). */
| val bsp4jVersion = "${Deps.bsp4j.dep.version}"
| /** BSP worker dependency. */
| val millBspWorkerVersion = "${workerDep.version}"
|}
|""".stripMargin.trim
os.write(T.dest / "mill" / "bsp" / "worker" / "BuildInfo.scala", code, createFolders = true)
Seq(PathRef(T.dest))
}
override def generatedSources: T[Seq[PathRef]] =
super.generatedSources() ++ generatedBuildInfo()
}
}
val DefaultLocalMillReleasePath =
s"target/mill-release${if (scala.util.Properties.isWin) ".bat" else ""}"
/**
* Build and install Mill locally.
* @param binFile The location where the Mill binary should be installed
* @param ivyRepo The local Ivy repository where Mill modules should be published to
*/
def installLocal(binFile: String = DefaultLocalMillReleasePath, ivyRepo: String = null) =
T.command {
PathRef(installLocalTask(T.task(binFile), ivyRepo)())
}
def installLocalTask(binFile: Task[String], ivyRepo: String = null): Task[os.Path] = {
val modules = build.millInternal.modules.collect { case m: PublishModule => m }
T.task {
T.traverse(modules)(m => m.publishLocal(ivyRepo))()