Skip to content

Commit aaf40df

Browse files
committed
Link directly to a JAR
1 parent 1b14b58 commit aaf40df

File tree

6 files changed

+40
-21
lines changed

6 files changed

+40
-21
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package dotty.tools
22
package dotc
33

4-
import dotty.tools.dotc.core.Types.Type
5-
import dotty.tools.dotc.core.tasty.{TastyUnpickler, TastyBuffer, TastyPickler}
4+
import dotty.tools.dotc.core.Types.Type // FIXME Why is this import needed in posTwice testNonCyclic?
65
import util.SourceFile
7-
import ast.{tpd, untpd}
8-
import dotty.tools.dotc.ast.tpd.{ Tree, TreeTraverser }
6+
import dotty.tools.dotc.ast.{ tpd, untpd }
97
import dotty.tools.dotc.core.Contexts.Context
108
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
119
import dotty.tools.dotc.core.Symbols._
@@ -27,16 +25,17 @@ class CompilationUnit(val source: SourceFile) {
2725
object CompilationUnit {
2826

2927
/** Make a compilation unit for top class `clsd` with the contends of the `unpickled` */
30-
def mkCompilationUnit(clsd: ClassDenotation, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit = {
31-
val unit1 = new CompilationUnit(new SourceFile(clsd.symbol.sourceFile, Seq()))
28+
def mkCompilationUnit(clsd: ClassDenotation, unpickled: tpd.Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit = {
29+
val file = Option(clsd.symbol.sourceFile).getOrElse(clsd.symbol.associatedFile)
30+
val unit1 = new CompilationUnit(new SourceFile(file, Seq()))
3231
unit1.tpdTree = unpickled
3332
if (forceTrees)
3433
force.traverse(unit1.tpdTree)
3534
unit1
3635
}
3736

3837
/** Force the tree to be loaded */
39-
private object force extends TreeTraverser {
40-
def traverse(tree: Tree)(implicit ctx: Context): Unit = traverseChildren(tree)
38+
private object force extends tpd.TreeTraverser {
39+
def traverse(tree: tpd.Tree)(implicit ctx: Context): Unit = traverseChildren(tree)
4140
}
4241
}

compiler/src/dotty/tools/dotc/transform/LinkAll.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class LinkAll extends Phase {
3434
}
3535
}
3636

37-
if (ctx.settings.Xlink.value) allUnits(Set.empty, units.toSet, Set.empty)
37+
if (doLink) allUnits(Set.empty, units.toSet, Set.empty)
3838
else units
3939
}
4040

@@ -62,6 +62,16 @@ class LinkAll extends Phase {
6262
else acc + topClass
6363
}
6464
}
65+
66+
private def doLink(implicit ctx: Context): Boolean = {
67+
val link = ctx.settings.Xlink
68+
if (link.value) {
69+
val out = ctx.settings.outputDir
70+
if (out.value.extension != "jar")
71+
ctx.error("With " + link.name + " the output directory " + out.name + " should be a .jar\n" + out.value)
72+
true
73+
} else false
74+
}
6575
}
6676

6777
object LinkAll {

compiler/test/dotty/tools/dotc/LinkOptimiseTests.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty
22
package tools
33
package dotc
44

5+
import dotty.tools.io.Jar
6+
57
import java.io.{File => JFile}
68
import java.nio.file.{Files, Path, Paths}
79

@@ -56,11 +58,11 @@ class LinkOptimiseTests extends ParallelTesting {
5658
for (check <- new JFile(sourceDir).listFiles().filter(_.toString.endsWith(checkExt))) {
5759
val outDir = {
5860
def path(str: String) = str.substring(linkDir.length, str.length - checkExt.length)
59-
defaultOutputDir + testName + path(check.toString) + "/"
61+
defaultOutputDir + testName + path(check.toString) + "/linked.jar"
6062
}
6163
val expectedClasses = scala.io.Source.fromFile(check).getLines().toSet
62-
val actualClasses = Files.walk(Paths.get(outDir)).iterator().asScala.collect {
63-
case f if f.toString.endsWith(".class") => f.toString.substring(outDir.length, f.toString.length - ".class".length)
64+
val actualClasses = new Jar(outDir).iterator.collect {
65+
case f if f.toString.endsWith(".class") => f.toString.substring(0, f.toString.length - ".class".length)
6466
}.toSet
6567
assertEquals(check.toString, expectedClasses, actualClasses)
6668
}

compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MissingCoreLibTests {
1212
@Test def missingDottyLib: Unit = {
1313
val classPath = mkClassPath(Jars.dottyCompiler :: Jars.dottyInterfaces :: Jars.dottyExtras) // missing Jars.dottyLib
1414
val source = "../tests/neg/nolib/Foo.scala"
15-
val options = Array("-classpath", classPath, source)
15+
val options = Array("-classpath", classPath, "-d", "../out/", source)
1616
val reporter = Main.process(options)
1717
assertEquals(1, reporter.errorCount)
1818
val errorMessage = reporter.allErrors.head.message

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,18 +1005,22 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10051005
}
10061006

10071007
/** Create out directory for directory `d` */
1008-
private def createOutputDirsForDir(d: JFile, sourceDir: JFile, outDir: String): JFile = {
1008+
private def createOutputDirsForDir(d: JFile, sourceDir: JFile, outDir: String, flags: TestFlags): JFile = {
10091009
val targetDir = new JFile(outDir + s"${sourceDir.getName}/${d.getName}")
10101010
targetDir.mkdirs()
1011-
targetDir
1011+
jaredIfNeeded(targetDir, flags)
10121012
}
10131013

10141014
/** Create out directory for `file` */
1015-
private def createOutputDirsForFile(file: JFile, sourceDir: JFile, outDir: String): JFile = {
1015+
private def createOutputDirsForFile(file: JFile, sourceDir: JFile, outDir: String, flags: TestFlags): JFile = {
10161016
val uniqueSubdir = file.getName.substring(0, file.getName.lastIndexOf('.'))
10171017
val targetDir = new JFile(outDir + s"${sourceDir.getName}/$uniqueSubdir")
10181018
targetDir.mkdirs()
1019-
targetDir
1019+
jaredIfNeeded(targetDir, flags)
1020+
}
1021+
1022+
private def jaredIfNeeded(targetDir: JFile, flags: TestFlags): JFile = {
1023+
new JFile(targetDir + (if (flags.isLinkTest) "/linked.jar" else ""))
10201024
}
10211025

10221026
/** Make sure that directory string is as expected */
@@ -1078,7 +1082,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10781082
callingMethod,
10791083
Array(sourceFile),
10801084
flags,
1081-
createOutputDirsForFile(sourceFile, parent, outDir)
1085+
createOutputDirsForFile(sourceFile, parent, outDir, flags)
10821086
)
10831087
new CompilationTest(target)
10841088
}
@@ -1158,9 +1162,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11581162

11591163
val (dirs, files) = compilationTargets(sourceDir)
11601164

1165+
def createOutputDirsFor(f: JFile): JFile = createOutputDirsForFile(f, sourceDir, outDir, flags)
1166+
11611167
val targets =
1162-
files.map(f => JointCompilationSource(callingMethod, Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir))) ++
1163-
dirs.map(dir => SeparateCompilationSource(callingMethod, dir, flags, createOutputDirsForDir(dir, sourceDir, outDir)))
1168+
files.map(f => JointCompilationSource(callingMethod, Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir, flags))) ++
1169+
dirs.map(dir => SeparateCompilationSource(callingMethod, dir, flags, createOutputDirsForDir(dir, sourceDir, outDir, flags)))
11641170

11651171
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
11661172
new CompilationTest(targets)
@@ -1179,7 +1185,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11791185
val (_, files) = compilationTargets(sourceDir)
11801186

11811187
val targets = files.map { file =>
1182-
JointCompilationSource(callingMethod, Array(file), flags, createOutputDirsForFile(file, sourceDir, outDir))
1188+
JointCompilationSource(callingMethod, Array(file), flags, createOutputDirsForFile(file, sourceDir, outDir, flags))
11831189
}
11841190

11851191
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test

compiler/test/dotty/tools/vulpix/TestFlags.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ final case class TestFlags(
1212
TestFlags(defaultClassPath, runClassPath, options diff flags)
1313

1414
def all: Array[String] = Array("-classpath", defaultClassPath) ++ options
15+
16+
def isLinkTest: Boolean = options.contains("-Xlink")
1517
}
1618

1719
object TestFlags {

0 commit comments

Comments
 (0)