File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
src/dotty/tools/dotc/semanticdb
test/dotty/tools/dotc/core/tasty Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import Names.Name
1212import StdNames .nme
1313import util .Spans .Span
1414import util .{SourceFile , SourcePosition }
15+ import scala .jdk .CollectionConverters ._
1516import collection .mutable
1617import java .nio .file .Paths
1718
@@ -594,8 +595,15 @@ object ExtractSemanticDB:
594595
595596 def write (source : SourceFile , occurrences : List [SymbolOccurrence ], symbolInfos : List [SymbolInformation ])(using Context ): Unit =
596597 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)
597600 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 _)
599607 val semanticdbTarget =
600608 val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
601609 absolutePath(
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ class CommentPicklingTest {
8282 Directory .inTempDirectory { tmp =>
8383 val sourceFiles = sources.zipWithIndex.map {
8484 case (src, id) =>
85- val path = tmp./ (File (" Src$id.scala" )).toAbsolute
85+ val path = tmp./ (File (s " Src $id.scala " )).toAbsolute
8686 path.writeAll(src)
8787 path.toString
8888 }
You can’t perform that action at this time.
0 commit comments