Skip to content

Commit 08dab95

Browse files
authored
Merge pull request #12100 from adpi2/zinc-13-compat
Check compatibility with Zinc 1.3 for Bloop
2 parents 321cb84 + cbed6f9 commit 08dab95

File tree

6 files changed

+153
-2
lines changed

6 files changed

+153
-2
lines changed

sbt-bridge/src/dotty/tools/xsbt/CompilerBridgeDriver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public CompilerBridgeDriver(String[] scalacOptions, Output output) {
2929
super();
3030
this.scalacOptions = scalacOptions;
3131

32-
if (!output.getSingleOutput().isPresent())
32+
if (!output.getSingleOutputAsPath().isPresent())
3333
throw new IllegalArgumentException("output should be a SingleOutput, was a " + output.getClass().getName());
3434

3535
this.args = new String[scalacOptions.length + 2];
3636
System.arraycopy(scalacOptions, 0, args, 0, scalacOptions.length);
3737
args[scalacOptions.length] = "-d";
38-
args[scalacOptions.length + 1] = output.getSingleOutput().get().getAbsolutePath();
38+
args[scalacOptions.length + 1] = output.getSingleOutputAsPath().get().toAbsolutePath().toString();
3939
}
4040

4141
private static final String StopInfoError =

sbt-bridge/src/xsbt/CachedCompilerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
import dotty.tools.xsbt.InterfaceCompileFailed;
1515
import dotty.tools.xsbt.DelegatingReporter;
1616

