Skip to content

Commit b3d18fe

Browse files
authored
Merge pull request #1650 from rvacaru/reflect3
scalafix-cli_3 & test dependencies (GSoC 2022)
2 parents 03d6768 + d15af9a commit b3d18fe

File tree

41 files changed

+615
-376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+615
-376
lines changed

build.sbt

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ lazy val core = projectMatrix
8484
}
8585
)
8686
.defaultAxes(VirtualAxis.jvm)
87-
.jvmPlatform(buildScalaVersions :+ scala3, Seq(), p => p)
87+
.jvmPlatform(buildScalaVersions)
8888
.enablePlugins(BuildInfoPlugin)
8989

9090
lazy val rules = projectMatrix
@@ -105,7 +105,7 @@ lazy val rules = projectMatrix
105105
}
106106
)
107107
.defaultAxes(VirtualAxis.jvm)
108-
.jvmPlatform(buildScalaVersions :+ scala3, Seq(), p => p)
108+
.jvmPlatform(buildScalaVersions)
109109
.dependsOn(core)
110110
.enablePlugins(BuildInfoPlugin)
111111

@@ -114,10 +114,18 @@ lazy val reflect = projectMatrix
114114
.settings(
115115
moduleName := "scalafix-reflect",
116116
isFullCrossVersion,
117-
libraryDependencies ++= Seq(
118-
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
119-
"org.scala-lang" % "scala-reflect" % scalaVersion.value
120-
)
117+
libraryDependencies ++= {
118+
if (!isScala3.value)
119+
List(
120+
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
121+
"org.scala-lang" % "scala-reflect" % scalaVersion.value
122+
)
123+
else
124+
List(
125+
"org.scala-lang" %% "scala3-compiler" % scalaVersion.value,
126+
"org.scala-lang" %% "scala3-library" % scalaVersion.value
127+
)
128+
}
121129
)
122130
.defaultAxes(VirtualAxis.jvm)
123131
.jvmPlatform(buildScalaVersions)
@@ -129,13 +137,18 @@ lazy val cli = projectMatrix
129137
moduleName := "scalafix-cli",
130138
isFullCrossVersion,
131139
libraryDependencies ++= Seq(
132-
java8Compat,
133140
nailgunServer,
134141
jgit,
135142
commonText
136143
),
137144
libraryDependencies ++= {
138-
if (isScala211.value) Seq()
145+
if (!isScala3.value)
146+
Seq(java8Compat)
147+
else
148+
Seq()
149+
},
150+
libraryDependencies ++= {
151+
if (isScala211.value || isScala3.value) Seq()
139152
else
140153
Seq(
141154
// metaconfig 0.10.0 shaded pprint but rules built with an old
@@ -160,7 +173,7 @@ lazy val testsShared = projectMatrix
160173
coverageEnabled := false
161174
)
162175
.defaultAxes(VirtualAxis.jvm)
163-
.jvmPlatform(testTargetScalaVersions)
176+
.jvmPlatform(buildScalaVersions)
164177
.disablePlugins(ScalafixPlugin)
165178

166179
lazy val testsInput = projectMatrix
@@ -176,7 +189,7 @@ lazy val testsInput = projectMatrix
176189
coverageEnabled := false
177190
)
178191
.defaultAxes(VirtualAxis.jvm)
179-
.jvmPlatform(testTargetScalaVersions)
192+
.jvmPlatform(buildScalaVersions)
180193
.disablePlugins(ScalafixPlugin)
181194

182195
lazy val testsOutput = projectMatrix
@@ -188,18 +201,16 @@ lazy val testsOutput = projectMatrix
188201
coverageEnabled := false
189202
)
190203
.defaultAxes(VirtualAxis.jvm)
191-
.jvmPlatform(testTargetScalaVersions)
204+
.jvmPlatform(buildScalaVersions)
192205
.disablePlugins(ScalafixPlugin)
193206

