@@ -4,6 +4,7 @@ package sbt
4
4
import scala .language .unsafeNulls
5
5
6
6
import java .io .File
7
+ import java .nio .file .Path
7
8
import java .util .{Arrays , EnumSet }
8
9
9
10
import dotty .tools .dotc .ast .tpd
@@ -19,6 +20,7 @@ import dotty.tools.dotc.core.Denotations.StaleSymbol
19
20
import dotty .tools .dotc .core .Types ._
20
21
import dotty .tools .dotc .transform .SymUtils ._
21
22
import dotty .tools .dotc .util .{SrcPos , NoSourcePosition }
23
+ import dotty .tools .uncheckedNN
22
24
import dotty .tools .io
23
25
import dotty .tools .io .{AbstractFile , PlainFile , ZipArchive }
24
26
import xsbti .UseScope
@@ -56,7 +58,7 @@ class ExtractDependencies extends Phase {
56
58
57
59
override def isRunnable (using Context ): Boolean = {
58
60
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)
60
62
}
61
63
62
64
// Check no needed. Does not transform trees
@@ -91,7 +93,7 @@ class ExtractDependencies extends Phase {
91
93
} finally pw.close()
92
94
}
93
95
94
- if (ctx.sbtCallback != null ) {
96
+ if (ctx.sbtCallback != null && ctx.sbtCallback.enabled() ) {
95
97
collector.usedNames.foreach {
96
98
case (clazz, usedNames) =>
97
99
val className = classNameAsString(clazz)
@@ -112,17 +114,17 @@ class ExtractDependencies extends Phase {
112
114
*/
113
115
def recordDependency (dep : ClassDependency )(using Context ): Unit = {
114
116
val fromClassName = classNameAsString(dep.from)
115
- val sourceFile = ctx.compilationUnit.source.file.file
117
+ val zincSourceFile = ctx.compilationUnit.source.underlyingZincFile
116
118
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)
119
121
120
122
def processExternalDependency (depFile : AbstractFile , binaryClassName : String ) = {
121
123
depFile match {
122
124
case ze : ZipArchive # Entry => // The dependency comes from a JAR
123
125
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)
126
128
case _ =>
127
129
case pf : PlainFile => // The dependency comes from a class file
128
130
// FIXME: pf.file is null for classfiles coming from the modulepath
@@ -131,15 +133,19 @@ class ExtractDependencies extends Phase {
131
133
// java.io.File, this means that we cannot record dependencies coming
132
134
// from the modulepath. For now this isn't a big deal since we only
133
135
// 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)
136
138
case _ =>
137
139
internalError(s " Ignoring dependency $depFile of unknown class ${depFile.getClass}} " , dep.from.srcPos)
138
140
}
139
141
}
140
142
141
143
val depFile = dep.to.associatedFile
142
144
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
+
143
149
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
144
150
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
145
151
val depClassFile =
@@ -148,7 +154,7 @@ class ExtractDependencies extends Phase {
148
154
if (depClassFile != null ) {
149
155
// Dependency is external -- source is undefined
150
156
processExternalDependency(depClassFile, dep.to.binaryClassName)
151
- } else if (allowLocal || depFile.file != sourceFile) {
157
+ } else if (allowLocal || ! depIsSameSource /* old: depFile.file != sourceFile.file */ ) {
152
158
// We cannot ignore dependencies coming from the same source file because
153
159
// the dependency info needs to propagate. See source-dependencies/trait-trait-211.
154
160
val toClassName = classNameAsString(dep.to)
0 commit comments