17+
// deprecation warnings are suppressed because scala3-sbt-bridge must stay compatible with Zinc 1.3
18+
// see https://github.com/lampepfl/dotty/issues/10816
19+
@SuppressWarnings("deprecation")
1720
public class CachedCompilerImpl implements CachedCompiler {
1821
private final String[] args;
1922
private final String[] outputArgs;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
scalaVersion := "2.12.13"
2+
3+
val Scala3Compiler = config("scala3-compiler")
4+
val Scala3Bridge = config("scala3-bridge")
5+
6+
val scala3Version = sys.props("plugin.scalaVersion")
7+
8+
lazy val root = project.in(file("."))
9+
.configs(Scala3Compiler, Scala3Bridge)
10+
.settings(
11+
inConfig(Scala3Compiler)(Defaults.configSettings),
12+
inConfig(Scala3Bridge)(Defaults.configSettings),
13+
libraryDependencies ++= Seq(
14+
"org.scala-sbt" %% "zinc" % "1.3.5",
15+
"org.scala-lang" % "scala3-compiler_3" % scala3Version % Scala3Compiler,
16+
"org.scala-lang" % "scala3-sbt-bridge" % scala3Version % Scala3Bridge
17+
),
18+
autoScalaLibrary := false,
19+
run / fork := true,
20+
Compile / sourceGenerators += Def.task {
21+
val scala3File = (Compile / sourceManaged).value / "Scala3.scala"
22+
val inputFile = (Compile / sourceManaged).value / "Input.scala"
23+
24+
val allJars = (Scala3Compiler / managedClasspath).value.seq.map(_.data)
25+
val compilerJar = allJars
26+
.find(jar => jar.name.contains("scala3-compiler"))
27+
.get.getAbsolutePath.toString
28+
val libraryJars = allJars
29+
.filter(jar => jar.name.contains("library"))
30+
.map(_.getAbsolutePath.toString)
31+
32+
val bridgeJars = (Scala3Bridge / managedClasspath).value.seq.map(_.data)
33+
val bridgeJar = bridgeJars
34+
.find(att => att.name.contains("scala3-sbt-bridge"))
35+
.get.getAbsolutePath.toString
36+
37+
IO.write(
38+
scala3File,
39+
s"""|
40+
|import java.io.File
41+
|
42+
|object Scala3 {
43+
| val version = "$scala3Version"
44+
| val allJars = Array(
45+
| ${allJars.map(jar => s"""new File("${jar.getAbsolutePath}")""").mkString(",\n ")}
46+
| )
47+
| val compilerJar = new File("$compilerJar")
48+
| val libraryJars = Array(
49+
| ${libraryJars.map(jar => s"""new File("$jar")""").mkString(",\n ")}
50+
| )
51+
| val bridgeJar = new File("$bridgeJar")
52+
|}
53+
|""".stripMargin
54+
)
55+
56+
val output = target.value / "test-output"
57+
IO.createDirectory(output)
58+
59+
val sourceFile = baseDirectory.value / "tests" / "Hello.scala"
60+
61+
IO.write(
62+
inputFile,
63+
s"""|
64+
|import java.io.File
65+
|
66+
|object Input {
67+
| val outputFile = new File("${output.getAbsolutePath}")
68+
| val sources = Array(new File("${sourceFile.getAbsolutePath}"))
69+
|}
70+
|""".stripMargin
71+
)
72+
73+
Seq(scala3File, inputFile)
74+
}
75+
)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
import java.net.URLClassLoader
3+
import java.io.File
4+
import java.util.{EnumSet, Set, HashSet}
5+
6+
import org.apache.logging.log4j.LogManager
7+
8+
import xsbti._
9+
import xsbti.api.ClassLike
10+
import xsbti.api.DependencyContext
11+
import xsbti.compile.DependencyChanges
12+
13+
import sbt.internal.util.ManagedLogger
14+
import sbt.internal.inc.FreshCompilerCache
15+
import sbt.internal.inc.ZincUtil
16+
import sbt.internal.inc.ScalaInstance
17+
18+
object Main extends App {
19+
val loaderLibraryOnly = new URLClassLoader(Scala3.libraryJars.map(_.toURI.toURL), null)
20+
val loader = new URLClassLoader(Scala3.allJars.map(_.toURI.toURL), loaderLibraryOnly)
21+
val instance = new ScalaInstance(
22+
Scala3.version,
23+
loader,
24+
loaderLibraryOnly,
25+
Scala3.libraryJars,
26+
Scala3.compilerJar,
27+
Scala3.allJars,
28+
Some(Scala3.version)
29+
)
30+
val compiler = ZincUtil.scalaCompiler(instance, Scala3.bridgeJar)
31+
32+
val noChanges = new DependencyChanges {
33+
val modifiedBinaries = Array.empty[File]
34+
val modifiedClasses = Array.empty[String]
35+
def isEmpty(): Boolean = true
36+
}
37+
val noCallback = new AnalysisCallback {
38+
override def startSource(x$1: File): Unit = ()
39+
override def classDependency(x$1: String, x$2: String, x$3: DependencyContext): Unit = ()
40+
override def binaryDependency(x$1: File, x$2: String, x$3: String, x$4: File, x$5: DependencyContext): Unit = ()
41+
override def generatedNonLocalClass(x$1: File, x$2: File, x$3: String, x$4: String): Unit = ()
42+
override def generatedLocalClass(x$1: File, x$2: File): Unit = ()
43+
override def api(x$1: File, x$2: ClassLike): Unit = ()
44+
override def mainClass(x$1: File, x$2: String): Unit = ()
45+
override def usedName(x$1: String, x$2: String, x$3: EnumSet[UseScope]): Unit = ()
46+
override def problem(x$1: String, x$2: Position, x$3: String, x$4: Severity, x$5: Boolean): Unit = ()
47+
override def dependencyPhaseCompleted(): Unit = ()
48+
override def apiPhaseCompleted(): Unit = ()
49+
override def enabled(): Boolean = false
50+
override def classesInOutputJar(): Set[String] = new HashSet[String]()
51+
}
52+
val cache = new FreshCompilerCache()
53+
val log = new ManagedLogger("default", None, None, LogManager.getLogger())
54+
55+
compiler.apply(
56+
Input.sources,
57+
noChanges,
58+
Scala3.libraryJars,
59+
Input.outputFile,
60+
options = Array(),
61+
noCallback,
62+
maximumErrors = 10,
63+
cache,
64+
log
65+
)
66+
}
67+
68+
69+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# this little app test that scala3-sbt-bridge is compatible with Zinc 1.3
2+
# this is necessary to maintain the compatibility with Bloop (see https://github.com/lampepfl/dotty/issues/10816)
3+
> run
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@main def hello = println("Hello, World!")

0 commit comments

Comments
 (0)