File tree Expand file tree Collapse file tree 1 file changed +6
-11
lines changed
compiler/src/dotty/tools/dotc/semanticdb Expand file tree Collapse file tree 1 file changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -595,20 +595,15 @@ object ExtractSemanticDB:
595595
596596 def write (source : SourceFile , occurrences : List [SymbolOccurrence ], symbolInfos : List [SymbolInformation ])(using Context ): Unit =
597597 def absolutePath (path : Path ): Path = path.toAbsolutePath.normalize
598- def common (root : Path , i1 : java.util.Iterator [Path ], i2 : java.util.Iterator [Path ]) =
599- require(root != null )
600- var res : Path = root
601- var next : Path = null
602- while
603- i1.hasNext && i2.hasNext
604- && { next = i1.next; next } == i2.next
605- do res = res.resolve(next)
606- res
607- end common
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)
608600 val sourcePath = absolutePath(source.file.jpath)
609601 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.
610605 val sourceRoot0 = absolutePath(Paths .get(ctx.settings.sourceroot.value))
611- common (sourcePath.getRoot, sourcePath.iterator , sourceRoot0.iterator )
606+ commonPrefix (sourcePath.getRoot)( sourcePath.asScala , sourceRoot0.asScala)(_ resolve _ )
612607 val semanticdbTarget =
613608 val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
614609 absolutePath(
You can’t perform that action at this time.
0 commit comments