-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sbt
225 lines (206 loc) · 7.01 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
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
import org.scalajs.linker.interface.Report
import org.scalajs.linker.interface.OutputPatterns
val unusedWarnings = Seq(
"-Ywarn-unused",
)
def Scala213 = "2.13.15"
val metaScalafixCompat = MetaCross("-scalafix-compat", "-scalafix_compat")
val metaLatest = MetaCross("-latest", "-latest")
lazy val commonSettings = Def.settings(
scalaVersion := Scala213,
licenses := Seq("MIT License" -> url("https://opensource.org/licenses/mit-license")),
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-Xlint",
"-language:existentials",
),
scalacOptions ++= unusedWarnings,
Seq(Compile, Test).flatMap(c => c / console / scalacOptions --= unusedWarnings),
)
commonSettings
lazy val commonLatest = Def.settings(
Compile / sources ++= {
(((Compile / sourceDirectory).value / "scala-latest") ** "*.scala").get
}
)
lazy val `scalameta-ast` = projectMatrix
.in(file("core"))
.settings(
name := "scalameta-ast",
commonSettings,
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest-freespec" % "3.2.19" % Test,
),
)
.jvmPlatform(
scalaVersions = Scala213 :: Nil,
settings = Def.settings(
metaVersion := (LocalProject("scalameta-ast-latestJS") / metaVersion).value,
testBuildInfo,
commonLatest,
libraryDependencies += "org.scalameta" %%% "scalameta" % "4.10.2",
libraryDependencies += "org.scalameta" %%% "scalafmt-core" % "3.8.3",
libraryDependencies += "com.google.inject" % "guice" % "7.0.0" % Test,
Test / resourceGenerators += Def.task {
val v1 = (LocalProject("scalameta-ast-latestJS") / metaTreesSource).value
val v2 = (LocalProject("scalameta-ast-scalafix-compatJS") / metaTreesSource).value
Seq(v1, v2).zipWithIndex.map { case (src, index) =>
val f = (Test / resourceManaged).value / s"trees${index}.scala"
IO.write(f, src)
f
}
},
)
)
.jsPlatform(
scalaVersions = Scala213 :: Nil,
axisValues = Seq(metaScalafixCompat),
settings = Def.settings(
jsProjectSettings,
libraryDependencies += {
("org.scalameta" %%% "scalameta" % "4.6.0").withSources() // scala-steward:off
}
)
)
.jsPlatform(
scalaVersions = Scala213 :: Nil,
axisValues = Seq(metaLatest),
settings = Def.settings(
jsProjectSettings,
commonLatest,
libraryDependencies += "org.ekrich" %%% "sconfig" % "1.8.1",
libraryDependencies += ("com.github.xuwei-k" %%% "scalafmt-core" % "3.8.3-fork-2").withSources(),
)
)
lazy val metaVersion = taskKey[String]("")
lazy val metaTreesSource = taskKey[String]("")
lazy val testBuildInfo = {
Test / sourceGenerators += Def.task {
val x = "ScalametaASTTestBuildInfo"
val f = (Test / sourceManaged).value / s"${x}.scala"
IO.write(
f,
s"""|package scalameta_ast
|
|object ${x} {
| def scalametaVersion: String = "${metaVersion.value}"
|}
|""".stripMargin
)
f :: Nil
}
}
lazy val jsProjectSettings: Def.SettingsDefinition = Def.settings(
scalaJSLinkerConfig ~= {
_.withESFeatures(_.withESVersion(org.scalajs.linker.interface.ESVersion.ES2018))
},
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
genBuildInfo := {
val hash = sys.process.Process("git rev-parse HEAD").lineStream_!.head
s"""{
| "gitHash" : "$hash",
| "scalametaVersion" : "${metaVersion.value}"
|}
|""".stripMargin
},
Seq(Compile, Test).map { x =>
x / unmanagedSourceDirectories += {
(x / scalaSource).value / ".." / "js"
}
},
libraryDependencies += "org.ekrich" %%% "sjavatime" % "1.3.0",
metaTreesSource := {
val v = metaVersion.value
val s = scalaBinaryVersion.value
val p = s"https/repo1.maven.org/maven2/org/scalameta/trees_sjs1_${s}/${v}/trees_sjs1_${s}-${v}-sources.jar"
val sourceJar = csrCacheDirectory.value / p
IO.withTemporaryDirectory { dir =>
val file :: Nil = IO.unzip(sourceJar, dir, _ == "scala/meta/Trees.scala").toList
IO.read(file)
}
},
testBuildInfo,
metaVersion := {
val s = scalaBinaryVersion.value
val x1 = s"https/repo1.maven.org/maven2/org/scalameta/parsers_sjs1_${s}/"
val x2 = s"/parsers_sjs1_${s}-"
val Seq(jarPath) = (Compile / externalDependencyClasspath).value
.map(_.data.getAbsolutePath)
.filter(path => path.contains(x1) && path.contains(x2))
jarPath.split(x1).last.split(x2).head
},
Test / scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.ESModule).withOutputPatterns(OutputPatterns.fromJSFile("%s.mjs"))
},
scalacOptions += {
val a = (LocalRootProject / baseDirectory).value.toURI.toString
val g = "https://raw.githubusercontent.com/xuwei-k/scalameta-ast/" + sys.process
.Process("git rev-parse HEAD")
.lineStream_!
.head
s"-P:scalajs:mapSourceURI:$a->$g/"
},
)
val genBuildInfo = taskKey[String]("")
lazy val localServer = project.settings(
commonSettings,
run / fork := true,
run / baseDirectory := (LocalRootProject / baseDirectory).value,
Test / testOptions += Tests.Argument("-oDF"),
Test / test := (Test / test).dependsOn(LocalRootProject / copyFilesFull).value,
Test / testOptions ++= {
if (scala.util.Properties.isMac) {
Nil
} else {
Seq(
Tests.Exclude(
Seq(
"scalameta_ast.IntegrationTestWebkit",
)
)
)
}
},
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-simple" % "2.0.16" % Runtime,
"ws.unfiltered" %% "unfiltered-filter" % "0.12.0",
"ws.unfiltered" %% "unfiltered-jetty" % "0.12.0",
"org.scalatest" %%% "scalatest-freespec" % "3.2.19" % Test,
"com.microsoft.playwright" % "playwright" % "1.49.0" % Test,
)
)
val srcDir = (LocalRootProject / baseDirectory).apply(_ / "sources")
val scalafixCompatOutJSDir = srcDir(_ / "scalafix-compat")
val latestOutJSDir = srcDir(_ / "latest")
cleanFiles += scalafixCompatOutJSDir.value
cleanFiles += latestOutJSDir.value
def cp(
c: MetaCross,
d: Def.Initialize[File],
k: TaskKey[Attributed[Report]],
originalOutputDir: TaskKey[File]
): Def.Initialize[Task[Unit]] = Def.taskDyn {
val Seq(p) = `scalameta-ast`.finder(c, VirtualAxis.js).get
Def.task {
val v = (p / Compile / k).value
val Seq(m) = v.data.publicModules.toSeq
val src = (p / Compile / originalOutputDir).value
val f = src / m.jsFileName
val srcMap = src / m.sourceMapName.getOrElse(sys.error("source map not found"))
IO.write(d.value / "build_info.json", (p / genBuildInfo).value)
IO.copyFile(f, d.value / m.jsFileName)
IO.copyFile(srcMap, d.value / srcMap.getName)
}
}
val copyFilesFull = taskKey[Unit]("")
TaskKey[Unit]("copyFilesFast") := {
cp(metaScalafixCompat, scalafixCompatOutJSDir, fastLinkJS, fastLinkJSOutput).value
cp(metaLatest, latestOutJSDir, fastLinkJS, fastLinkJSOutput).value
}
copyFilesFull := {
cp(metaScalafixCompat, scalafixCompatOutJSDir, fullLinkJS, fullLinkJSOutput).value
cp(metaLatest, latestOutJSDir, fullLinkJS, fullLinkJSOutput).value
}
publish := {}
publishLocal := {}