forked from com-lihaoyi/mill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sc
executable file
·1321 lines (1219 loc) · 42.5 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
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.1.2-4-dcde72`
import $ivy.`com.github.lolgab::mill-mima::0.0.6`
import $ivy.`net.sourceforge.htmlcleaner:htmlcleaner:2.24`
import java.nio.file.attribute.PosixFilePermission
import com.github.lolgab.mill.mima
import com.github.lolgab.mill.mima.ProblemFilter
import com.typesafe.tools.mima.core.{DirectMissingMethodProblem, IncompatibleSignatureProblem}
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 os.RelPath
object Settings {
val pomOrg = "com.lihaoyi"
val githubOrg = "com-lihaoyi"
val githubRepo = "mill"
val projectUrl = s"https://github.com/${githubOrg}/${githubRepo}"
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(
"0.9.6",
"0.9.7",
"0.9.8",
"0.9.9",
"0.9.10",
"0.9.11",
"0.10.0-M2",
"0.10.0-M3",
"0.10.0-M4"
)
val mimaBaseVersions = Seq("0.10.0-M4")
}
object Deps {
// The Scala version to use
val scalaVersion = "2.13.7"
// The Scala 2.12.x version to use for some workers
val workerScalaVersion212 = "2.12.13"
object Scalajs_0_6 {
val scalajsJsEnvs = ivy"org.scala-js::scalajs-js-envs:0.6.33"
val scalajsSbtTestAdapter = ivy"org.scala-js::scalajs-sbt-test-adapter:0.6.33"
val scalajsTools = ivy"org.scala-js::scalajs-tools:0.6.33"
}
object Scalajs_1 {
val scalajsEnvJsdomNodejs = ivy"org.scala-js::scalajs-env-jsdom-nodejs:1.1.0"
val scalajsEnvNodejs = ivy"org.scala-js::scalajs-env-nodejs:1.2.0"
val scalajsEnvPhantomjs = ivy"org.scala-js::scalajs-env-phantomjs:1.0.0"
val scalajsSbtTestAdapter = ivy"org.scala-js::scalajs-sbt-test-adapter:1.7.1"
val scalajsLinker = ivy"org.scala-js::scalajs-linker:1.7.1"
}
object Scalanative_0_4 {
val scalanativeTools = ivy"org.scala-native::tools:0.4.0"
val scalanativeUtil = ivy"org.scala-native::util:0.4.0"
val scalanativeNir = ivy"org.scala-native::nir:0.4.0"
val scalanativeTestRunner = ivy"org.scala-native::test-runner:0.4.0"
}
val acyclic = ivy"com.lihaoyi::acyclic:0.2.0"
val ammonite = ivy"com.lihaoyi:::ammonite:2.5.0"
val ammoniteTerminal = ivy"com.lihaoyi::ammonite-terminal:2.5.0"
// Exclude trees here to force the version of we have defined. We use this
// here instead of a `forceVersion()` on scalametaTrees since it's not
// respected in the POM causing issues for Coursier Mill users.
val ammoniteExcludingTrees = ammonite.exclude(
"org.scalameta" -> "trees_2.13"
)
val asciidoctorj = ivy"org.asciidoctor:asciidoctorj:2.4.3"
val bloopConfig = ivy"ch.epfl.scala::bloop-config:1.4.11"
val coursier = ivy"io.get-coursier::coursier:2.0.16-200-ge888c6dea"
val coursierReducedDeps = coursier.exclude(
"com.lihaoyi" -> "utest",
"org.codehaus.plexus" -> "*"
)
val flywayCore = ivy"org.flywaydb:flyway-core:8.0.2"
val graphvizJava = ivy"guru.nidi:graphviz-java:0.18.1"
// Warning: Avoid ipcsocket version 1.3.0, as it caused many failures on CI
val ipcsocket = ivy"org.scala-sbt.ipcsocket:ipcsocket:1.0.1"
val ipcsocketExcludingJna = ipcsocket.exclude(
"net.java.dev.jna" -> "jna",
"net.java.dev.jna" -> "jna-platform"
)
object jetty {
val version = "8.2.0.v20160908"
val server = ivy"org.eclipse.jetty:jetty-server:${version}"
val websocket = ivy"org.eclipse.jetty:jetty-websocket:${version}"
}
val javaxServlet = ivy"org.eclipse.jetty.orbit:javax.servlet:3.0.0.v201112011016"
val jgraphtCore = ivy"org.jgrapht:jgrapht-core:1.5.1"
val jna = ivy"net.java.dev.jna:jna:5.10.0"
val jnaPlatform = ivy"net.java.dev.jna:jna-platform:5.10.0"
val junitInterface = ivy"com.github.sbt:junit-interface:0.13.2"
val lambdaTest = ivy"de.tototec:de.tobiasroeser.lambdatest:0.7.1"
val log4j2Core = ivy"org.apache.logging.log4j:log4j-core:2.16.0"
val osLib = ivy"com.lihaoyi::os-lib:0.8.0"
val testng = ivy"org.testng:testng:7.4.0"
val sbtTestInterface = ivy"org.scala-sbt:test-interface:1.0"
val scalaCheck = ivy"org.scalacheck::scalacheck:1.15.4"
def scalaCompiler(scalaVersion: String) = ivy"org.scala-lang:scala-compiler:${scalaVersion}"
val scalafmtDynamic = ivy"org.scalameta::scalafmt-dynamic:3.0.8"
val scalametaTrees = ivy"org.scalameta::trees:4.4.31"
def scalaReflect(scalaVersion: String) = ivy"org.scala-lang:scala-reflect:${scalaVersion}"
def scalacScoveragePlugin = ivy"org.scoverage:::scalac-scoverage-plugin:1.4.10"
val sourcecode = ivy"com.lihaoyi::sourcecode:0.2.7"
val upickle = ivy"com.lihaoyi::upickle:1.4.3"
val utest = ivy"com.lihaoyi::utest:0.7.10"
val windowsAnsi = ivy"io.github.alexarchambault.windows-ansi:windows-ansi:0.0.3"
val zinc = ivy"org.scala-sbt::zinc:1.5.9"
val bsp = ivy"ch.epfl.scala:bsp4j:2.0.0"
val fansi = ivy"com.lihaoyi::fansi:0.3.0"
val jarjarabrams = ivy"com.eed3si9n.jarjarabrams::jarjar-abrams-core:1.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()
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"
)
)
}
}
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 mimaBinaryIssueFilters: Target[Seq[ProblemFilter]] = T {
issueFilterByModule.getOrElse(this, Seq())
}
lazy val issueFilterByModule: Map[MillMimaConfig, Seq[ProblemFilter]] = Map(
main.api -> Seq(
ProblemFilter.exclude[IncompatibleSignatureProblem]("mill.api.Ctx.args"),
ProblemFilter.exclude[IncompatibleSignatureProblem]("mill.api.Ctx.this"),
ProblemFilter.exclude[IncompatibleSignatureProblem]("mill.api.Ctx#Args.args")
),
main.core -> Seq(
ProblemFilter.exclude[IncompatibleSignatureProblem]("mill.define.Target.makeT"),
ProblemFilter.exclude[IncompatibleSignatureProblem]("mill.define.Target.args"),
ProblemFilter.exclude[IncompatibleSignatureProblem]("mill.define.ParseArgs.standaloneIdent"),
ProblemFilter.exclude[IncompatibleSignatureProblem](
"mill.define.ParseArgs#BraceExpansionParser.plainChars"
),
ProblemFilter.exclude[IncompatibleSignatureProblem](
"mill.define.ParseArgs#BraceExpansionParser.braceParser"
),
ProblemFilter.exclude[IncompatibleSignatureProblem](
"mill.define.ParseArgs#BraceExpansionParser.parser"
),
ProblemFilter.exclude[IncompatibleSignatureProblem](
"mill.define.ParseArgs#BraceExpansionParser.toExpand"
),
ProblemFilter.exclude[IncompatibleSignatureProblem]("mill.eval.EvaluatorPaths.*"),
ProblemFilter.exclude[DirectMissingMethodProblem]("mill.eval.EvaluatorPaths.*")
)
)
}
trait MillApiModule
extends MillPublishModule
with ScalaModule
with MillCoursierModule
with MillMimaConfig {
def scalaVersion = Deps.scalaVersion
override def ammoniteVersion = Deps.ammonite.dep.version
}
trait MillModule extends MillApiModule { outer =>
override def scalacPluginClasspath =
super.scalacPluginClasspath() ++ Seq(main.moduledefs.jar())
def testArgs = T { Seq.empty[String] }
def testIvyDeps: T[Agg[Dep]] = Agg(Deps.utest)
val test = new Tests(implicitly)
class Tests(ctx0: mill.define.Ctx) extends mill.Module()(ctx0) with super.Tests {
override def forkArgs = T { testArgs() }
override def moduleDeps =
if (this == main.test) Seq(main)
else Seq(outer, main.test)
override def ivyDeps: T[Agg[Dep]] = outer.testIvyDeps()
override def testFramework = "mill.UTestFramework"
override def scalacPluginClasspath =
super.scalacPluginClasspath() ++ Seq(main.moduledefs.jar())
}
}
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()
)
override val test = new Tests(implicitly)
class Tests(ctx0: mill.define.Ctx) extends super.Tests(ctx0) {
}
object api extends MillApiModule {
override def ivyDeps = Agg(
Deps.osLib,
Deps.upickle,
Deps.sbtTestInterface
)
}
object util extends MillApiModule {
override def moduleDeps = Seq(api)
def ivyDeps = Agg(
Deps.ammoniteTerminal,
Deps.fansi
)
}
object core extends MillModule {
override def moduleDeps = Seq(moduledefs, api, util)
override def compileIvyDeps = Agg(
Deps.scalaReflect(scalaVersion())
)
override def ivyDeps = Agg(
Deps.ammoniteExcludingTrees,
Deps.scalametaTrees,
Deps.coursierReducedDeps,
// 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
|
|object BuildInfo {
| /** Scala version used to compile mill core. */
| val scalaVersion = "$scalaVersion"
| /** 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}""""
)}
|}
""".stripMargin.trim
os.write(dir / "mill" / "BuildInfo.scala", code, createFolders = true)
}
}
object moduledefs extends MillPublishModule with ScalaModule {
def scalaVersion = Deps.scalaVersion
override def ivyDeps = Agg(
Deps.scalaCompiler(scalaVersion()),
Deps.sourcecode
)
}
object client extends MillPublishModule {
override def ivyDeps = Agg(
Deps.ipcsocketExcludingJna
)
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 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.
| * 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}"
|}
|
|""".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(",")
)
}
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 MillApiModule {
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.api)
override def testArgs = T {
val mapping = Map(
"MILL_SCALAJS_WORKER_0_6" -> worker("0.6").compile().classes.path,
"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 {
| val jettyWebsocket = "${formatDep(Deps.jetty.websocket)}"
| val jettyServer = "${formatDep(Deps.jetty.server)}"
| val javaxServlet = "${formatDep(Deps.javaxServlet)}"
| val scalajsEnvNodejs = "${formatDep(Deps.Scalajs_1.scalajsEnvNodejs)}"
| val scalajsEnvJsdomNodejs = "${formatDep(Deps.Scalajs_1.scalajsEnvJsdomNodejs)}"
| 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 api extends MillApiModule {
override def moduleDeps = Seq(main.api)
override def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("0.6", "1")
class WorkerModule(scalajsWorkerVersion: String) extends MillApiModule {
override def moduleDeps = Seq(scalajslib.api)
override def ivyDeps = scalajsWorkerVersion match {
case "0.6" =>
Agg(
Deps.Scalajs_0_6.scalajsTools,
Deps.Scalajs_0_6.scalajsSbtTestAdapter,
Deps.Scalajs_0_6.scalajsJsEnvs,
Deps.jetty.websocket,
Deps.jetty.server,
Deps.javaxServlet
)
case "1" =>
Agg(
Deps.Scalajs_1.scalajsLinker,
Deps.Scalajs_1.scalajsSbtTestAdapter,
Deps.Scalajs_1.scalajsEnvNodejs,
Deps.Scalajs_1.scalajsEnvJsdomNodejs,
Deps.Scalajs_1.scalajsEnvPhantomjs,
Deps.jetty.websocket,
Deps.jetty.server,
Deps.javaxServlet
)
}
}
}
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,
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 docJar: T[PathRef] = super[JavaModule].docJar
override val test = new Tests(implicitly)
class Tests(ctx0: mill.define.Ctx) extends super.Tests(ctx0) {
override def compileModuleDeps = Seq(scalalib)
}
}
object twirllib extends MillModule {
override def compileModuleDeps = 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
)
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
(for ((k, v) <- mapping.to(Seq)) yield s"-D$k=$v")
}
object api extends MillPublishModule
object worker extends Cross[WorkerModule]("2.6", "2.7", "2.8")
class WorkerModule(playBinary: String) extends MillApiModule {
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 = playBinary match {
case "2.6" => Deps.workerScalaVersion212
case _ => Deps.scalaVersion
}
override def moduleDeps = Seq(playlib.api)
def playVersion = playBinary match {
case "2.6" => "2.6.25"
case "2.7" => "2.7.9"
case "2.8" => "2.8.8"
}
override def ivyDeps = Agg(
Deps.osLib,
ivy"com.typesafe.play::routes-compiler::$playVersion"
)
}
}
object scalapblib extends MillModule {
override def compileModuleDeps = 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
)
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 val test = new Tests(implicitly)
class Tests(ctx0: mill.define.Ctx) extends super.Tests(ctx0) {
override def moduleDeps = super.moduleDeps :+ contrib.buildinfo
}
object worker extends MillApiModule {
override def moduleDeps = Seq(scoverage.api)
override def compileIvyDeps = T {
Agg(
// compile-time only, need to provide the correct scoverage version runtime
Deps.scalacScoveragePlugin,
// 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()
}
}
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()
}
}
object flyway extends MillModule {
override def compileModuleDeps = Seq(scalalib)
override def ivyDeps = Agg(Deps.flywayCore)
}
object docker extends MillModule {
override def compileModuleDeps = Seq(scalalib)
override def testArgs = T {
Seq("-Djna.nosys=true") ++
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs()
}
}
object bloop extends MillModule {
override def compileModuleDeps = Seq(scalalib, scalajslib, scalanativelib)
override def ivyDeps = Agg(
Deps.bloopConfig
)
override def testArgs = T(scalanativelib.testArgs())
override def generatedSources = T {
val dest = T.ctx.dest
val artifacts = T.traverse(dev.moduleDeps)(_.publishSelfDependency)()
os.write(
dest / "Versions.scala",
s"""package mill.contrib.bloop
|
|object Versions {
| val bloop = "${Deps.bloopConfig.dep.version}"
|}
|""".stripMargin
)
super.generatedSources() ++ Seq(PathRef(dest))
}
}
object artifactory extends MillModule {
override def compileModuleDeps = Seq(scalalib)
}
object codeartifact extends MillModule {
override def compileModuleDeps = Seq(scalalib)
}
object versionfile extends MillModule {
override def compileModuleDeps = Seq(scalalib)
}
object bintray extends MillModule {
override def compileModuleDeps = Seq(scalalib)
}
}
object scalanativelib extends MillModule {
override def moduleDeps = Seq(scalalib, scalanativelib.api)
override def testArgs = T {
val mapping = Map(
"MILL_SCALANATIVE_WORKER_0_4" -> worker("0.4").assembly().path
)
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
(for ((k, v) <- mapping.to(Seq)) yield s"-D$k=$v")
}
object api extends MillPublishModule {
override def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("0.4")
class WorkerModule(scalaNativeWorkerVersion: String) extends MillApiModule {
override def scalaVersion = Deps.workerScalaVersion212
override def moduleDeps = Seq(scalanativelib.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, scalajslib, scalanativelib, testrunner)
override def ivyDeps = Agg(
Deps.bsp,
Deps.sbtTestInterface
)
}
def testRepos = T {
Seq(
"MILL_ACYCLIC_REPO" ->
shared.downloadTestRepo(
"lihaoyi/acyclic",
"bc41cd09a287e2c270271e27ccdb3066173a8598",
T.ctx.dest / "acyclic"
),
"MILL_JAWN_REPO" ->
shared.downloadTestRepo(
"non/jawn",
"fd8dc2b41ce70269889320aeabf8614fe1e8fbcb",
T.ctx.dest / "jawn"
),
"MILL_BETTERFILES_REPO" ->
shared.downloadTestRepo(
"pathikrit/better-files",
"ba74ae9ef784dcf37f1b22c3990037a4fcc6b5f8",
T.ctx.dest / "better-files"
),
"MILL_AMMONITE_REPO" ->
shared.downloadTestRepo(
"lihaoyi/ammonite",
"26b7ebcace16b4b5b4b68f9344ea6f6f48d9b53e",
T.ctx.dest / "ammonite"
),
"MILL_UPICKLE_REPO" ->
shared.downloadTestRepo(
"lihaoyi/upickle",
"7f33085c890db7550a226c349832eabc3cd18769",
T.ctx.dest / "upickle"
),
"MILL_PLAY_JSON_REPO" ->
shared.downloadTestRepo(
"playframework/play-json",
"0a5ba16a03f3b343ac335117eb314e7713366fd4",
T.ctx.dest / "play-json"
),
"MILL_CAFFEINE_REPO" ->
shared.downloadTestRepo(
"ben-manes/caffeine",
"c02c623aedded8174030596989769c2fecb82fe4",
T.ctx.dest / "caffeine"
)
)
}
object integration extends MillModule {
override def moduleDeps = Seq(main.moduledefs, scalalib, scalajslib, scalanativelib)
override def testArgs = T {
scalajslib.testArgs() ++
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
scalanativelib.testArgs() ++
Seq(
"-DMILL_TESTNG=" + contrib.testng.runClasspath().map(_.path).mkString(","),
"-DMILL_VERSION=" + publishVersion(),
"-DMILL_SCALA_LIB=" + scalalib.runClasspath().map(_.path).mkString(","),
"-Djna.nosys=true"
) ++
(for ((k, v) <- testRepos()) yield s"-D$k=$v")
}
override def forkArgs = testArgs()
}
def launcherScript(
shellJvmArgs: Seq[String],
cmdJvmArgs: Seq[String],
shellClassPath: Agg[String],
cmdClassPath: Agg[String]
) = {
val millMainClass = "mill.MillMain"
val millClientMainClass = "mill.main.client.MillClientMain"
mill.modules.Jvm.universalScript(
shellCommands = {
val jvmArgsStr = shellJvmArgs.mkString(" ")
def java(mainClass: String, passMillJvmOpts: Boolean) = {
val millJvmOpts = if (passMillJvmOpts) "$mill_jvm_opts" else ""
s"""exec "$$JAVACMD" $jvmArgsStr $$JAVA_OPTS $millJvmOpts -cp "${shellClassPath.mkString(
":"
)}" $mainClass "$$@""""
}
s"""if [ -z "$$JAVA_HOME" ] ; then
| JAVACMD="java"
|else
| JAVACMD="$$JAVA_HOME/bin/java"
|fi
|
|mill_jvm_opts=""
|init_mill_jvm_opts () {
| if [ -z $$MILL_JVM_OPTS_PATH ] ; then
| mill_jvm_opts_file=".mill-jvm-opts"
| else
| mill_jvm_opts_file=$$MILL_JVM_OPTS_PATH
| fi
|
| if [ -f "$$mill_jvm_opts_file" ] ; then
| while IFS= read line
| do
| case $$line in
| "-X"*) mill_jvm_opts="$${mill_jvm_opts} $$line"
| esac
| done <"$$mill_jvm_opts_file"
| fi
|}
|
|# Client-server mode doesn't seem to work on WSL, just disable it for now
|# https://stackoverflow.com/a/43618657/871202
|if grep -qEi "(Microsoft|WSL)" /proc/version > /dev/null 2> /dev/null ; then
| init_mill_jvm_opts
| if [ -z $$COURSIER_CACHE ] ; then
| COURSIER_CACHE=.coursier
| fi
| ${java(millMainClass, true)}
|else
| case "$$1" in
| -i | --interactive | --repl | --no-server | --bsp )
| init_mill_jvm_opts
| ${java(millMainClass, true)}
| ;;
| *)
| ${java(millClientMainClass, false)}
| ;;
|esac
|fi
|""".stripMargin
},
cmdCommands = {
val jvmArgsStr = cmdJvmArgs.mkString(" ")
def java(mainClass: String, passMillJvmOpts: Boolean) = {
val millJvmOpts = if (passMillJvmOpts) "!mill_jvm_opts!" else ""
s""""%JAVACMD%" $jvmArgsStr %JAVA_OPTS% $millJvmOpts -cp "${cmdClassPath.mkString(
";"
)}" $mainClass %*"""
}
s"""setlocal EnableDelayedExpansion
|set "JAVACMD=java.exe"
|if not "%JAVA_HOME%"=="" set "JAVACMD=%JAVA_HOME%\\bin\\java.exe"
|if "%1" == "-i" set _I_=true
|if "%1" == "--interactive" set _I_=true
|if "%1" == "--repl" set _I_=true
|if "%1" == "--no-server" set _I_=true
|if "%1" == "--bsp" set _I_=true
|
|set "mill_jvm_opts="
|set "mill_jvm_opts_file=.mill-jvm-opts"
|if not "%MILL_JVM_OPTS_PATH%"=="" set "mill_jvm_opts_file=%MILL_JVM_OPTS_PATH%"
|
|if defined _I_ (
| if exist %mill_jvm_opts_file% (
| for /f "delims=" %%G in (%mill_jvm_opts_file%) do (
| set line=%%G
| if "!line:~0,2!"=="-X" set "mill_jvm_opts=!mill_jvm_opts! !line!"
| )
| )
| ${java(millMainClass, true)}
|) else (
| ${java(millClientMainClass, false)}
|)
|endlocal
|""".stripMargin
}
)
}
object dev extends MillModule {
override def moduleDeps = Seq(scalalib, scalajslib, scalanativelib, bsp)
def forkArgs: T[Seq[String]] =
(
scalalib.testArgs() ++
scalajslib.testArgs() ++
scalalib.worker.testArgs() ++
scalanativelib.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
// Workaround for Zinc/JNA bug
// https://github.com/sbt/sbt/blame/6718803ee6023ab041b045a6988fafcfae9d15b5/main/src/main/scala/sbt/Main.scala#L130
Seq(
"-Djna.nosys=true",
"-DMILL_VERSION=" + publishVersion(),
"-DMILL_CLASSPATH=" + runClasspath().map(_.path.toString).mkString(",")
)
).distinct
override def launcher = T {
val isWin = scala.util.Properties.isWin
val outputPath = T.ctx.dest / (if (isWin) "run.bat" else "run")
os.write(outputPath, prependShellScript())
if (!isWin) {
os.perms.set(outputPath, "rwxrwxrwx")
}
PathRef(outputPath)
}
override def extraPublish: T[Seq[PublishInfo]] = T {
Seq(
PublishInfo(file = assembly(), classifier = Some("assembly"), ivyConfig = "compile")
)
}
override def assembly = T {
val isWin = scala.util.Properties.isWin
val millPath = T.ctx.dest / (if (isWin) "mill.bat" else "mill")
os.copy(super.assembly().path, millPath)
PathRef(millPath)
}
def prependShellScript = T {
val (millArgs, otherArgs) =
forkArgs().partition(arg => arg.startsWith("-DMILL") && !arg.startsWith("-DMILL_VERSION"))
// Pass Mill options via file, due to small max args limit in Windows
val vmOptionsFile = T.ctx.dest / "mill.properties"
val millOptionsContent =
millArgs.map(_.drop(2).replace("\\", "/")).mkString(
"\r\n"
) // drop -D prefix, replace \ with /
os.write(vmOptionsFile, millOptionsContent)
val jvmArgs = otherArgs ++ List(s"-DMILL_OPTIONS_PATH=$vmOptionsFile")
val classpath = runClasspath().map(_.path.toString)
launcherScript(
jvmArgs,
jvmArgs,
classpath,
Agg(pathingJar().path.toString) // TODO not working yet on Windows! see #791
)
}
def pathingJar = T {
// see http://todayguesswhat.blogspot.com/2011/03/jar-manifestmf-class-path-referencing.html
// for more detailed explanation
val isWin = scala.util.Properties.isWin