forked from mipt-scala-course/23-master
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sbt
More file actions
130 lines (117 loc) · 3.83 KB
/
build.sbt
File metadata and controls
130 lines (117 loc) · 3.83 KB
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
import org.typelevel.scalacoptions.{ScalaVersion, ScalacOption, ScalacOptions}
import deps.*
import sbt.internal.*
import StateSyntax.*
import sbt.Project.projectToRef
import scala.Ordering.Implicits.*
import sbtprojectmatrix.ProjectMatrixKeys
import scala.sys.process.Process
ThisBuild / organization := "ru.tinkoff"
ThisBuild / organizationName := "Tinkoff"
ThisBuild / scalaVersion := scalac.v3
lazy val scala2Versions = List(scalac.v2_13)
lazy val scala3Versions = List(scalac.v3)
lazy val scala2And3Versions = scala3Versions ++ scala2Versions
lazy val commonSettings = Seq(
tpolecatExcludeOptions ++= Set(ScalacOptions.privateKindProjector),
tpolecatScalacOptions ++= Set(
ScalacOption("-Ykind-projector:underscores", _.isAtLeast(ScalaVersion.V3_0_0)),
ScalacOption("-P:kind-projector:underscore-placeholders", _ < ScalaVersion.V3_0_0),
ScalacOptions.source3,
ScalacOption("-Xmigration", _ < ScalaVersion.V3_0_0),
ScalacOptions.warnOption("macros:after", v => v.isAtLeast(ScalaVersion.V2_13_0) && v < ScalaVersion.V3_0_0),
ScalacOptions.privateOption("macro-annotations", v => v.isAtLeast(ScalaVersion.V2_13_0) && v < ScalaVersion.V3_0_0),
ScalacOptions.privatePartialUnification
),
tpolecatExcludeOptions += ScalacOptions.privateWarnUnusedNoWarn,
tpolecatExcludeOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => Set(ScalacOptions.warnUnusedLocals)
case _ => Set()
}
},
Test / tpolecatExcludeOptions ++= Set(
ScalacOptions.warnUnusedLocals,
ScalacOptions.fatalWarnings,
ScalacOptions.privateWarnUnusedLocals
),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
Seq(
compilerPlugin(deps.kindProjector),
compilerPlugin(deps.bmFor)
)
case _ => Seq()
}
},
publish / skip := true
)
val s201name = "s2-01-scala3-overview"
lazy val `s2-01-scala3-overview` = (projectMatrix in file(s"modules/$s201name"))
.settings(commonSettings)
.settings(
name := s201name,
libraryDependencies ++= Seq(
circe.core,
munit % Test
)
)
.jvmPlatform(scala2And3Versions)
val s202name = "s2-02-metaprogramming-1"
lazy val `s2-02-metaprogramming-1` = (project in file(s"modules/$s202name"))
.settings(commonSettings)
.settings(
name := s202name,
libraryDependencies ++= Seq(
circe.core,
munit % Test
)
)
val s203name = "s2-03-metaprogramming-2"
lazy val `s2-03-metaprogramming-2` = (project in file(s"modules/$s203name"))
.settings(commonSettings)
.settings(
name := s203name,
libraryDependencies ++= Seq(
circe.core,
circe.parse,
munit % Test
)
)
lazy val allModules =
Seq(
`s2-01-scala3-overview`, // cross build projects
).flatMap(_.projectRefs) ++ Seq(
`s2-02-metaprogramming-1`, // scala 3 only projects
`s2-03-metaprogramming-2`
).map(projectToRef)
lazy val `root` = (project in file("."))
.settings(
name := "root",
publish / skip := true
)
.aggregate(allModules: _*)
// map task -> module to compile
lazy val moduleKeys: Map[String, String] = {
List(
s202name,
s203name,
).map(x => x.take(5) -> x).toMap + (
"s2-01" -> (s201name + "3") // 3 is for scala3 module in sbt matrix, only for cross-build modules
)
}
commands += Command.command("hw") { state =>
val branch = Process("git rev-parse --abbrev-ref HEAD").lineStream.headOption
val pattern = """solution-(s\d-\d\d).*""".r
branch.flatMap {
case pattern(x) =>
val key = moduleKeys.get(x)
if (key.isEmpty)
sLog.value.warn(s"WARN: Current branch starts with 'solution-' prefix, but $x doesn't correspond to any module")
key
case _ => None
}.fold(
runCommand("test", state)
)(m => runCommand(s"$m / test", state))
}