File tree 2 files changed +10
-2
lines changed
src/dotty/tools/dotc/semanticdb
test/dotty/tools/dotc/core/tasty
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import Names.Name
12
12
import StdNames .nme
13
13
import util .Spans .Span
14
14
import util .{SourceFile , SourcePosition }
15
+ import scala .jdk .CollectionConverters ._
15
16
import collection .mutable
16
17
import java .nio .file .Paths
17
18
@@ -594,8 +595,15 @@ object ExtractSemanticDB:
594
595
595
596
def write (source : SourceFile , occurrences : List [SymbolOccurrence ], symbolInfos : List [SymbolInformation ])(using Context ): Unit =
596
597
def absolutePath (path : Path ): Path = path.toAbsolutePath.normalize
598
+ def commonPrefix [T ](z : T )(i1 : Iterable [T ], i2 : Iterable [T ])(app : (T , T ) => T ): T =
599
+ (i1 lazyZip i2).takeWhile(p => p(0 ) == p(1 )).map(_(0 )).foldLeft(z)(app)
597
600
val sourcePath = absolutePath(source.file.jpath)
598
- val sourceRoot = absolutePath(Paths .get(ctx.settings.sourceroot.value))
601
+ val sourceRoot =
602
+ // Here if `sourceRoot` and `sourcePath` do not share a common prefix then `relPath` will not be normalised,
603
+ // containing ../.. etc, which is problematic when appending to `/META-INF/semanticdb/` and will not be accepted
604
+ // by Files.createDirectories on JDK 11.
605
+ val sourceRoot0 = absolutePath(Paths .get(ctx.settings.sourceroot.value))
606
+ commonPrefix(sourcePath.getRoot)(sourcePath.asScala, sourceRoot0.asScala)(_ resolve _)
599
607
val semanticdbTarget =
600
608
val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
601
609
absolutePath(
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ class CommentPicklingTest {
82
82
Directory .inTempDirectory { tmp =>
83
83
val sourceFiles = sources.zipWithIndex.map {
84
84
case (src, id) =>
85
- val path = tmp./ (File (" Src$id.scala" )).toAbsolute
85
+ val path = tmp./ (File (s " Src $id.scala " )).toAbsolute
86
86
path.writeAll(src)
87
87
path.toString
88
88
}
You can’t perform that action at this time.
0 commit comments