Skip to content

Commit 4af4ffe

Browse files
authored
Merge pull request #13254 from romanowski/tastyreader/fix-from-jar
2 parents f27c250 + a1debc5 commit 4af4ffe

File tree

7 files changed

+50
-3
lines changed

7 files changed

+50
-3
lines changed

compiler/src/dotty/tools/dotc/fromtasty/TASTYRun.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package fromtasty
44

55
import io.{JarArchive, AbstractFile, Path}
66
import core.Contexts._
7+
import java.io.File
78

89
class TASTYRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) {
910
override def compile(files: List[AbstractFile]): Unit = {
@@ -17,9 +18,10 @@ class TASTYRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) {
1718
val classNames = files.flatMap { file =>
1819
file.extension match
1920
case "jar" =>
20-
JarArchive.open(Path(file.path), create = false).iterator()
21-
.filter(e => e.extension == "tasty" && !fromTastyIgnoreList(e.name))
22-
.map(e => e.name.stripSuffix(".tasty").replace("/", "."))
21+
JarArchive.open(Path(file.path), create = false).allFileNames()
22+
.map(_.stripPrefix(File.separator)) // change paths from absolute to relative
23+
.filter(e => Path.extension(e) == "tasty" && !fromTastyIgnoreList(e))
24+
.map(e => e.stripSuffix(".tasty").replace(File.separator, "."))
2325
.toList
2426
case "tasty" => TastyFileUtil.getClassName(file)
2527
case _ =>

compiler/src/dotty/tools/io/JarArchive.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import scala.jdk.CollectionConverters._
1010
*/
1111
class JarArchive private (root: Directory) extends PlainDirectory(root) {
1212
def close(): Unit = jpath.getFileSystem().close()
13+
def allFileNames(): Iterator[String] =
14+
java.nio.file.Files.walk(jpath).iterator().asScala.map(_.toString)
1315
}
1416

1517
object JarArchive {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
lazy val dottyVersion = sys.props("plugin.scalaVersion")
2+
3+
lazy val lib = project
4+
.in(file("lib"))
5+
.settings(
6+
scalaVersion := dottyVersion
7+
)
8+
9+
val jarDest = file("target") / "app.jar"
10+
11+
val runTest = Def.taskKey[Unit]("run tests")
12+
13+
lazy val inspector = project
14+
.in(file("inspector"))
15+
.settings(
16+
scalaVersion := dottyVersion,
17+
libraryDependencies += "org.scala-lang" %% "scala3-tasty-inspector" % scalaVersion.value,
18+
runTest :=
19+
Def.sequential(
20+
Def.task(IO.copyFile((lib/Compile/packageBin).value, jarDest)),
21+
(Compile/run).toTask(" " + jarDest.getAbsolutePath)
22+
).value
23+
)
24+
.dependsOn(lib)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted.Quotes
2+
import scala.quoted.quotes
3+
import scala.tasty.inspector as ins
4+
5+
class MyInspector extends ins.Inspector:
6+
def inspect(using Quotes)(tastys: List[ins.Tasty[quotes.type]]): Unit =
7+
val sources = tastys.map(_.ast.pos.sourceFile.toString).toSet
8+
val expectedSources = Set("lib/src/main/scala/toplevel.scala", "lib/src/main/scala/inpackage.scala")
9+
assert(sources == expectedSources, s"expected $expectedSources tasty files but get: $sources")
10+
11+
@main def main(args: String*): Unit =
12+
ins.TastyInspector.inspectTastyFilesInJar(args.head)(new MyInspector)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package pkg
2+
3+
class A
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// NOTE: no package, this is top-level!
2+
3+
class A
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> inspector/runTest

0 commit comments

Comments
 (0)