/
BuildCommons.scala
267 lines (229 loc) · 8.79 KB
/
BuildCommons.scala
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
import sbt._
import Keys._
import java.io.PrintWriter
import scala.io.Source
import scalanative.sbtplugin.ScalaNativePlugin
import ScalaNativePlugin.autoImport.{nativeLinkStubs, nativeDump}
trait BuildCommons {
lazy val scalaVersionsSettings: Seq[Setting[_]] = Seq(
crossScalaVersions := Seq("2.13.10", "2.12.17", "2.11.12", "2.10.7"),
scalaVersion := crossScalaVersions.value.head,
)
val runFlickerTests = Option(System.getenv("SCALATEST_RUN_FLICKER_TESTS")).getOrElse("FALSE").toUpperCase == "TRUE"
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).getOrElse("1.8.0")
def scalatestJSLibraryDependencies =
Seq(
"org.scala-js" %% "scalajs-test-interface" % scalaJSVersion
)
val releaseVersion = "3.2.14"
val previousReleaseVersion = "3.2.13"
val plusJUnitVersion = "3.2.10.0"
val plusTestNGVersion = "3.2.10.0"
val flexmarkVersion = "0.62.2"
def rootProject: Project
def scalatestCompatible: Project
def scalaXmlDependency(theScalaVersion: String): Seq[ModuleID]
def scalatestLibraryDependencies: Seq[ModuleID]
def scalaLibraries(theScalaVersion: String): Seq[ModuleID]
def sharedSettings: Seq[Setting[_]]
def scalacticDocSettings: Seq[Setting[_]]
def scalatestDocSettings: Seq[Setting[_]]
def scalatestJSDocTaskSetting: Setting[_]
def crossBuildTestLibraryDependencies: sbt.Def.Initialize[Seq[sbt.ModuleID]]
lazy val projectTitle = settingKey[String]("Name of project to display in doc titles")
val javaSourceManaged: SettingKey[java.io.File] = sbt.SettingKey[java.io.File]("javaSourceManaged")
//
// Prepares source files for running scaladoc.
//
def genDocSources(srcFiles: Seq[File],
srcDirs: Seq[File],
docsrcDir: File): Seq[File] =
{
val scalaFiles =
for {
srcFile <- srcFiles
if srcFile.name.endsWith(".scala")
} yield {
val srcPath = srcFile.getPath
val maybeSourceFile = srcDirs.flatMap(srcFile.relativeTo).headOption
maybeSourceFile match {
case Some(docsrcFile) => copyDocFile(srcFile, new File(docsrcDir.asFile, docsrcFile.getPath))
case None =>
throw new RuntimeException("unexpected source path ["+ srcPath +"] not relative to " + srcDirs.mkString("[", ", ", "]"))
}
}
val javaSources = srcFiles.filter(_.name.endsWith(".java")).toSet
val javaTagFiles = JavaTagDocumenter.docJavaTags(javaSources)
scalaFiles ++ javaTagFiles
}
//
// Copies a file, doing a little filtering along the way to make
// destination file suitable for use in generating scaladocs.
//
// Returns destination file.
//
private def copyDocFile(srcFile: File, destFile: File): File = {
if (!destFile.exists || (destFile.lastModified < srcFile.lastModified)) {
IO.createDirectory(file(destFile.getParent))
val writer = new PrintWriter(destFile)
try {
for (line <- Source.fromFile(srcFile).getLines)
writer.println(line.replaceFirst("@Finders(.*)", ""))
}
finally { writer.close }
}
destFile
}
//
// Adds customization to scaladocs.
//
// Appends additional css to template.css file and copies
// additional gifs into lib directory.
//
// Note: found that adding new gifs into lib directory causes
// doc task to rebuild scaladocs from scratch each time.
// Without that it only rebuilds if needed.
//
def docTask(docDir: File, resDir: File, projectName: String): File = {
val docLibDir = docDir / "lib"
val htmlSrcDir = resDir / "html"
val cssFile = docLibDir / "template.css"
val addlCssFile = htmlSrcDir / "addl.css"
val css = Source.fromFile(cssFile).mkString
val addlCss = Source.fromFile(addlCssFile).mkString
if (!css.contains("pre.stHighlighted")) {
val writer = new PrintWriter(cssFile)
try {
writer.println(css)
writer.println(addlCss)
}
finally { writer.close }
}
if (projectName.contains("scalatest")) {
(htmlSrcDir * "*.gif").get.foreach { gif =>
IO.copyFile(gif, docLibDir / gif.name)
}
}
docDir
}
lazy val docsrcDir =
settingKey[File](
"Directory to hold processed source files for generating scaladocs")
val docsrcDirSetting =
docsrcDir := target.value / "docsrc"
val docTaskSetting =
doc in Compile := docTask((doc in Compile).value,
(sourceDirectory in Compile).value,
name.value)
def scalatestTestOptions =
Seq(
Tests.Argument(TestFrameworks.ScalaTest,
(
Seq(
"-l", "org.scalatest.tags.Slow",
"-m", "org.scalatest",
"-m", "org.scalactic",
"-m", "org.scalactic.anyvals",
"-m", "org.scalactic.algebra",
"-m", "org.scalactic.enablers",
"-m", "org.scalatest.fixture",
"-m", "org.scalatest.concurrent",
"-m", "org.scalatest.deprecated",
"-m", "org.scalatest.events",
"-m", "org.scalatest.prop",
"-m", "org.scalatest.tools",
"-m", "org.scalatest.matchers",
"-m", "org.scalatest.matchers.should",
"-m", "org.scalatest.matchers.must",
"-m", "org.scalatest.matchers.dsl",
"-m", "org.scalatest.verbs",
"-m", "org.scalatest.suiteprop",
"-m", "org.scalatest.path",
"-m", "org.scalatest.exceptions",
"-m", "org.scalatest.time",
"-m", "org.scalatest.words",
"-m", "org.scalatest.enablers",
"-m", "org.scalatest.expectations",
"-m", "org.scalatest.diagrams",
"-m", "org.scalatest.featurespec",
"-m", "org.scalatest.flatspec",
"-m", "org.scalatest.freespec",
"-m", "org.scalatest.funspec",
"-m", "org.scalatest.funsuite",
"-m", "org.scalatest.propspec",
"-m", "org.scalatest.wordspec",
"-oDIF",
"-W", "120", "60",
"-h", "target/html",
"-u", "target/junit",
"-fW", "target/result.txt"
) ++
(if (runFlickerTests) Seq.empty[String] else Seq("-l", "org.scalatest.tags.Flicker"))
): _*
)
)
def scalatestTestJSNativeOptions =
Seq(
Tests.Argument(TestFrameworks.ScalaTest,
(
Seq(
"-l", "org.scalatest.tags.Slow",
"-m", "org.scalatest",
"-m", "org.scalactic",
"-m", "org.scalactic.anyvals",
"-m", "org.scalactic.algebra",
"-m", "org.scalactic.enablers",
"-m", "org.scalatest.fixture",
"-m", "org.scalatest.concurrent",
"-m", "org.scalatest.events",
"-m", "org.scalatest.prop",
"-m", "org.scalatest.tools",
"-m", "org.scalatest.matchers",
"-m", "org.scalatest.matchers",
"-m", "org.scalatest.matchers.should",
"-m", "org.scalatest.matchers.must",
"-m", "org.scalatest.matchers.dsl",
"-m", "org.scalatest.verbs",
"-m", "org.scalatest.suiteprop",
"-m", "org.scalatest.path",
"-m", "org.scalatest.exceptions",
"-m", "org.scalatest.time",
"-m", "org.scalatest.words",
"-m", "org.scalatest.enablers",
"-m", "org.scalatest.expectations",
"-m", "org.scalatest.diagrams",
"-m", "org.scalatest.featurespec",
"-m", "org.scalatest.flatspec",
"-m", "org.scalatest.freespec",
"-m", "org.scalatest.funspec",
"-m", "org.scalatest.funsuite",
"-m", "org.scalatest.propspec",
"-m", "org.scalatest.wordspec",
"-oDIF"
) ++
(if (runFlickerTests) Seq.empty[String] else Seq("-l", "org.scalatest.tags.Flicker"))
): _*
)
)
def nativeCrossBuildLibraryDependencies = Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 10)) => Seq.empty
case Some((2, 11)) => Seq(("org.scala-lang.modules" %% "scala-xml" % "1.3.0"))
case Some((scalaEpoch, scalaMajor)) if (scalaEpoch == 2 && scalaMajor >= 12) || scalaEpoch == 3 =>
Seq(("org.scala-lang.modules" %% "scala-xml" % "2.1.0"))
}
}
def sharedTestSettingsNative: Seq[Setting[_]] =
Seq(
organization := "org.scalatest",
libraryDependencies ++= nativeCrossBuildLibraryDependencies.value,
// libraryDependencies += "io.circe" %%% "circe-parser" % "0.7.1" % "test",
fork in test := false,
nativeLinkStubs in Test := true,
nativeDump in Test := false,
testOptions in Test := scalatestTestJSNativeOptions,
publishArtifact := false,
publish := {},
publishLocal := {}
)
}