forked from almond-sh/almond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sc
896 lines (824 loc) · 29 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
import $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
import $ivy.`io.get-coursier.util::get-cs:0.1.1`
import $ivy.`com.github.lolgab::mill-mima::0.0.24`
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.24`
import $file.project.deps, deps.{Deps, DepOps, ScalaVersions}
import $file.project.jupyterserver, jupyterserver.{jupyterConsole => jupyterConsole0, jupyterServer}
import $file.scripts.website0.Website, Website.Relativize
import $file.project.settings, settings.{
AlmondModule,
AlmondRepositories,
AlmondSimpleModule,
AlmondTestModule,
BootstrapLauncher,
DependencyListResource,
ExternalSources,
LocalRepo,
Mima,
PropertyFile,
TestCommand,
Util,
buildVersion
}
import java.nio.charset.Charset
import java.nio.file.FileSystems
import coursier.getcs.GetCs
import io.github.alexarchambault.millnativeimage.upload.Upload
import mill._, scalalib._
import mill.contrib.bloop.Bloop
import _root_.scala.concurrent.duration._
import _root_.scala.util.Properties
// Tell mill modules are under modules/
implicit def millModuleBasePath: define.BasePath =
define.BasePath(super.millModuleBasePath.value / "modules")
class LoggerScala2Macros(val crossScalaVersion: String) extends AlmondModule {
def ivyDeps = T {
val sv = scalaVersion()
Agg(Deps.scalaReflect(sv))
}
}
class Logger(val crossScalaVersion: String) extends AlmondModule {
def supports3 = true
def moduleDeps = Seq(
shared.`logger-scala2-macros`()
)
def ivyDeps = T {
val sv = scalaVersion()
val scalaReflect =
if (sv.startsWith("2.")) Agg(Deps.scalaReflect(sv))
else Agg(ivy"org.scala-lang:scala3-library_3:${scalaVersion()}")
scalaReflect
}
object test extends Tests with AlmondTestModule
}
class Channels(val crossScalaVersion: String) extends AlmondModule with Mima {
def moduleDeps = Seq(
shared.logger()
)
def ivyDeps = Agg(
Deps.fs2(crossScalaVersion),
Deps.jeromq
)
object test extends Tests with AlmondTestModule
}
class Protocol(val crossScalaVersion: String) extends AlmondModule {
def moduleDeps = Seq(
shared.channels()
)
def ivyDeps = Agg(
Deps.jsoniterScalaCore.applyBinaryVersion213_3(scalaVersion())
)
def compileIvyDeps = Agg(
Deps.scalaReflect(scalaVersion()),
Deps.jsoniterScalaMacros.withConfiguration("provided")
)
object test extends Tests with AlmondTestModule
}
class InterpreterApi(val crossScalaVersion: String) extends AlmondModule with Mima
class Interpreter(val crossScalaVersion: String) extends AlmondModule {
def moduleDeps = Seq(
shared.`interpreter-api`(),
shared.protocol()
)
def ivyDeps = Agg(
Deps.collectionCompat,
Deps.fansi,
Deps.scalatags.applyBinaryVersion213_3(scalaVersion()),
Deps.slf4jNop
)
object test extends Tests with AlmondTestModule
}
class Kernel(val crossScalaVersion: String) extends AlmondModule {
def moduleDeps = Seq(
shared.interpreter()
)
def compileIvyDeps = Agg(
Deps.jsoniterScalaMacros
)
def ivyDeps = Agg(
Deps.caseAppAnnotations.withDottyCompat(crossScalaVersion),
Deps.collectionCompat,
Deps.coursierApi,
Deps.fs2(crossScalaVersion)
)
object test extends Tests with AlmondTestModule {
def moduleDeps = super.moduleDeps ++ Seq(
shared.interpreter().test,
shared.`test-kit`()
)
}
}
class Test(val crossScalaVersion: String) extends AlmondModule {
def moduleDeps = Seq(
shared.`interpreter-api`()
)
}
class JupyterApi(val crossScalaVersion: String) extends AlmondModule with Mima {
def moduleDeps = Seq(
shared.`interpreter-api`()
)
def ivyDeps = Agg(
Deps.jvmRepr
)
}
class ScalaKernelApi(val crossScalaVersion: String) extends AlmondModule with DependencyListResource
with ExternalSources with PropertyFile with Mima with Bloop.Module {
def skipBloop = !ScalaVersions.binaries.contains(crossScalaVersion)
def crossFullScalaVersion = true
def moduleDeps =
if (crossScalaVersion.startsWith("3."))
Seq(
shared.`interpreter-api`(ScalaVersions.scala3Compat),
scala.`jupyter-api`(ScalaVersions.scala3Compat)
)
else
Seq(
shared.`interpreter-api`(),
scala.`jupyter-api`()
)
def ivyDeps = Agg(
Deps.ammoniteCompiler(crossScalaVersion)
.exclude(("org.slf4j", "slf4j-api")),
Deps.ammoniteReplApi(crossScalaVersion)
.exclude(("org.slf4j", "slf4j-api")),
Deps.jvmRepr,
Deps.coursierApi.exclude(("org.slf4j", "slf4j-api")),
Deps.collectionCompat
)
def resolvedIvyDeps = T {
// Ensure we don't depend on slf4j-api
// As no logger implem would be loaded alongside it by default, slf4j would fail to initialize,
// complain in stderr, and default to NOP logging.
val value = super.resolvedIvyDeps()
val jarNames = value
.map(_.path.last)
.filter(_.endsWith(".jar"))
.map(_.stripSuffix(".jar"))
val slf4jJars = jarNames.filter(_.startsWith("slf4j-"))
if (slf4jJars.nonEmpty)
sys.error(s"Found slf4j JARs: ${slf4jJars.mkString(", ")}")
value
}
def propertyFilePath = "almond/almond.properties"
def propertyExtra = T {
Seq(
"default-scalafmt-version" -> Deps.scalafmtDynamic.dep.version,
"scala-version" -> crossScalaVersion
)
}
}
class ScalaInterpreter(val crossScalaVersion: String) extends AlmondModule with Bloop.Module {
def skipBloop = !ScalaVersions.binaries.contains(crossScalaVersion)
def crossFullScalaVersion = true
def supports3 = true
def moduleDeps =
if (crossScalaVersion.startsWith("3."))
Seq(
shared.interpreter(ScalaVersions.scala3Compat),
scala.`coursier-logger`(ScalaVersions.scala3Compat),
scala.`scala-kernel-api-helper`(),
scala.`shared-directives`(ScalaVersions.scala3Compat),
scala.`toree-hooks`(ScalaVersions.binary(crossScalaVersion))
)
else
Seq(
shared.interpreter(),
scala.`coursier-logger`(),
scala.`scala-kernel-api`(),
scala.`shared-directives`(),
scala.`toree-hooks`(ScalaVersions.binary(crossScalaVersion))
)
def ivyDeps = T {
val metabrowse =
if (crossScalaVersion.startsWith("2."))
Agg(
Deps.metabrowseServer
// don't let metabrowse bump our slf4j version (switching to v2 can be quite sensitive when Spark is involved)
.exclude(("org.slf4j", "slf4j-api")),
// bump the scalameta version, so that all scalameta JARs have the same version as the few scalameta
// dependencies of Ammonite
Deps.scalameta
)
else
Agg.empty
metabrowse ++ Agg(
Deps.coursier.withDottyCompat(crossScalaVersion),
Deps.coursierApi,
Deps.dependencyInterface,
Deps.directiveHandler,
Deps.jansi,
Deps.ammoniteCompiler(crossScalaVersion).exclude(("net.java.dev.jna", "jna")),
Deps.ammoniteRepl(crossScalaVersion).exclude(("net.java.dev.jna", "jna"))
)
}
def scalacOptions = super.scalacOptions() ++ {
val scala213Options =
if (scalaVersion().startsWith("2.13.")) Seq("-Ymacro-annotations")
else Nil
scala213Options
}
object test extends Tests with AlmondTestModule {
def moduleDeps = {
val rx =
if (crossScalaVersion.startsWith("2.12.")) Seq(scala.`almond-rx`())
else Nil
val kernel = Seq(
if (crossScalaVersion.startsWith("3."))
shared.kernel(ScalaVersions.scala3Compat).test
else
shared.kernel().test
)
val testKit = Seq(
if (crossScalaVersion.startsWith("3."))
shared.`test-kit`(ScalaVersions.scala3Compat)
else
shared.`test-kit`()
)
val testDefs = Seq(
if (crossScalaVersion.startsWith("3."))
scala.`test-definitions`(ScalaVersions.scala3Compat)
else
scala.`test-definitions`()
)
super.moduleDeps ++
testKit ++
kernel ++
rx ++
testDefs
}
def ivyDeps = super.ivyDeps() ++ Seq(
Deps.caseApp
)
}
}
class ScalaKernel(val crossScalaVersion: String) extends AlmondModule with ExternalSources
with BootstrapLauncher with Bloop.Module {
def skipBloop = !ScalaVersions.binaries.contains(crossScalaVersion)
def crossFullScalaVersion = true
def moduleDeps =
if (crossScalaVersion.startsWith("3."))
Seq(
shared.kernel(ScalaVersions.scala3Compat),
scala.`scala-interpreter`()
)
else
Seq(
shared.kernel(),
scala.`scala-interpreter`()
)
def ivyDeps = Agg(
Deps.caseApp.withDottyCompat(crossScalaVersion),
Deps.classPathUtil,
Deps.scalafmtDynamic.withDottyCompat(crossScalaVersion)
)
object test extends Tests with AlmondTestModule {
def moduleDeps = super.moduleDeps ++ Seq(
scala.`scala-interpreter`().test
)
}
def resolvedIvyDeps = T {
// Ensure we stay on slf4j 1.x
// Kind of unnecessary now that scala-kernel-api doesn't bring slf4j-api any more,
// but keeping that just in case…
val value = super.resolvedIvyDeps()
val jarNames = value
.map(_.path.last)
.filter(_.endsWith(".jar"))
.map(_.stripSuffix(".jar"))
val slf4jJars = jarNames.filter(_.startsWith("slf4j-"))
assert(slf4jJars.nonEmpty, "No slf4j JARs found")
val wrongSlf4jVersionJars = slf4jJars.filter { name =>
val version = name.split('-').dropWhile(_.head.isLetter).mkString("-")
!version.startsWith("1.")
}
if (wrongSlf4jVersionJars.nonEmpty)
sys.error(s"Found some slf4j non-1.x JARs: ${wrongSlf4jVersionJars.mkString(", ")}")
value
}
def runClasspath =
super.runClasspath() ++
transitiveSources() ++
externalSources()
def launcherClassPath =
transitiveJars() ++
unmanagedClasspath() ++
resolvedRunIvyDeps() ++
transitiveSourceJars() ++
externalSources()
def launcherSharedClassPath = {
val mod: AlmondModule with ExternalSources =
if (crossScalaVersion.startsWith("3.")) scala.`scala-kernel-api-helper`()
else scala.`scala-kernel-api`()
mod.transitiveJars() ++
mod.unmanagedClasspath() ++
mod.resolvedRunIvyDeps() ++
mod.transitiveSourceJars() ++
mod.externalSources()
}
def manifest = T {
import java.util.jar.Attributes.Name
val ver = publishVersion()
super.manifest().add(
Name.IMPLEMENTATION_TITLE.toString -> "scala-kernel",
Name.IMPLEMENTATION_VERSION.toString -> ver,
Name.SPECIFICATION_VENDOR.toString -> "sh.almond",
Name.SPECIFICATION_TITLE.toString -> "scala-kernel",
Name.IMPLEMENTATION_VENDOR_ID.toString -> "sh.almond",
Name.SPECIFICATION_VERSION.toString -> ver,
Name.IMPLEMENTATION_VENDOR.toString -> "sh.almond"
)
}
def mainClass = Some("almond.ScalaKernel")
}
// For Scala 3 only. This publishes modules like scala-kernel_3.0.2 that
// depend on the more complex 2.13-targeting-scala-3 module like
// scala-kernel-cross-3.0.2_2.13.7. The former follows the same name pattern
// as their Scala 2 counterparts, and are more convenient to write down for end users.
class ScalaKernelHelper(val crossScalaVersion: String) extends AlmondModule with Bloop.Module {
def skipBloop = !ScalaVersions.binaries.contains(crossScalaVersion)
def crossFullScalaVersion = true
def supports3 = true
def artifactName = super.artifactName().stripSuffix("-helper")
def moduleDeps = Seq(
scala.`scala-kernel`()
)
}
class CoursierLogger(val crossScalaVersion: String) extends AlmondModule {
def supports3 = true
def moduleDeps = super.moduleDeps ++ Seq(
shared.`interpreter-api`(),
shared.logger()
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.coursierApi,
Deps.scalatags.applyBinaryVersion213_3(scalaVersion())
)
}
class SharedDirectives(val crossScalaVersion: String) extends AlmondModule {
def supports3 = true
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.directiveHandler,
Deps.jsoniterScalaCore.applyBinaryVersion213_3(scalaVersion())
)
def compileIvyDeps = Agg(
Deps.jsoniterScalaMacros
)
}
trait Launcher extends AlmondSimpleModule with BootstrapLauncher with PropertyFile
with Bloop.Module {
def supports3 = true
private def sv = ScalaVersions.scala3Latest
def scalaVersion = sv
def moduleDeps = Seq(
scala.`coursier-logger`(ScalaVersions.scala3Compat),
scala.`shared-directives`(ScalaVersions.scala3Compat),
shared.kernel(ScalaVersions.scala3Compat)
)
def ivyDeps = Agg(
Deps.caseApp,
Deps.coursierLauncher,
Deps.fansi,
Deps.scalaparse
)
def propertyFilePath = "almond/launcher/launcher.properties"
def propertyExtra = T {
val mainClass = scala.`scala-kernel`(ScalaVersions.scala3Latest).mainClass().getOrElse {
sys.error("No main class found")
}
Seq(
"kernel-main-class" -> mainClass,
"ammonite-version" -> Versions.ammonite,
"default-scala212-version" -> ScalaVersions.scala212,
"default-scala213-version" -> ScalaVersions.scala213,
"default-scala-version" -> ScalaVersions.scala3Latest
)
}
}
class ScalaKernelApiHelper(val crossScalaVersion: String) extends AlmondModule with ExternalSources
with Bloop.Module {
def skipBloop = !ScalaVersions.binaries.contains(crossScalaVersion)
def crossFullScalaVersion = true
def supports3 = true
def artifactName = super.artifactName().stripSuffix("-helper")
def moduleDeps = Seq(
scala.`scala-kernel-api`()
)
}
class AlmondScalaPy(val crossScalaVersion: String) extends AlmondModule with Mima {
def ivyDeps = Agg(
Deps.jvmRepr
)
def compileIvyDeps = Agg(
Deps.scalapy
)
}
class AlmondRx(val crossScalaVersion: String) extends AlmondModule with Mima {
def compileModuleDeps = Seq(
scala.`scala-kernel-api`()
)
def ivyDeps = Agg(
Deps.scalaRx
)
}
class Echo(val crossScalaVersion: String) extends AlmondModule {
def moduleDeps = Seq(
shared.kernel()
)
def ivyDeps = Agg(
Deps.caseApp.withDottyCompat(crossScalaVersion)
)
def propertyFilePath = "almond/echo.properties"
object test extends Tests with AlmondTestModule {
def moduleDeps = super.moduleDeps ++ Seq(
shared.test()
)
}
}
class ToreeHooks(val crossScalaVersion: String) extends AlmondModule {
def supports3 = true
def compileModuleDeps = super.compileModuleDeps ++ Seq(
scala.`scala-kernel-api`(ScalaVersions.binary(crossScalaVersion))
)
}
object shared extends Module {
object `logger-scala2-macros` extends Cross[LoggerScala2Macros](ScalaVersions.binaries: _*)
object logger extends Cross[Logger](ScalaVersions.binaries: _*)
object channels extends Cross[Channels](ScalaVersions.binaries: _*)
object protocol extends Cross[Protocol](ScalaVersions.binaries: _*)
object `interpreter-api` extends Cross[InterpreterApi](ScalaVersions.binaries: _*)
object interpreter extends Cross[Interpreter](ScalaVersions.binaries: _*)
object kernel extends Cross[Kernel](ScalaVersions.binaries: _*)
object test extends Cross[Test](ScalaVersions.binaries: _*)
object `test-kit` extends Cross[TestKit](ScalaVersions.all: _*)
}
// FIXME Can't use 'scala' because of macro hygiene issues in some mill macros
object scala extends Module {
implicit def millModuleBasePath: define.BasePath =
define.BasePath(super.millModuleBasePath.value / os.up / "scala")
object `jupyter-api` extends Cross[JupyterApi](ScalaVersions.binaries: _*)
object `scala-kernel-api` extends Cross[ScalaKernelApi](ScalaVersions.all: _*)
object `scala-kernel-api-helper`
extends Cross[ScalaKernelApiHelper](ScalaVersions.all.filter(_.startsWith("3.")): _*)
object `scala-interpreter` extends Cross[ScalaInterpreter](ScalaVersions.all: _*)
object `scala-kernel` extends Cross[ScalaKernel](ScalaVersions.all: _*)
object `scala-kernel-helper`
extends Cross[ScalaKernelHelper](ScalaVersions.all.filter(_.startsWith("3.")): _*)
object `coursier-logger` extends Cross[CoursierLogger](ScalaVersions.binaries: _*)
object `shared-directives`
extends Cross[SharedDirectives]("2.12.15" +: ScalaVersions.binaries: _*)
object launcher extends Launcher
object `almond-scalapy` extends Cross[AlmondScalaPy](ScalaVersions.binaries: _*)
object `almond-rx` extends Cross[AlmondRx](ScalaVersions.scala212, ScalaVersions.scala213)
object `toree-hooks` extends Cross[ToreeHooks](ScalaVersions.binaries: _*)
object `test-definitions` extends Cross[TestDefinitions](ScalaVersions.all: _*)
object `local-repo` extends Cross[KernelLocalRepo](ScalaVersions.all: _*)
object integration extends Integration
object examples extends Examples
}
trait Examples extends SbtModule {
private def examplesScalaVersion = "2.12.18"
private def baseRepoRoot = os.rel / "out" / "repo"
def scalaVersion = ScalaVersions.scala3Latest
object test extends Tests {
def testFramework = "munit.Framework"
def ivyDeps = T {
super.ivyDeps() ++ Agg(
Deps.expecty,
Deps.munit,
Deps.osLib,
Deps.pprint,
Deps.upickle
)
}
def forkArgs = T {
scala.`almond-scalapy`(ScalaVersions.scala212)
.publishLocalNoFluff((baseRepoRoot / "{VERSION}").toString)()
super.forkArgs() ++ Seq(
s"-Dalmond.examples.dir=${os.pwd / "examples"}",
s"-Dalmond.examples.output-dir=${T.dest / "output"}",
s"-Dalmond.examples.jupyter-path=${T.dest / "jupyter"}",
s"-Dalmond.examples.launcher=${scala.`scala-kernel`(examplesScalaVersion).launcher().path}",
s"-Dalmond.examples.repo-root=${baseRepoRoot / scala.`scala-kernel`(examplesScalaVersion).publishVersion()}"
)
}
}
}
class TestKit(val crossScalaVersion: String) extends CrossSbtModule with Bloop.Module {
def skipBloop = !ScalaVersions.binaries.contains(crossScalaVersion)
def moduleDeps =
if (crossScalaVersion.startsWith("3."))
Seq(
shared.interpreter(ScalaVersions.scala3Compat)
)
else
Seq(
shared.interpreter()
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.expecty,
Deps.osLib,
Deps.pprint
)
}
class TestDefinitions(val crossScalaVersion: String) extends CrossSbtModule with Bloop.Module {
def skipBloop = !ScalaVersions.binaries.contains(crossScalaVersion)
def moduleDeps = super.moduleDeps ++ Seq(
shared.`test-kit`()
)
def ivyDeps = T {
Agg(
Deps.coursierApi,
Deps.upickleCompat(scalaVersion())
)
}
}
class KernelLocalRepo(val testScalaVersion: String) extends LocalRepo {
def stubsModules = {
val extra =
if (testScalaVersion.startsWith("2.")) Nil
else
Seq(
scala.`scala-kernel-helper`(testScalaVersion),
scala.`scala-kernel-api-helper`(testScalaVersion)
)
Seq(
shared.kernel(ScalaVersions.binary(testScalaVersion)),
shared.interpreter(ScalaVersions.binary(testScalaVersion)),
shared.`interpreter-api`(ScalaVersions.binary(testScalaVersion)),
shared.protocol(ScalaVersions.binary(testScalaVersion)),
shared.channels(ScalaVersions.binary(testScalaVersion)),
shared.logger(ScalaVersions.binary(testScalaVersion)),
shared.`logger-scala2-macros`(ScalaVersions.binary(testScalaVersion)),
scala.`scala-kernel`(testScalaVersion),
scala.`scala-kernel-api`(testScalaVersion),
scala.`jupyter-api`(ScalaVersions.binary(testScalaVersion)),
scala.`scala-interpreter`(testScalaVersion),
scala.`toree-hooks`(ScalaVersions.binary(testScalaVersion)),
scala.`coursier-logger`(ScalaVersions.binary(testScalaVersion)),
scala.`shared-directives`(ScalaVersions.binary(testScalaVersion)),
scala.launcher,
shared.kernel(ScalaVersions.binary(ScalaVersions.scala3Latest)),
shared.interpreter(ScalaVersions.binary(ScalaVersions.scala3Latest)),
shared.`interpreter-api`(ScalaVersions.binary(ScalaVersions.scala3Latest)),
shared.protocol(ScalaVersions.binary(ScalaVersions.scala3Latest)),
shared.channels(ScalaVersions.binary(ScalaVersions.scala3Latest)),
shared.logger(ScalaVersions.binary(ScalaVersions.scala3Latest)),
shared.`logger-scala2-macros`(ScalaVersions.binary(ScalaVersions.scala3Latest))
) ++ extra
}
def version = scala.`scala-kernel`(testScalaVersion).publishVersion()
}
trait Integration extends SbtModule {
private def scalaVersion0 = ScalaVersions.scala213
def scalaVersion = scalaVersion0
def moduleDeps = super.moduleDeps ++ Seq(
shared.`test-kit`(scalaVersion0),
scala.`test-definitions`(scalaVersion0)
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.munit,
Deps.osLib,
Deps.pprint
)
object test extends Tests with TestCommand {
def testFramework = "munit.Framework"
def forkArgs = T {
scala.`local-repo`(ScalaVersions.scala212).localRepo()
scala.`local-repo`(ScalaVersions.scala213).localRepo()
scala.`local-repo`(ScalaVersions.scala3Latest).localRepo()
val version = scala.`local-repo`(ScalaVersions.scala3Latest).version()
super.forkArgs() ++ Seq(
"-Xmx768m", // let's not use too much memory here, Windows CI sometimes runs short on it
s"-Dalmond.test.local-repo=${scala.`local-repo`(ScalaVersions.scala3Latest).repoRoot.toString.replace("{VERSION}", version)}",
s"-Dalmond.test.version=$version",
s"-Dalmond.test.cs-launcher=${GetCs.cs(Deps.coursier.dep.version, "2.1.2")}",
s"-Dalmond.test.scala-version=${ScalaVersions.scala3Latest}",
s"-Dalmond.test.scala212-version=${ScalaVersions.scala212}",
s"-Dalmond.test.scala213-version=${ScalaVersions.scala213}"
)
}
def tmpDirBase = T.persistent {
PathRef(T.dest / "working-dir")
}
def forkEnv = super.forkEnv() ++ Seq(
"ALMOND_INTEGRATION_TMP" -> tmpDirBase().path.toString
)
}
}
object echo extends Cross[Echo](ScalaVersions.binaries: _*)
object docs extends ScalaModule with AlmondRepositories {
private def scalaVersion0 = ScalaVersions.scala213
def scalaVersion = scalaVersion0
def moduleDeps = Seq(
scala.`scala-kernel-api`(scalaVersion0)
)
def ivyDeps = Agg(
Deps.mdoc
)
def mainClass = Some("mdoc.Main")
def generate(args: String*) = T.command {
def processArgs(
npmInstall: Boolean,
yarnRunBuild: Boolean,
watch: Boolean,
relativize: Boolean,
args: List[String]
): (Boolean, Boolean, Boolean, Boolean, List[String]) =
args match {
case "--npm-install" :: rem => processArgs(true, yarnRunBuild, watch, relativize, rem)
case "--yarn-run-build" :: rem => processArgs(npmInstall, true, watch, relativize, rem)
case "--watch" :: rem => processArgs(npmInstall, yarnRunBuild, true, relativize, rem)
case "--relativize" :: rem => processArgs(npmInstall, yarnRunBuild, watch, true, rem)
case _ => (npmInstall, yarnRunBuild, watch, relativize, args)
}
val (npmInstall, yarnRunBuild, watch, relativize, args0) =
processArgs(false, false, false, false, args.toList)
val ver = scala.`scala-kernel-api`(scalaVersion0).publishVersion()
val latestRelease = settings.latestTaggedVersion
val ammVer = Deps.ammoniteReplApi(scalaVersion0).dep.version
val scalaVer = scalaVersion0
val isSnapshot = ver.endsWith("SNAPSHOT")
val extraSbt =
if (isSnapshot) """resolvers += Resolver.sonatypeRepo("snapshots")""" + "\n"
else ""
val extraCoursierArgs =
if (isSnapshot) "-r sonatype:snapshots "
else ""
val outputDir = "docs/processed-pages"
val allArgs = Seq(
"--in",
"docs/pages",
"--out",
outputDir,
"--site.VERSION",
ver,
"--site.LATEST_RELEASE",
latestRelease,
"--site.EXTRA_SBT",
extraSbt,
"--site.AMMONITE_VERSION",
ammVer,
"--site.SCALA_VERSION",
scalaVer,
"--site.SCALA212_VERSION",
ScalaVersions.scala212,
"--site.SCALA213_VERSION",
ScalaVersions.scala213,
"--site.EXTRA_COURSIER_ARGS",
extraCoursierArgs
) ++ (if (watch) Seq("--watch") else Nil) ++ args0
// TODO Run yarn run thing right after, add --watch mode
val websiteDir = os.pwd / "docs" / "website"
if (npmInstall)
Util.run(Seq("npm", "install"), dir = websiteDir.toIO)
def runMdoc(): Unit =
// adapted from https://github.com/com-lihaoyi/mill/blob/c500ca986ab79af3ce59ba65a093146672092307/scalalib/src/JavaModule.scala#L488-L494
mill.modules.Jvm.runSubprocess(
finalMainClass(),
runClasspath().map(_.path),
Nil,
forkEnv(),
allArgs,
workingDir = forkWorkingDir()
)
if (watch)
if (yarnRunBuild)
Util.withBgProcess(
Seq("yarn", "run", "start"),
dir = websiteDir.toIO,
waitFor = () => Util.waitForDir((os.pwd / outputDir.split('/').toSeq).toIO)
) {
runMdoc()
}
else
runMdoc()
else {
runMdoc()
if (yarnRunBuild)
Util.run(Seq("yarn", "run", "build"), dir = websiteDir.toIO)
if (relativize)
Relativize.relativize((websiteDir / "build").toNIO)
}
}
}
def jupyter0(args: Seq[String], fast: Boolean, console: Boolean = false) = {
val (sv, args0) = args match {
case Seq(sv, rem @ _*) if sv.startsWith("2.") || sv.startsWith("3.") =>
(sv, rem)
case _ => (ScalaVersions.scala213, args)
}
val launcher =
if (fast) scala.`scala-kernel`(sv).fastLauncher
else scala.`scala-kernel`(sv).launcher
val specialLauncher =
if (fast) scala.launcher.fastLauncher
else scala.launcher.launcher
T.command {
val jupyterDir = T.ctx().dest / "jupyter"
val launcher0 = launcher().path.toNIO
val specialLauncher0 = specialLauncher().path.toNIO
if (console)
jupyterConsole0(launcher0, specialLauncher0, jupyterDir.toNIO, args0)
else
jupyterServer(launcher0, specialLauncher0, jupyterDir.toNIO, args0)
}
}
def jupyter(args: String*) =
jupyter0(args, fast = false)
def jupyterFast(args: String*) =
jupyter0(args, fast = true)
def jupyterConsole(args: String*) =
jupyter0(args, fast = false, console = true)
def jupyterConsoleFast(args: String*) =
jupyter0(args, fast = true, console = true)
def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]) =
T.command {
val timeout = 10.minutes
val credentials = sys.env("SONATYPE_USERNAME") + ":" + sys.env("SONATYPE_PASSWORD")
val pgpPassword = sys.env("PGP_PASSWORD")
val data = T.sequence(tasks.value)()
settings.publishSonatype(
credentials = credentials,
pgpPassword = pgpPassword,
data = data,
timeout = timeout,
log = T.ctx().log
)
}
def scala212() = T.command {
println(ScalaVersions.scala212)
}
def scala213() = T.command {
println(ScalaVersions.scala213)
}
def scala3() = T.command {
println(ScalaVersions.scala3Latest)
}
def scalaVersions() = T.command {
for (sv <- ScalaVersions.all)
println(sv)
}
def launcher(scalaVersion: String = ScalaVersions.scala213) = T.command {
val launcher = scala.`scala-kernel`(scalaVersion).launcher().path.toNIO
println(launcher)
}
def specialLauncher(scalaVersion: String = ScalaVersions.scala213) = T.command {
val launcher = scala.launcher.launcher().path.toNIO
println(launcher)
}
def launcherFast(scalaVersion: String = ScalaVersions.scala213) = T.command {
val launcher = scala.`scala-kernel`(scalaVersion).fastLauncher().path.toNIO
println(launcher)
}
def specialLauncherFast(scalaVersion: String = ScalaVersions.scala213) = T.command {
val launcher = scala.launcher.fastLauncher().path.toNIO
println(launcher)
}
def ghOrg = "almond-sh"
def ghName = "almond"
object ci extends Module {
def uploadLaunchers(almondVersion: String = buildVersion) = T.command {
def ghToken() = Option(System.getenv("UPLOAD_GH_TOKEN")).getOrElse {
sys.error("UPLOAD_GH_TOKEN not set")
}
val scalaVersions = Seq(
ScalaVersions.scala212,
ScalaVersions.scala213,
ScalaVersions.scala3Latest
)
val launchers = scalaVersions.map { sv =>
val sbv = sv.split('.').take(2).mkString(".")
val output = T.dest / s"launcher-$sv"
os.proc(
"cs",
"bootstrap",
"--no-default",
"-r",
"central",
"-r",
"jitpack",
s"sh.almond:scala-kernel_$sv:$almondVersion",
"--shared",
s"sh.almond:scala-kernel-api_$sv",
"-o",
output
).call(stdin = os.Inherit, stdout = os.Inherit)
(output, s"almond-scala-$sbv")
}
val (tag, overwriteAssets) =
if (almondVersion.endsWith("-SNAPSHOT")) ("nightly", true)
else ("v" + almondVersion, false)
Upload.upload(ghOrg, ghName, ghToken(), tag, dryRun = false, overwrite = overwriteAssets)(
launchers: _*
)
}
}
object dummy extends Module {
// dummy module to get Scala Steward updates for ammonite-spark
object `amm-spark` extends ScalaModule {
def scalaVersion = ScalaVersions.scala212
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.ammoniteSpark
)
}
}