-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.sbt
197 lines (172 loc) · 6.21 KB
/
build.sbt
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
import sbt.Keys.libraryDependencies
import sbt.internal.util.ManagedLogger
import org.scalajs.jsenv.nodejs.NodeJSEnv
val usedScalaCompiler = "3.6.2"
val usedTastyRelease = usedScalaCompiler
val scala2Version = "2.13.14"
val SourceDeps = config("sourcedeps").hide
val rtJarOpt = taskKey[Option[String]]("Path to rt.jar if it exists")
val javalibEntry = taskKey[String]("Path to rt.jar or \"jrt:/\"")
inThisBuild(Def.settings(
crossScalaVersions := Seq(usedScalaCompiler),
scalaVersion := usedScalaCompiler,
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-encoding",
"utf-8",
),
scmInfo := Some(
ScmInfo(
url("https://github.com/scalacenter/tasty-query"),
"scm:git@github.com:scalacenter/tasty-query.git",
Some("scm:git:git@github.com:scalacenter/tasty-query.git")
)
),
organization := "ch.epfl.scala",
homepage := Some(url(s"https://github.com/scalacenter/tasty-query")),
licenses += (("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0"))),
developers := List(
Developer("sjrd", "Sébastien Doeraene", "sjrdoeraene@gmail.com", url("https://github.com/sjrd/")),
Developer("bishabosha", "Jamie Thompson", "bishbashboshjt@gmail.com", url("https://github.com/bishabosha")),
),
versionPolicyIntention := Compatibility.BinaryAndSourceCompatible,
// Ignore dependencies to internal modules whose version is like `1.2.3+4...` (see https://github.com/scalacenter/sbt-version-policy#how-to-integrate-with-sbt-dynver)
versionPolicyIgnoredInternalDependencyVersions := Some("^\\d+\\.\\d+\\.\\d+\\+\\d+".r)
))
val commonSettings = Seq(
Test / parallelExecution := false,
// Skip `versionCheck` for snapshot releases
versionCheck / skip := isSnapshot.value
)
val strictCompileSettings = Seq(
scalacOptions ++= Seq(
"-Xfatal-warnings",
"-Yexplicit-nulls",
"-Wsafe-init",
"-source:future",
),
)
lazy val root = project.in(file("."))
.aggregate(tastyQuery.js, tastyQuery.jvm).settings(
publish / skip := true,
)
lazy val scala2TestSources = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("scala2-test-sources"))
.settings(commonSettings)
.settings(
scalaVersion := scala2Version,
publish / skip := true,
scalacOptions += "-Xfatal-warnings",
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided",
)
lazy val testSources = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("test-sources"))
.settings(commonSettings)
.settings(
publish / skip := true,
scalacOptions += "-Xfatal-warnings",
javacOptions += "-parameters",
)
.dependsOn(scala2TestSources)
lazy val tastyQuery =
crossProject(JSPlatform, JVMPlatform).in(file("tasty-query"))
.dependsOn(testSources % Test)
.settings(commonSettings)
.settings(strictCompileSettings)
.settings(name := "tasty-query")
.settings(
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.0" % Test,
testFrameworks += new TestFramework("munit.Framework")
)
.settings(
Test / rtJarOpt := {
for (bootClasspath <- Option(System.getProperty("sun.boot.class.path"))) yield {
val rtJarOpt = bootClasspath.split(java.io.File.pathSeparatorChar).find { path =>
new java.io.File(path).getName() == "rt.jar"
}
rtJarOpt match {
case Some(rtJar) =>
rtJar
case None =>
throw new AssertionError(s"cannot find rt.jar in $bootClasspath")
}
}
},
Test / envVars ++= {
val javalib = (Test / javalibEntry).value
val testSourcesCP = Attributed.data((testSources.jvm / Compile / fullClasspath).value)
val testClasspath = (javalib +: testSourcesCP.map(_.getAbsolutePath())).mkString(";")
val testResourcesCode =
((LocalRootProject / baseDirectory).value / "test-sources/src").getAbsolutePath()
Map(
"TASTY_TEST_CLASSPATH" -> testClasspath,
"TASTY_TEST_SOURCES" -> testResourcesCode,
)
},
mimaBinaryIssueFilters ++= {
import com.typesafe.tools.mima.core.*
Seq(
)
},
tastyMiMaPreviousArtifacts := mimaPreviousArtifacts.value,
tastyMiMaTastyQueryVersionOverride := Some("1.5.0"),
tastyMiMaConfig ~= { prev =>
import tastymima.intf._
prev
.withMoreArtifactPrivatePackages(java.util.Arrays.asList(
"tastyquery",
))
},
)
.jvmSettings(
fork := true,
Test / javalibEntry := (Test / rtJarOpt).value.getOrElse("jrt:/modules/java.base/"),
)
.jsSettings(
Test / javalibEntry := {
val rtJar = (Test / rtJarOpt).value
val s = streams.value
val targetRTJar = target.value / "extracted-rt.jar"
rtJar.getOrElse {
if (!targetRTJar.exists()) {
s.log.info(s"Extracting jrt:/modules/java.base/ to $targetRTJar")
extractRTJar(targetRTJar)
}
targetRTJar.getAbsolutePath()
}
},
scalaJSUseMainModuleInitializer := true,
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
jsEnv := new NodeJSEnv(NodeJSEnv.Config().withArgs(List("--enable-source-maps"))),
)
def extractRTJar(targetRTJar: File): Unit = {
import java.io.{IOException, FileOutputStream}
import java.nio.file.{Files, FileSystems}
import java.util.zip.{ZipEntry, ZipOutputStream}
import scala.jdk.CollectionConverters._
import scala.util.control.NonFatal
val fs = FileSystems.getFileSystem(java.net.URI.create("jrt:/"))
val zipStream = new ZipOutputStream(new FileOutputStream(targetRTJar))
try {
val javaBasePath = fs.getPath("modules", "java.base")
Files.walk(javaBasePath).forEach({ p =>
if (Files.isRegularFile(p)) {
try {
val data = Files.readAllBytes(p)
val outPath = javaBasePath.relativize(p).iterator().asScala.mkString("/")
val ze = new ZipEntry(outPath)
zipStream.putNextEntry(ze)
zipStream.write(data)
} catch {
case NonFatal(t) =>
throw new IOException(s"Exception while extracting $p", t)
}
}
})
} finally {
zipStream.close()
}
}