194207
lazy val testkit = projectMatrix
195208
.in(file("scalafix-testkit"))
196209
.settings(
197210
moduleName := "scalafix-testkit",
198211
isFullCrossVersion,
199-
libraryDependencies ++= Seq(
200-
googleDiff,
201-
scalatest
202-
)
212+
libraryDependencies += googleDiff,
213+
libraryDependencies += scalatestDep.value
203214
)
204215
.defaultAxes(VirtualAxis.jvm)
205216
.jvmPlatform(buildScalaVersions)
@@ -211,18 +222,32 @@ lazy val unit = projectMatrix
211222
noPublishAndNoMima,
212223
// Change working directory to match when `fork := false`.
213224
Test / baseDirectory := (ThisBuild / baseDirectory).value,
225+
// Prevent issues with scalatest serialization
226+
Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat,
214227
javaOptions := Nil,
215-
testFrameworks += new TestFramework("munit.Framework"),
216-
buildInfoPackage := "scalafix.tests",
217-
buildInfoObject := "BuildInfo",
218228
libraryDependencies ++= List(
219229
jgit,
220-
coursier,
221-
scalatest.withRevision(
222-
"3.2.13"
223-
), // make sure testkit clients can use recent 3.x versions
224-
scalametaTeskit
230+
munit,
231+
scalatest.withRevision(scalatestLatestV)
225232
),
233+
libraryDependencies ++= {
234+
if (!isScala3.value) {
235+
List(
236+
coursier,
237+
scalametaTeskit
238+
)
239+
} else {
240+
// exclude _2.13 artifacts that have their _3 counterpart in the classpath
241+
List(
242+
coursier
243+
.exclude("org.scala-lang.modules", "scala-xml_2.13"),
244+
scalametaTeskit
245+
.exclude("com.lihaoyi", "sourcecode_2.13")
246+
.exclude("org.scala-lang.modules", "scala-collection-compat_2.13")
247+
.exclude("org.scalameta", "munit_2.13")
248+
)
249+
}
250+
},
226251
Compile / compile / compileInputs := {
227252
(Compile / compile / compileInputs)
228253
.dependsOn(
@@ -277,8 +302,11 @@ lazy val unit = projectMatrix
277302
IO.write(props, "Input data for scalafix testkit", out)
278303
List(out)
279304
},
305+
buildInfoPackage := "scalafix.tests",
306+
buildInfoObject := "BuildInfo",
280307
buildInfoKeys := Seq[BuildInfoKey](
281308
"scalametaVersion" -> scalametaV,
309+
"scalaVersion" -> scalaVersion.value,
282310
"baseDirectory" ->
283311
(ThisBuild / baseDirectory).value,
284312
"unitResourceDirectory" -> (Compile / resourceDirectory).value,
@@ -313,6 +341,11 @@ lazy val unit = projectMatrix
313341
}
314342
)
315343
.defaultAxes(VirtualAxis.jvm)
344+
.jvmPlatform(
345+
scalaVersions = Seq(scala3),
346+
axisValues = Seq(TargetAxis(scala3)),
347+
settings = Seq()
348+
)
316349
.jvmPlatform(
317350
scalaVersions = Seq(scala212),
318351
axisValues = Seq(TargetAxis(scala3)),

project/Dependencies.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Dependencies {
1212
val scala213 = "2.13.10"
1313
val scala3 = "3.1.3"
1414

15-
val buildScalaVersions = Seq(scala211, scala212, scala213)
15+
val buildScalaVersions = Seq(scala211, scala212, scala213, scala3)
1616
val testTargetScalaVersions = Seq(scala211, scala212, scala213, scala3)
1717

1818
// we support 3 last binary versions of scala212 and scala213
@@ -34,12 +34,15 @@ object Dependencies {
3434
val scalaXmlV = "2.1.0"
3535
val scalaXml211V = "1.3.0" // scala-xml stops publishing for scala 2.11
3636
val scalametaV = "4.6.0"
37-
val scalatestV = "3.0.8" // don't bump, to avoid forcing breaking changes on clients via eviction
37+
val scalatestMinV = "3.0.8" // don't bump, to avoid forcing breaking changes on clients via eviction
38+
val scalatestLatestV = "3.2.13"
39+
val munitV = "0.7.29"
3840

3941
val bijectionCore = "com.twitter" %% "bijection-core" % bijectionCoreV
4042
val collectionCompat = "org.scala-lang.modules" %% "scala-collection-compat" % collectionCompatV
4143
val commonText = "org.apache.commons" % "commons-text" % commontTextV
42-
val coursier = "io.get-coursier" %% "coursier" % coursierV
44+
val coursier = ("io.get-coursier" %% "coursier" % coursierV)
45+
.cross(CrossVersion.for3Use2_13)
4346
val coursierInterfaces = "io.get-coursier" % "interface" % coursierInterfaceV
4447
val googleDiff = "com.googlecode.java-diff-utils" % "diffutils" % googleDiffV
4548
val java8Compat = "org.scala-lang.modules" %% "scala-java8-compat" % java8CompatV
@@ -56,8 +59,10 @@ object Dependencies {
5659
// https://github.com/scalameta/scalameta/issues/2485
5760
val scalameta = ("org.scalameta" %% "scalameta" % scalametaV)
5861
.cross(CrossVersion.for3Use2_13)
59-
val scalametaTeskit = "org.scalameta" %% "testkit" % scalametaV
60-
val scalatest = "org.scalatest" %% "scalatest" % scalatestV
62+
val scalametaTeskit = ("org.scalameta" %% "testkit" % scalametaV)
63+
.cross(CrossVersion.for3Use2_13)
64+
val scalatest = "org.scalatest" %% "scalatest" % scalatestMinV
65+
val munit = "org.scalameta" %% "munit" % munitV
6166
val semanticdbScalacCore = "org.scalameta" % "semanticdb-scalac-core" % scalametaV cross CrossVersion.full
6267

6368
private def previousVersions(scalaVersion: String): List[String] = {

project/ScalafixBuild.scala

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
121121
lazy val buildInfoSettingsForRules: Seq[Def.Setting[_]] = Seq(
122122
buildInfoObject := "RulesBuildInfo"
123123
)
124+
125+
lazy val scalatestDep = Def.setting {
126+
if (isScala3.value) scalatest.withRevision(scalatestLatestV)
127+
else scalatest
128+
}
124129
}
125130

126131
import autoImport._
@@ -140,8 +145,7 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
140145
},
141146
commands += Command.command("ci-3") { s =>
142147
"unit2_12Target3/test" ::
143-
"core3/compile" ::
144-
"rules3/compile" ::
148+
"unit3Target3/test" ::
145149
s
146150
},
147151
commands += Command.command("ci-213") { s =>
@@ -218,8 +222,17 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
218222
Compile / doc / scalacOptions ++= scaladocOptions,
219223
Compile / unmanagedSourceDirectories ++= {
220224
val sourceDir = (Compile / sourceDirectory).value
225+
val scala212PlusSourceDir = "scala-2.12+"
226+
CrossVersion.partialVersion(scalaVersion.value) match {
227+
case Some((2, n)) if n >= 12 => Seq(sourceDir / scala212PlusSourceDir)
228+
case Some((3, _)) => Seq(sourceDir / scala212PlusSourceDir)
229+
case _ => Seq()
230+
}
231+
},
232+
Compile / unmanagedResourceDirectories ++= {
233+
val resourceParentDir = (Compile / resourceDirectory).value.getParentFile
221234
CrossVersion.partialVersion(scalaVersion.value) match {
222-
case Some((2, n)) if n >= 12 => Seq(sourceDir / "scala-2.12+")
235+
case Some((major, _)) => Seq(resourceParentDir / s"resources-${major}")
223236
case _ => Seq()
224237
}
225238
},

scalafix-cli/src/main/scala/scalafix/internal/interfaces/ScalafixFileEvaluationImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ object ScalafixFileEvaluationImpl {
143143
ctx: RuleCtx,
144144
index: Option[v0.SemanticdbIndex]
145145
): ScalafixFileEvaluationImpl = {
146-
val scalafixPatches = patches.map(ScalafixPatchImpl)
146+
val scalafixPatches = patches.map(ScalafixPatchImpl.apply)
147147
ScalafixFileEvaluationImpl(
148148
originalPath = originalPath,
149149
fixedOpt = fixed,

scalafix-cli/src/main/scala/scalafix/internal/interfaces/ScalafixInputImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.util.Optional
77
import scala.{meta => m}
88

99
import scala.meta.inputs.Input
10+
import scala.meta.internal.inputs.XtensionInputSyntaxStructure
1011

1112
import scalafix.interfaces.ScalafixInput
1213

scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import scala.util.control.NoStackTrace
1919
import scala.util.control.NonFatal
2020

2121
import scala.meta.inputs.Input
22+
import scala.meta.internal.inputs.XtensionInputSyntaxStructure
2223
import scala.meta.internal.semanticdb.TextDocument
2324
import scala.meta.io.AbsolutePath
2425
import scala.meta.parsers.ParseException

scalafix-cli/src/main/scala/scalafix/internal/v1/ValidatedArgs.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package scalafix.internal.v1
33
import scala.meta.AbsolutePath
44
import scala.meta.Input
55
import scala.meta.Source
6+
import scala.meta.internal.inputs.XtensionInputSyntaxStructure
67
import scala.meta.internal.io.FileIO
78
import scala.meta.internal.symtab.SymbolTable
89
import scala.meta.io.RelativePath
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
package scalafix.internal.reflect
22
import java.io.File
3-
import java.nio.file.Paths
43

54
import scala.reflect.internal.util.AbstractFileClassLoader
65
import scala.reflect.internal.util.BatchSourceFile
6+
import scala.reflect.io.Directory
7+
import scala.reflect.io.PlainDirectory
78
import scala.tools.nsc.Global
89
import scala.tools.nsc.Settings
9-
import scala.tools.nsc.io.AbstractFile
1010
import scala.tools.nsc.io.VirtualDirectory
1111
import scala.tools.nsc.reporters.StoreReporter
1212

13-
import scala.meta.io.AbsolutePath
14-
1513
import metaconfig.ConfError
1614
import metaconfig.Configured
1715
import metaconfig.Input
1816
import metaconfig.Position
1917

2018
class RuleCompiler(
2119
classpath: String,
22-
target: AbstractFile = new VirtualDirectory("(memory)", None)
20+
targetDirectory: Option[File] = None
2321
) {
22+
private val output = targetDirectory match {
23+
case Some(file) => new PlainDirectory(new Directory(file))
24+
case None => new VirtualDirectory("(memory)", None)
25+
}
2426
private val settings = new Settings()
2527
settings.deprecation.value = true // enable detailed deprecation warnings
2628
settings.unchecked.value = true // enable detailed unchecked warnings
27-
settings.outputDirs.setSingleOutput(target)
29+
settings.outputDirs.setSingleOutput(output)
2830
settings.classpath.value = classpath
2931
lazy val reporter = new StoreReporter
3032
private val global = new Global(settings, reporter)
31-
private val classLoader =
32-
new AbstractFileClassLoader(target, this.getClass.getClassLoader)
3333

3434
def compile(input: Input): Configured[ClassLoader] = {
3535
reporter.reset()
@@ -55,33 +55,10 @@ class RuleCompiler(
5555
ConfError
5656
.fromResults(errors.toSeq)
5757
.map(_.notOk)
58-
.getOrElse(Configured.Ok(classLoader))
59-
}
60-
}
61-
object RuleCompiler {
62-
63-
def defaultClasspath: String = {
64-
defaultClasspathPaths.mkString(File.pathSeparator)
65-
}
66-
67-
def defaultClasspathPaths: List[AbsolutePath] = {
68-
val classLoader = ClasspathOps.thisClassLoader
69-
val paths = classLoader.getURLs.iterator.map { u =>
70-
if (u.getProtocol.startsWith("bootstrap")) {
71-
import java.nio.file._
72-
val stream = u.openStream
73-
val tmp = Files.createTempFile("bootstrap-" + u.getPath, ".jar")
74-
try {
75-
Files.copy(stream, tmp, StandardCopyOption.REPLACE_EXISTING)
76-
} finally {
77-
stream.close()
78-
}
79-
AbsolutePath(tmp)
80-
} else {
81-
AbsolutePath(Paths.get(u.toURI))
58+
.getOrElse {
59+
val classLoader: AbstractFileClassLoader =
60+
new AbstractFileClassLoader(output, this.getClass.getClassLoader)
61+
Configured.Ok(classLoader)
8262
}
83-
}
84-
paths.toList
8563
}
86-
8764
}

0 commit comments

Comments
 (0)