-
Notifications
You must be signed in to change notification settings - Fork 129
/
build.sc
1949 lines (1749 loc) · 69.8 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 $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
import $ivy.`io.get-coursier::coursier-launcher:2.1.13`
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.26`
import $file.project.deps, deps.{Deps, Docker, InternalDeps, Java, Scala, TestDeps}
import $file.project.publish, publish.{ghOrg, ghName, ScalaCliPublishModule, organization}
import $file.project.settings, settings.{
CliLaunchers,
FormatNativeImageConf,
HasTests,
LocalRepo,
PublishLocalNoFluff,
ScalaCliCrossSbtModule,
ScalaCliSbtModule,
ScalaCliScalafixModule,
localRepoResourcePath,
platformExecutableJarExtension,
workspaceDirName,
projectFileName,
jvmPropertiesFileName
}
import $file.project.deps, deps.customRepositories
import $file.project.website
import java.io.File
import java.net.URL
import java.nio.charset.Charset
import java.util.Locale
import de.tobiasroeser.mill.vcs.version.VcsVersion
import io.github.alexarchambault.millnativeimage.upload.Upload
import mill._, scalalib.{publish => _, _}
import mill.contrib.bloop.Bloop
import _root_.scala.util.{Properties, Using}
// Tell mill modules are under modules/
implicit def millModuleBasePath: define.Ctx.BasePath =
define.Ctx.BasePath(super.millModuleBasePath.value / "modules")
object cli extends Cross[Cli](Scala.scala3MainVersions) with CrossScalaDefaultToInternal
trait CrossScalaDefault { _: mill.define.Cross[_] =>
def crossScalaDefaultVersion: String
override def defaultCrossSegments = Seq(crossScalaDefaultVersion)
}
trait CrossScalaDefaultToInternal extends CrossScalaDefault { _: mill.define.Cross[_] =>
def crossScalaDefaultVersion: String = Scala.defaultInternal
}
trait CrossScalaDefaultToRunner extends CrossScalaDefault { _: mill.define.Cross[_] =>
def crossScalaDefaultVersion: String = Scala.runnerScala3
}
// Publish a bootstrapped, executable jar for a restricted environments
object cliBootstrapped extends ScalaCliPublishModule {
override def unmanagedClasspath = T(cli(Scala.defaultInternal).nativeImageClassPath())
override def jar = assembly()
import mill.scalalib.Assembly
override def mainClass = Some("scala.cli.ScalaCli")
override def assemblyRules = Seq(
Assembly.Rule.ExcludePattern(".*\\.tasty"),
Assembly.Rule.ExcludePattern(".*\\.semanticdb")
) ++ super.assemblyRules
override def resources = T.sources {
super.resources() ++ Seq(propertiesFilesResources())
}
def propertiesFilesResources = T.persistent {
val dir = T.dest / "resources"
val dest = dir / "java-properties" / "scala-cli-properties"
val content = "scala-cli.kind=jvm.bootstrapped"
os.write.over(dest, content, createFolders = true)
PathRef(dir)
}
}
object `specification-level` extends Cross[SpecificationLevel](Scala.all)
with CrossScalaDefaultToInternal
object `build-macros` extends Cross[BuildMacros](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
object config extends Cross[Config](Scala.all) with CrossScalaDefaultToInternal
object options extends Cross[Options](Scala.scala3MainVersions) with CrossScalaDefaultToInternal
object directives extends Cross[Directives](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
object core extends Cross[Core](Scala.scala3MainVersions) with CrossScalaDefaultToInternal
object `build-module` extends Cross[Build](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
object runner extends Cross[Runner](Scala.runnerScalaVersions) with CrossScalaDefaultToRunner
object `test-runner` extends Cross[TestRunner](Scala.testRunnerScalaVersions)
with CrossScalaDefaultToRunner
object `tasty-lib` extends Cross[TastyLib](Scala.all) with CrossScalaDefaultToInternal
// Runtime classes used within native image on Scala 3 replacing runtime from Scala
object `scala3-runtime` extends Cross[Scala3Runtime](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
// Logic to process classes that is shared between build and the scala-cli itself
object `scala3-graal` extends Cross[Scala3Graal](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
// Main app used to process classpath within build itself
object `scala3-graal-processor` extends Cross[Scala3GraalProcessor](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
object `scala-cli-bsp` extends JavaModule with ScalaCliPublishModule {
def ivyDeps = super.ivyDeps() ++ Seq(
Deps.bsp4j
)
def javacOptions = T {
super.javacOptions() ++ Seq("-target", "8", "-source", "8")
}
}
object integration extends CliIntegration {
object test extends IntegrationScalaTests {
def ivyDeps = super.ivyDeps() ++ Seq(
Deps.jgit,
Deps.jsoup
)
}
object docker extends CliIntegrationDocker {
object test extends ScalaCliTests {
def sources = T.sources {
super.sources() ++ integration.sources()
}
def tmpDirBase = T.persistent {
PathRef(T.dest / "working-dir")
}
def forkEnv = super.forkEnv() ++ Seq(
"SCALA_CLI_TMP" -> tmpDirBase().path.toString,
"SCALA_CLI_IMAGE" -> "scala-cli",
"SCALA_CLI_PRINT_STACK_TRACES" -> "1"
)
}
}
object `docker-slim` extends CliIntegrationDocker {
object test extends ScalaCliTests {
def sources = T.sources {
integration.docker.test.sources()
}
def tmpDirBase = T.persistent {
PathRef(T.dest / "working-dir")
}
def forkEnv = super.forkEnv() ++ Seq(
"SCALA_CLI_TMP" -> tmpDirBase().path.toString,
"SCALA_CLI_IMAGE" -> "scala-cli-slim",
"SCALA_CLI_PRINT_STACK_TRACES" -> "1"
)
}
}
}
object `docs-tests` extends Cross[DocsTests](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
trait DocsTests extends CrossSbtModule with ScalaCliScalafixModule with HasTests { main =>
def ivyDeps = Agg(
Deps.fansi,
Deps.osLib,
Deps.pprint
)
def tmpDirBase = T.persistent {
PathRef(T.dest / "working-dir")
}
def extraEnv = T {
Seq(
"SCLICHECK_SCALA_CLI" -> cli(crossScalaVersion).standaloneLauncher().path.toString,
"SCALA_CLI_CONFIG" -> (tmpDirBase().path / "config" / "config.json").toString
)
}
def forkEnv = super.forkEnv() ++ extraEnv()
def constantsFile = T.persistent {
val dir = T.dest / "constants"
val dest = dir / "Constants.scala"
val code =
s"""package sclicheck
|
|/** Build-time constants. Generated by mill. */
|object Constants {
| def coursierOrg = "${Deps.coursier.dep.module.organization.value}"
| def coursierCliModule = "${Deps.coursierCli.dep.module.name.value}"
| def coursierCliVersion = "${Deps.Versions.coursierCli}"
| def defaultScalaVersion = "${Scala.defaultUser}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}
def generatedSources = super.generatedSources() ++ Seq(constantsFile())
object test extends ScalaCliTests with ScalaCliScalafixModule {
def forkEnv = super.forkEnv() ++ extraEnv() ++ Seq(
"SCALA_CLI_EXAMPLES" -> (os.pwd / "examples").toString,
"SCALA_CLI_GIF_SCENARIOS" -> (os.pwd / "gifs" / "scenarios").toString,
"SCALA_CLI_WEBSITE_IMG" -> (os.pwd / "website" / "static" / "img").toString,
"SCALA_CLI_GIF_RENDERER_DOCKER_DIR" -> (os.pwd / "gifs").toString,
"SCALA_CLI_SVG_RENDERER_DOCKER_DIR" -> (os.pwd / "gifs" / "svg_render").toString
)
def resources = T.sources {
// Adding markdown directories here, so that they're watched for changes in watch mode
Seq(
PathRef(os.pwd / "website" / "docs" / "commands"),
PathRef(os.pwd / "website" / "docs" / "cookbooks")
) ++ super.resources()
}
}
}
object packager extends ScalaModule with Bloop.Module {
def skipBloop = true
def scalaVersion = Scala.scala213
def ivyDeps = Agg(
Deps.scalaPackagerCli
)
def mainClass = Some("packager.cli.PackagerCli")
}
object `generate-reference-doc` extends Cross[GenerateReferenceDoc](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
trait GenerateReferenceDoc extends CrossSbtModule with ScalaCliScalafixModule {
def moduleDeps = Seq(
cli(crossScalaVersion)
)
def repositoriesTask = T.task(super.repositoriesTask() ++ customRepositories)
def ivyDeps = Agg(
Deps.caseApp,
Deps.munit
)
def mainClass = Some("scala.cli.doc.GenerateReferenceDoc")
def forkEnv = super.forkEnv() ++ Seq(
"SCALA_CLI_POWER" -> "true"
)
}
object dummy extends Module {
// dummy projects to get scala steward updates for Ammonite and scalafmt, whose
// versions are used in the fmt and repl commands, and ensure Ammonite is available
// for all Scala versions we support.
object amm extends Cross[Amm](Scala.listMaxAmmoniteScalaVersion)
trait Amm extends Cross.Module[String] with CrossScalaModule with Bloop.Module {
def crossScalaVersion = crossValue
def skipBloop = true
def ivyDeps = {
val ammoniteDep =
if (crossValue == Scala.scala3Lts) Deps.ammoniteForScala3Lts
else Deps.ammonite
Agg(ammoniteDep)
}
}
object scalafmt extends ScalaModule with Bloop.Module {
def skipBloop = true
def scalaVersion = Scala.defaultInternal
def ivyDeps = Agg(
Deps.scalafmtCli
)
}
object pythonInterface extends JavaModule with Bloop.Module {
def skipBloop = true
def ivyDeps = Agg(
Deps.pythonInterface
)
}
object scalaPy extends ScalaModule with Bloop.Module {
def skipBloop = true
def scalaVersion = Scala.defaultInternal
def ivyDeps = Agg(
Deps.scalaPy
)
}
}
trait BuildMacros extends ScalaCliCrossSbtModule
with ScalaCliPublishModule
with ScalaCliScalafixModule
with HasTests {
def crossScalaVersion = crossValue
def compileIvyDeps = T {
if (crossScalaVersion.startsWith("3")) super.compileIvyDeps()
else super.compileIvyDeps() ++ Agg(Deps.scalaReflect(crossScalaVersion))
}
object test extends ScalaCliTests {
// Is there a better way to add task dependency to test?
def test(args: String*) = T.command {
val res = super.test(args: _*)()
testNegativeCompilation()()
res
}
def scalacOptions = T {
super.scalacOptions() ++ asyncScalacOptions(scalaVersion())
}
def testNegativeCompilation() = T.command {
val base = os.pwd / "modules" / "build-macros" / "src"
val negativeTests = Seq(
"MismatchedLeft.scala" -> Seq(
"Found\\: +EE1".r,
"Found\\: +EE2".r,
"Required\\: +E2".r
)
)
val cpsSource = base / "main" / "scala" / "scala" / "build" / "EitherCps.scala"
assert(os.exists(cpsSource))
val sv = scalaVersion()
def compile(extraSources: os.Path*) =
os.proc("scala-cli", "compile", "-S", sv, cpsSource, extraSources).call(
check =
false,
mergeErrIntoOut = true
)
assert(0 == compile().exitCode)
val notPassed = negativeTests.filter { case (testName, expectedErrors) =>
val testFile = base / "negative-tests" / testName
val res = compile(testFile)
println(s"Compiling $testName:")
println(res.out.text())
val name = testFile.last
if (res.exitCode != 0) {
println(s"Test case $name failed to compile as expected")
val lines = res.out.lines()
println(lines)
expectedErrors.forall { expected =>
if (lines.exists(expected.findFirstIn(_).nonEmpty)) false
else {
println(s"ERROR: regex `$expected` not found in compilation output for $testName")
true
}
}
}
else {
println(s"[ERROR] $name compiled successfully but it should not!")
true
}
}
assert(notPassed.isEmpty)
}
}
}
def asyncScalacOptions(scalaVersion: String) =
if (scalaVersion.startsWith("3")) Nil else Seq("-Xasync")
trait ProtoBuildModule extends ScalaCliPublishModule with HasTests
with ScalaCliScalafixModule
trait Core extends ScalaCliCrossSbtModule
with ScalaCliPublishModule
with HasTests
with ScalaCliScalafixModule {
def crossScalaVersion = crossValue
def moduleDeps = Seq(
config(crossScalaVersion)
)
def compileModuleDeps = Seq(
`build-macros`(crossScalaVersion)
)
def scalacOptions = T {
super.scalacOptions() ++ asyncScalacOptions(crossScalaVersion)
}
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.bloopRifle.exclude(("org.scala-lang.modules", "scala-collection-compat_2.13")),
Deps.collectionCompat,
Deps.coursierJvm
// scalaJsEnvNodeJs brings a guava version that conflicts with this
.exclude(("com.google.collections", "google-collections"))
// Coursier is not cross-compiled and pulls jsoniter-scala-macros in 2.13
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-macros"))
// Let's favor our config module rather than the one coursier pulls
.exclude((organization, "config_2.13"))
.exclude(("org.scala-lang.modules", "scala-collection-compat_2.13")),
Deps.dependency,
Deps.guava, // for coursierJvm / scalaJsEnvNodeJs, see above
Deps.jgit,
Deps.nativeTools, // Used only for discovery methods. For linking, look for scala-native-cli
Deps.osLib,
Deps.pprint,
Deps.scalaJsEnvJsdomNodejs,
Deps.scalaJsLogging,
Deps.swoval
)
def compileIvyDeps = super.compileIvyDeps() ++ Seq(
Deps.jsoniterMacros
)
private def vcsState = T.persistent {
val isCI = System.getenv("CI") != null
val state = VcsVersion.vcsState().format()
if (isCI) state
else state + "-maybe-stale"
}
def constantsFile = T.persistent {
val dir = T.dest / "constants"
val dest = dir / "Constants.scala"
val testRunnerMainClass = `test-runner`(Scala.runnerScala3)
.mainClass()
.getOrElse(sys.error("No main class defined for test-runner"))
val runnerMainClass = runner(Scala.runnerScala3)
.mainClass()
.getOrElse(sys.error("No main class defined for runner"))
val detailedVersionValue =
if (`local-repo`.developingOnStubModules) s"""Some("${vcsState()}")"""
else "None"
val testRunnerOrganization = `test-runner`(Scala.runnerScala3)
.pomSettings()
.organization
val code =
s"""package scala.build.internal
|
|/** Build-time constants. Generated by mill. */
|object Constants {
| def version = "${publishVersion()}"
| def detailedVersion: Option[String] = $detailedVersionValue
| def ghOrg = "$ghOrg"
| def ghName = "$ghName"
|
| def scalaJsVersion = "${Scala.scalaJs}"
| def scalaJsCliVersion = "${Scala.scalaJsCli}"
| def scalajsEnvJsdomNodejsVersion = "${Deps.scalaJsEnvJsdomNodejs.dep.version}"
| def scalaNativeVersion04 = "${Deps.Versions.scalaNative04}"
| def scalaNativeVersion = "${Deps.Versions.scalaNative}"
|
| def testRunnerOrganization = "$testRunnerOrganization"
| def testRunnerModuleName = "${`test-runner`(Scala.runnerScala3).artifactName()}"
| def testRunnerVersion = "${`test-runner`(Scala.runnerScala3).publishVersion()}"
| def testRunnerMainClass = "$testRunnerMainClass"
|
| def runnerOrganization = "${runner(Scala.runnerScala3).pomSettings().organization}"
| def runnerModuleName = "${runner(Scala.runnerScala3).artifactName()}"
| def runnerVersion = "${runner(Scala.runnerScala3).publishVersion()}"
| def runnerMainClass = "$runnerMainClass"
|
| def semanticDbPluginOrganization = "${Deps.semanticDbScalac.dep.module.organization
.value}"
| def semanticDbPluginModuleName = "${Deps.semanticDbScalac.dep.module.name.value}"
| def semanticDbPluginVersion = "${Deps.semanticDbScalac.dep.version}"
|
| def semanticDbJavacPluginOrganization = "${Deps.semanticDbJavac.dep.module.organization
.value}"
| def semanticDbJavacPluginModuleName = "${Deps.semanticDbJavac.dep.module.name.value}"
| def semanticDbJavacPluginVersion = "${Deps.semanticDbJavac.dep.version}"
|
| def localRepoResourcePath = "$localRepoResourcePath"
|
| def jmhVersion = "${Deps.Versions.jmh}"
| def jmhOrg = "${Deps.jmhCore.dep.module.organization.value}"
| def jmhCoreModule = "${Deps.jmhCore.dep.module.name.value}"
| def jmhGeneratorBytecodeModule = "${Deps.jmhGeneratorBytecode.dep.module.name.value}"
|
| def ammoniteVersion = "${Deps.Versions.ammonite}"
| def ammoniteVersionForScala3Lts = "${Deps.Versions.ammoniteForScala3Lts}"
| def millVersion = "${InternalDeps.Versions.mill}"
| def lefouMillwRef = "${InternalDeps.Versions.lefouMillwRef}"
| def maxScalaNativeForMillExport = "${Deps.Versions.maxScalaNativeForMillExport}"
|
| def scalafmtOrganization = "${Deps.scalafmtCli.dep.module.organization.value}"
| def scalafmtName = "${Deps.scalafmtCli.dep.module.name.value}"
| def defaultScalafmtVersion = "${Deps.scalafmtCli.dep.version}"
|
| def toolkitOrganization = "${Deps.toolkit.dep.module.organization.value}"
| def toolkitName = "${Deps.toolkit.dep.module.name.value}"
| def toolkitTestName = "${Deps.toolkitTest.dep.module.name.value}"
| def toolkitDefaultVersion = "${Deps.toolkitVersion}"
| def toolkitMaxScalaNative = "${Deps.Versions.maxScalaNativeForToolkit}"
| def toolkitVersionForNative04 = "${Deps.toolkitVersionForNative04}"
| def toolkitVersionForNative05 = "${Deps.toolkitVersionForNative05}"
|
| def typelevelOrganization = "${Deps.typelevelToolkit.dep.module.organization.value}"
| def typelevelToolkitDefaultVersion = "${Deps.typelevelToolkitVersion}"
| def typelevelToolkitMaxScalaNative = "${Deps.Versions.maxScalaNativeForTypelevelToolkit}"
|
| def minimumBloopJavaVersion = ${Java.minimumBloopJava}
| def minimumInternalJavaVersion = ${Java.minimumInternalJava}
| def defaultJavaVersion = ${Java.defaultJava}
|
| def defaultScalaVersion = "${Scala.defaultUser}"
| def defaultScala212Version = "${Scala.scala212}"
| def defaultScala213Version = "${Scala.scala213}"
| def scala3LtsPrefix = "${Scala.scala3LtsPrefix}"
|
| def workspaceDirName = "$workspaceDirName"
| def projectFileName = "$projectFileName"
| def jvmPropertiesFileName = "$jvmPropertiesFileName"
| def scalacArgumentsFileName = "scalac.args.txt"
| def maxScalacArgumentsCount = 5000
|
| def defaultGraalVMJavaVersion = ${deps.graalVmJavaVersion}
| def defaultGraalVMVersion = "${deps.graalVmVersion}"
|
| def scalaCliSigningOrganization = "${Deps.signingCli.dep.module.organization.value}"
| def scalaCliSigningName = "${Deps.signingCli.dep.module.name.value}"
| def scalaCliSigningVersion = "${Deps.signingCli.dep.version}"
| def javaClassNameOrganization = "${Deps.javaClassName.dep.module.organization.value}"
| def javaClassNameName = "${Deps.javaClassName.dep.module.name.value}"
| def javaClassNameVersion = "${Deps.javaClassName.dep.version}"
|
| def signingCliJvmVersion = ${Deps.Versions.signingCliJvmVersion}
|
| def libsodiumVersion = "${deps.libsodiumVersion}"
| def libsodiumjniVersion = "${Deps.libsodiumjni.dep.version}"
|
| def scalaPyVersion = "${Deps.scalaPy.dep.version}"
| def scalaPyMaxScalaNative = "${Deps.Versions.maxScalaNativeForScalaPy}"
|
| def giter8Organization = "${Deps.giter8.dep.module.organization.value}"
| def giter8Name = "${Deps.giter8.dep.module.name.value}"
| def giter8Version = "${Deps.giter8.dep.version}"
|
| def sbtVersion = "${Deps.Versions.sbtVersion}"
|
| def mavenVersion = "${Deps.Versions.mavenVersion}"
| def mavenScalaCompilerPluginVersion = "${Deps.Versions.mavenScalaCompilerPluginVersion}"
| def mavenExecPluginVersion = "${Deps.Versions.mavenExecPluginVersion}"
| def mavenAppArtifactId = "${Deps.Versions.mavenAppArtifactId}"
| def mavenAppGroupId = "${Deps.Versions.mavenAppGroupId}"
| def mavenAppVersion = "${Deps.Versions.mavenAppVersion}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}
def generatedSources = super.generatedSources() ++ Seq(constantsFile())
}
trait Directives extends ScalaCliCrossSbtModule
with ScalaCliPublishModule
with HasTests
with ScalaCliScalafixModule {
def crossScalaVersion = crossValue
def moduleDeps = Seq(
options(crossScalaVersion),
core(crossScalaVersion),
`build-macros`(crossScalaVersion),
`specification-level`(crossScalaVersion)
)
def scalacOptions = T {
super.scalacOptions() ++ asyncScalacOptions(crossScalaVersion)
}
def compileIvyDeps = super.compileIvyDeps() ++ Agg(
Deps.jsoniterMacros,
Deps.svm
)
def ivyDeps = super.ivyDeps() ++ Agg(
// Deps.asm,
Deps.bloopConfig,
Deps.jsoniterCore,
Deps.pprint,
Deps.usingDirectives
)
def repositoriesTask =
T.task(super.repositoriesTask() ++ deps.customRepositories)
object test extends ScalaCliTests {
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.pprint
)
def runClasspath = T {
super.runClasspath() ++ Seq(`local-repo`.localRepoJar())
}
def generatedSources = super.generatedSources() ++ Seq(constantsFile())
def constantsFile = T.persistent {
val dir = T.dest / "constants"
val dest = dir / "Constants2.scala"
val code =
s"""package scala.build.tests
|
|/** Build-time constants. Generated by mill. */
|object Constants {
| def cs = "${settings.cs().replace("\\", "\\\\")}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}
// uncomment below to debug tests in attach mode on 5005 port
// def forkArgs = T {
// super.forkArgs() ++ Seq("-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5005,suspend=y")
// }
}
}
trait Config extends ScalaCliCrossSbtModule
with ScalaCliPublishModule
with ScalaCliScalafixModule {
def crossScalaVersion = crossValue
def moduleDeps = Seq(`specification-level`(crossScalaVersion))
def ivyDeps = {
val maybeCollectionCompat =
if (crossScalaVersion.startsWith("2.12.")) Seq(Deps.collectionCompat)
else Nil
super.ivyDeps() ++ maybeCollectionCompat ++ Agg(
Deps.jsoniterCoreJava8
)
}
def compileIvyDeps = super.compileIvyDeps() ++ Agg(
Deps.jsoniterMacrosJava8
)
def scalacOptions = T {
super.scalacOptions() ++ Seq("-release", "8")
}
// Disabling Scalafix in 2.13 and 3, so that it doesn't remove
// some compatibility-related imports, that are actually only used
// in Scala 2.12.
def fix(args: String*) =
if (crossScalaVersion.startsWith("2.12.")) super.fix(args: _*)
else T.command(())
}
trait Options extends ScalaCliCrossSbtModule with ScalaCliPublishModule with HasTests
with ScalaCliScalafixModule {
def crossScalaVersion = crossValue
def moduleDeps = Seq(
core(crossScalaVersion)
)
def compileModuleDeps = Seq(
`build-macros`(crossScalaVersion)
)
def scalacOptions = T {
super.scalacOptions() ++ asyncScalacOptions(crossScalaVersion)
}
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.bloopConfig,
Deps.signingCliShared
)
def compileIvyDeps = super.compileIvyDeps() ++ Seq(
Deps.jsoniterMacros
)
def repositoriesTask =
T.task(super.repositoriesTask() ++ deps.customRepositories)
object test extends ScalaCliTests {
// uncomment below to debug tests in attach mode on 5005 port
// def forkArgs = T {
// super.forkArgs() ++ Seq("-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5005,suspend=y")
// }
}
}
trait Scala3Runtime extends CrossSbtModule with ScalaCliPublishModule {
def crossScalaVersion = crossValue
def ivyDeps = super.ivyDeps()
}
trait Scala3Graal extends ScalaCliCrossSbtModule
with ScalaCliPublishModule with ScalaCliScalafixModule {
def crossScalaVersion = crossValue
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.asm,
Deps.osLib
)
def resources = T.sources {
val extraResourceDir = T.dest / "extra"
// scala3RuntimeFixes.jar is also used within
// resource-config.json and BytecodeProcessor.scala
os.copy.over(
`scala3-runtime`(crossScalaVersion).jar().path,
extraResourceDir / "scala3RuntimeFixes.jar",
createFolders = true
)
super.resources() ++ Seq(mill.PathRef(extraResourceDir))
}
}
trait Scala3GraalProcessor extends CrossScalaModule with ScalaCliPublishModule {
def moduleDeps = Seq(`scala3-graal`(crossScalaVersion))
def finalMainClass = "scala.cli.graal.CoursierCacheProcessor"
}
trait Build extends ScalaCliCrossSbtModule
with ScalaCliPublishModule
with HasTests
with ScalaCliScalafixModule {
def crossScalaVersion = crossValue
def millSourcePath = super.millSourcePath / os.up / "build"
def moduleDeps = Seq(
options(crossScalaVersion),
directives(crossScalaVersion),
`scala-cli-bsp`,
`test-runner`(crossScalaVersion),
`tasty-lib`(crossScalaVersion)
)
def scalacOptions = T {
super.scalacOptions() ++ asyncScalacOptions(crossScalaVersion)
}
def compileIvyDeps = super.compileIvyDeps() ++ Agg(
Deps.jsoniterMacros,
Deps.svm
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.asm,
Deps.collectionCompat,
Deps.javaClassName,
Deps.jsoniterCore,
Deps.scalametaSemanticDbShared,
Deps.nativeTestRunner,
Deps.osLib,
Deps.pprint,
Deps.scalaJsEnvNodeJs,
Deps.scalaJsTestAdapter,
Deps.swoval,
Deps.zipInputStream
)
def repositoriesTask =
T.task(super.repositoriesTask() ++ deps.customRepositories)
object test extends ScalaCliTests {
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.pprint,
Deps.slf4jNop
)
def runClasspath = T {
super.runClasspath() ++ Seq(`local-repo`.localRepoJar())
}
def generatedSources = super.generatedSources() ++ Seq(constantsFile())
def constantsFile = T.persistent {
val dir = T.dest / "constants"
val dest = dir / "Constants2.scala"
val code =
s"""package scala.build.tests
|
|/** Build-time constants. Generated by mill. */
|object Constants {
| def cs = "${settings.cs().replace("\\", "\\\\")}"
| def toolkitOrganization = "${Deps.toolkit.dep.module.organization.value}"
| def toolkitName = "${Deps.toolkit.dep.module.name.value}"
| def toolkitTestName = "${Deps.toolkitTest.dep.module.name.value}"
| def toolkitVersion = "${Deps.toolkitTest.dep.version}"
| def typelevelToolkitOrganization = "${Deps.typelevelToolkit.dep.module.organization
.value}"
| def typelevelToolkitVersion = "${Deps.typelevelToolkit.dep.version}"
|
| def defaultScalaVersion = "${Scala.defaultUser}"
| def defaultScala212Version = "${Scala.scala212}"
| def defaultScala213Version = "${Scala.scala213}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}
// uncomment below to debug tests in attach mode on 5005 port
// def forkArgs = T {
// super.forkArgs() ++ Seq("-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5005,suspend=y")
// }
}
}
trait SpecificationLevel extends ScalaCliCrossSbtModule
with ScalaCliPublishModule {
def crossScalaVersion = crossValue
def scalacOptions = T {
val isScala213 = crossScalaVersion.startsWith("2.13.")
val extraOptions =
if (isScala213) Seq("-Xsource:3")
else Nil
super.scalacOptions() ++ extraOptions ++ Seq("-release", "8")
}
}
trait Cli extends CrossSbtModule with ProtoBuildModule with CliLaunchers
with FormatNativeImageConf {
// Copied from Mill: https://github.com/com-lihaoyi/mill/blob/ea367c09bd31a30464ca901cb29863edde5340be/scalalib/src/mill/scalalib/JavaModule.scala#L792
def debug(port: Int, args: Task[Args] = T.task(Args())): Command[Unit] = T.command {
try mill.api.Result.Success(
mill.util.Jvm.runSubprocess(
finalMainClass(),
runClasspath().map(_.path),
forkArgs() ++ Seq(
s"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=$port,quiet=y"
),
forkEnv(),
args().value,
workingDir = forkWorkingDir(),
useCpPassingJar = runUseArgsFile()
)
)
catch {
case e: Exception =>
mill.api.Result.Failure("subprocess failed")
}
}
def constantsFile = T.persistent {
val dir = T.dest / "constants"
val dest = dir / "Constants.scala"
val code =
s"""package scala.cli.internal
|
|/** Build-time constants. Generated by mill. */
|object Constants {
| def pythonInterfaceOrg = "${Deps.pythonInterface.dep.module.organization.value}"
| def pythonInterfaceName = "${Deps.pythonInterface.dep.module.name.value}"
| def pythonInterfaceVersion = "${Deps.pythonInterface.dep.version}"
| def launcherTypeResourcePath = "${launcherTypeResourcePath.toString}"
| def defaultFilesResourcePath = "$defaultFilesResourcePath"
| def maxAmmoniteScala3Version = "${Scala.maxAmmoniteScala3Version}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}
def optionsConstantsFile = T.persistent {
val dir = T.dest / "constants"
val dest = dir / "Constants.scala"
val code =
s"""package scala.cli.commands
|
|/** Build-time constants. Generated by mill. */
|object Constants {
| def defaultScalaVersion = "${Scala.defaultUser}"
| def defaultJavaVersion = ${Java.defaultJava}
| def minimumBloopJavaVersion = ${Java.minimumBloopJava}
| def scalaJsVersion = "${Scala.scalaJs}"
| def scalaJsCliVersion = "${Scala.scalaJsCli}"
| def scalaNativeVersion = "${Deps.nativeTools.dep.version}"
| def ammoniteVersion = "${Deps.Versions.ammonite}"
| def ammoniteVersionForScala3Lts = "${Deps.Versions.ammoniteForScala3Lts}"
| def defaultScalafmtVersion = "${Deps.scalafmtCli.dep.version}"
| def defaultGraalVMJavaVersion = "${deps.graalVmJavaVersion}"
| def defaultGraalVMVersion = "${deps.graalVmVersion}"
| def scalaPyVersion = "${Deps.scalaPy.dep.version}"
| def signingCliJvmVersion = ${Deps.Versions.signingCliJvmVersion}
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}
def generatedSources = super.generatedSources() ++ Seq(constantsFile(), optionsConstantsFile())
def defaultFilesResources = T.persistent {
val dir = T.dest / "resources"
def transformWorkflow(content: Array[Byte]): Array[Byte] =
new String(content, "UTF-8")
.replaceAll(" ./scala-cli", " scala-cli")
.getBytes("UTF-8")
val resources = Seq[(String, os.SubPath, Array[Byte] => Array[Byte])](
(
"https://raw.githubusercontent.com/scala-cli/default-workflow/main/.github/workflows/ci.yml",
os.sub / "workflows" / "default.yml",
transformWorkflow _
),
(
"https://raw.githubusercontent.com/scala-cli/default-workflow/main/.gitignore",
os.sub / "gitignore",
identity
)
)
for ((srcUrl, destRelPath, transform) <- resources) {
val dest = dir / defaultFilesResourcePath / destRelPath
if (!os.isFile(dest)) {
val content = Using.resource(new URL(srcUrl).openStream())(_.readAllBytes())
os.write(dest, transform(content), createFolders = true)
}
}
PathRef(dir)
}
override def resources = T.sources {
super.resources() ++ Seq(defaultFilesResources())
}
def scalacOptions = T {
super.scalacOptions() ++ asyncScalacOptions(crossScalaVersion)
}
def javacOptions = T {
super.javacOptions() ++ Seq("--release", "16")
}
def moduleDeps = Seq(
`build-module`(crossScalaVersion),
config(crossScalaVersion),
`scala3-graal`(crossScalaVersion),
`specification-level`(crossScalaVersion)
)
def repositoriesTask = T.task(super.repositoriesTask() ++ customRepositories)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.caseApp,
Deps.coursierLauncher,
Deps.coursierProxySetup,
Deps.coursierPublish.exclude((organization, "config_2.13")),
Deps.jimfs, // scalaJsEnvNodeJs pulls jimfs:1.1, whose class path seems borked (bin compat issue with the guava version it depends on)
Deps.jniUtils,
Deps.jsoniterCore,
Deps.libsodiumjni,
Deps.metaconfigTypesafe,
Deps.pythonNativeLibs,
Deps.scalaPackager.exclude("com.lihaoyi" -> "os-lib_2.13"),
Deps.signingCli.exclude((organization, "config_2.13")),
Deps.slf4jNop, // to silence jgit
Deps.sttp
)
def compileIvyDeps = super.compileIvyDeps() ++ Agg(
Deps.jsoniterMacros,
Deps.svm
)
def mainClass = Some("scala.cli.ScalaCli")
override def nativeImageClassPath = T {
val classpath = super.nativeImageClassPath().map(_.path).mkString(File.pathSeparator)
val cache = T.dest / "native-cp"
// `scala3-graal-processor`.run() do not give me output and I cannot pass dynamically computed values like classpath
val res = mill.util.Jvm.callSubprocess(
mainClass = `scala3-graal-processor`(crossScalaVersion).finalMainClass(),
classPath = `scala3-graal-processor`(crossScalaVersion).runClasspath().map(_.path),
mainArgs = Seq(cache.toNIO.toString, classpath),
workingDir = os.pwd
)
val cp = res.out.trim()
cp.split(File.pathSeparator).toSeq.map(p => PathRef(os.Path(p)))
}
def localRepoJar = `local-repo`.localRepoJar()
object test extends ScalaCliTests with ScalaCliScalafixModule {
def moduleDeps = super.moduleDeps ++ Seq(
`build-module`(crossScalaVersion).test
)
def runClasspath = T {
super.runClasspath() ++ Seq(localRepoJar())
}
def compileIvyDeps = super.ivyDeps() ++ Agg(
Deps.jsoniterMacros
)
// Required by the reflection usage in modules/cli/src/test/scala/cli/tests/SetupScalaCLITests.scala
override def forkArgs: T[Seq[String]] = T {
super.forkArgs() ++ Seq("--add-opens=java.base/java.util=ALL-UNNAMED")
}
}
}
trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
with ScalaCliScalafixModule {
def scalaVersion = sv
def sv = Scala.scala213
private def prefix = "integration-"
def tmpDirBase = T.persistent {
PathRef(T.dest / "working-dir")
}
def scalacOptions = T {
super.scalacOptions() ++ Seq("-Xasync", "-deprecation")
}
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.osLib
)
private def mainArtifactName = T(artifactName())
trait IntegrationScalaTests extends super.ScalaCliTests with ScalaCliScalafixModule {
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.bsp4j,
Deps.coursier
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-macros")),
Deps.dockerClient,
Deps.jsoniterCore,
Deps.libsodiumjni,
Deps.pprint,
Deps.scalaAsync,
Deps.slf4jNop,
Deps.usingDirectives
)
def compileIvyDeps = super.compileIvyDeps() ++ Seq(
Deps.jsoniterMacros
)
def forkEnv = super.forkEnv() ++ Seq(