@@ -4,6 +4,7 @@ package sbt
44import scala .language .unsafeNulls
55
66import java .io .File
7+ import java .nio .file .Path
78import java .util .{Arrays , EnumSet }
89
910import dotty .tools .dotc .ast .tpd
@@ -19,6 +20,7 @@ import dotty.tools.dotc.core.Denotations.StaleSymbol
1920import dotty .tools .dotc .core .Types ._
2021import dotty .tools .dotc .transform .SymUtils ._
2122import dotty .tools .dotc .util .{SrcPos , NoSourcePosition }
23+ import dotty .tools .uncheckedNN
2224import dotty .tools .io
2325import dotty .tools .io .{AbstractFile , PlainFile , ZipArchive }
2426import xsbti .UseScope
@@ -56,7 +58,7 @@ class ExtractDependencies extends Phase {
5658
5759 override def isRunnable (using Context ): Boolean = {
5860 def forceRun = ctx.settings.YdumpSbtInc .value || ctx.settings.YforceSbtPhases .value
59- super .isRunnable && (ctx.sbtCallback != null || forceRun)
61+ super .isRunnable && (ctx.sbtCallback != null && ctx.sbtCallback.enabled() || forceRun)
6062 }
6163
6264 // Check no needed. Does not transform trees
@@ -91,7 +93,7 @@ class ExtractDependencies extends Phase {
9193 } finally pw.close()
9294 }
9395
94- if (ctx.sbtCallback != null ) {
96+ if (ctx.sbtCallback != null && ctx.sbtCallback.enabled() ) {
9597 collector.usedNames.foreach {
9698 case (clazz, usedNames) =>
9799 val className = classNameAsString(clazz)
@@ -112,17 +114,17 @@ class ExtractDependencies extends Phase {
112114 */
113115 def recordDependency (dep : ClassDependency )(using Context ): Unit = {
114116 val fromClassName = classNameAsString(dep.from)
115- val sourceFile = ctx.compilationUnit.source.file.file
117+ val zincSourceFile = ctx.compilationUnit.source.underlyingZincFile
116118
117- def binaryDependency (file : File , binaryClassName : String ) =
118- ctx.sbtCallback.binaryDependency(file, binaryClassName, fromClassName, sourceFile , dep.context)
119+ def binaryDependency (file : Path , binaryClassName : String ) =
120+ ctx.sbtCallback.binaryDependency(file, binaryClassName, fromClassName, zincSourceFile , dep.context)
119121
120122 def processExternalDependency (depFile : AbstractFile , binaryClassName : String ) = {
121123 depFile match {
122124 case ze : ZipArchive # Entry => // The dependency comes from a JAR
123125 ze.underlyingSource match
124- case Some (zip) if zip.file != null =>
125- binaryDependency(zip.file , binaryClassName)
126+ case Some (zip) if zip.jpath != null =>
127+ binaryDependency(zip.jpath , binaryClassName)
126128 case _ =>
127129 case pf : PlainFile => // The dependency comes from a class file
128130 // FIXME: pf.file is null for classfiles coming from the modulepath
@@ -131,15 +133,19 @@ class ExtractDependencies extends Phase {
131133 // java.io.File, this means that we cannot record dependencies coming
132134 // from the modulepath. For now this isn't a big deal since we only
133135 // support having the standard Java library on the modulepath.
134- if pf.file != null then
135- binaryDependency(pf.file , binaryClassName)
136+ if pf.jpath != null then
137+ binaryDependency(pf.jpath , binaryClassName)
136138 case _ =>
137139 internalError(s " Ignoring dependency $depFile of unknown class ${depFile.getClass}} " , dep.from.srcPos)
138140 }
139141 }
140142
141143 val depFile = dep.to.associatedFile
142144 if (depFile != null ) {
145+ def depIsSameSource =
146+ val depVF : xsbti.VirtualFile | Null = ctx.zincVirtualFiles.uncheckedNN.get(depFile.absolutePath)
147+ depVF != null && depVF.id() == zincSourceFile.id()
148+
143149 // Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
144150 def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
145151 val depClassFile =
@@ -148,7 +154,7 @@ class ExtractDependencies extends Phase {
148154 if (depClassFile != null ) {
149155 // Dependency is external -- source is undefined
150156 processExternalDependency(depClassFile, dep.to.binaryClassName)
151- } else if (allowLocal || depFile.file != sourceFile) {
157+ } else if (allowLocal || ! depIsSameSource /* old: depFile.file != sourceFile.file */ ) {
152158 // We cannot ignore dependencies coming from the same source file because
153159 // the dependency info needs to propagate. See source-dependencies/trait-trait-211.
154160 val toClassName = classNameAsString(dep.to)
0 commit comments