Skip to content

Commit

Permalink
Convert known products into slash path
Browse files Browse the repository at this point in the history
Fixes #851

This normalizes backslash to slash / in parallel.
  • Loading branch information
eed3si9n committed Jul 23, 2020
1 parent 1ef6d25 commit 94ba81e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import sbt.internal.inc.Analysis.{ LocalProduct, NonLocalProduct }
import sbt.util.{ InterfaceUtil, Level, Logger }
import sbt.util.InterfaceUtil.jo2o
import scala.collection.JavaConverters._
import scala.util.control.NonFatal
import scala.collection.parallel.immutable.ParVector
import xsbti.{ FileConverter, Position, Problem, Severity, UseScope, VirtualFile, VirtualFileRef }
import xsbt.api.{ APIUtil, HashAPI, NameHashing }
import xsbti.api._
Expand Down Expand Up @@ -1000,24 +1002,33 @@ private final class AnalysisCallback(
pickleJarPath <- jo2o(earlyO.getSingleOutputAsPath())
} {
// List classes defined in the files that were compiled in this run.
val knownProducts = merged.relations.allSources
.flatMap(merged.relations.products)
.flatMap(extractProductPath)
PickleJar.write(pickleJarPath, knownProducts.toSet)
val ps = java.util.concurrent.ConcurrentHashMap.newKeySet[String]
val knownProducts: ParVector[VirtualFileRef] =
new ParVector(merged.relations.allSources.toVector)
.flatMap(merged.relations.products)
// extract product paths in parallel
jo2o(output.getSingleOutputAsPath) match {
case Some(so) if so.getFileName.toString.endsWith(".jar") =>
knownProducts foreach { product =>
new JarUtils.ClassInJar(product.id).toClassFilePath foreach { path =>
ps.add(path.replace('\\', '/'))
}
}
case Some(so) =>
knownProducts foreach { product =>
val productPath = converter.toPath(product)
try {
ps.add(so.relativize(productPath).toString.replace('\\', '/'))
} catch {
case NonFatal(_) => ps.add(product.id)
}
}
case _ => sys.error(s"unsupported output $output")
}
PickleJar.write(pickleJarPath, ps)
}
progress foreach { p =>
p.earlyOutputComplete(true)
}
}

private def extractProductPath(product: VirtualFileRef): Option[String] = {
jo2o(output.getSingleOutputAsPath) match {
case Some(so) if so.getFileName.toString.endsWith(".jar") =>
new JarUtils.ClassInJar(product.id).toClassFilePath
case Some(so) =>
val productPath = converter.toPath(product)
sbt.io.IO.relativize(so.toFile, productPath.toFile)
case _ => sys.error(s"unsupported output $output")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import java.nio.file.attribute.BasicFileAttributes
import scala.reflect.io.RootPath

object PickleJar {
def write(pickleOut: Path, knownProducts: Set[String]): Path = {
def write(pickleOut: Path, knownProducts: java.util.Set[String]): Path = {
val pj = RootPath(pickleOut, writable = false) // so it doesn't delete the file
try Files.walkFileTree(pj.root, deleteUnknowns(knownProducts))
finally pj.close()
}

def deleteUnknowns(knownProducts: Set[String]) = new SimpleFileVisitor[Path] {
def deleteUnknowns(knownProducts: java.util.Set[String]) = new SimpleFileVisitor[Path] {
override def visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult = {
val ps = path.toString
if (ps.endsWith(".sig")) {
Expand Down

0 comments on commit 94ba81e

Please sign in to comment.