Skip to content

Commit

Permalink
Merge pull request #858 from eed3si9n/wip/dotty
Browse files Browse the repository at this point in the history
Fix Dotty doc task
  • Loading branch information
eed3si9n authored Jul 27, 2020
2 parents 944c09f + efd0c3f commit 2bd16be
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ trait CompilingSpecification extends BridgeProviderSpecification {
val compilerBridge = getCompilerBridge(tempDir.toPath, noLogger, scalaVersion)
val si = scalaInstance(scalaVersion, tempDir.toPath, noLogger)
val sc = scalaCompiler(si, compilerBridge)
val cp = (si.allJars ++ Array(targetDir)).map(_.toPath).map(converter.toVirtualFile)
val cp = (si.allJars ++ Array(targetDir)).map(_.toPath)
val emptyChanges: DependencyChanges = new DependencyChanges {
override val modifiedLibraries = new Array[VirtualFileRef](0)
override val modifiedBinaries = new Array[File](0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,31 @@ final class AnalyzingCompiler(
reporter: Reporter
): Unit = {
val compArgs = new CompilerArguments(scalaInstance, classpathOptions)
val arguments =
compArgs.makeArguments(Nil, classpath, Some(outputDirectory), options)
onArgsHandler(arguments)
val (bridge, bridgeClass) = bridgeInstance(scaladocBridgeClassName, log)
val cp = classpath.map(converter.toPath)
bridge match {
case intf: ScaladocInterface2 =>
val arguments =
compArgs.makeArguments(Nil, cp, Some(outputDirectory), options)
onArgsHandler(arguments)
intf.run(sources.toArray, arguments.toArray[String], log, reporter)
case intf: ScaladocInterface1 =>
val fileSources: Seq[Path] = sources.map(converter.toPath(_))
val arguments =
compArgs.makeArguments(fileSources, cp, Some(outputDirectory), options)
onArgsHandler(arguments)
intf.run(arguments.toArray[String], log, reporter)
case _ =>
// fall back to old reflection
val fileSources: Array[File] = sources.toArray.map(converter.toPath(_).toFile)
val fileSources: Seq[Path] = sources.map(converter.toPath(_))
val arguments =
compArgs.makeArguments(fileSources, cp, Some(outputDirectory), options)
onArgsHandler(arguments)
invoke(bridge, bridgeClass, "run", log)(
classOf[Array[File]],
classOf[Array[String]],
classOf[xLogger],
classOf[Reporter]
)(fileSources, arguments.toArray[String], log, reporter)
)(arguments.toArray[String], log, reporter)
}
()
}
Expand Down Expand Up @@ -364,9 +373,7 @@ object AnalyzingCompiler {
val scalaLibraryJars = compiler.scalaInstance.libraryJars
val restClasspath = xsbtiJars.toSeq ++ sourceJars
val classpath = scalaLibraryJars.map(_.toPath) ++ restClasspath
val vs = sourceFiles.map(PlainVirtualFile(_))
val cp = classpath.map(PlainVirtualFile(_))
compiler(vs, cp, outputDirectory.toPath, "-nowarn" :: Nil)
compiler(sourceFiles, classpath, outputDirectory.toPath, "-nowarn" :: Nil)

val end = (System.currentTimeMillis - start) / 1000.0
log.info(s" Compilation completed in ${end}s.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package sbt
package internal
package inc

import xsbti.{ ArtifactInfo, PathBasedFile, VirtualFile }
import xsbti.ArtifactInfo
import xsbti.compile.{ MultipleOutput, Output, SingleOutput }
import scala.util
import java.nio.file.Path
Expand Down Expand Up @@ -45,45 +45,39 @@ final class CompilerArguments(
cpOptions: xsbti.compile.ClasspathOptions
) {
def makeArguments(
sources: Seq[VirtualFile],
classpath: Seq[VirtualFile],
sources: Seq[Path],
classpath: Seq[Path],
output: Option[Path],
options: Seq[String]
): Seq[String] =
CompilerArguments.outputOption(output) ++
makeArguments(sources, classpath, options)

def makeArguments(
sources: Seq[VirtualFile],
classpath: Seq[VirtualFile],
sources: Seq[Path],
classpath: Seq[Path],
output: Output,
options: Seq[String]
): Seq[String] =
CompilerArguments.outputOption(output) ++
makeArguments(sources, classpath, options)

def makeArguments(
sources: Seq[VirtualFile],
classpath: Seq[VirtualFile],
sources: Seq[Path],
classpath: Seq[Path],
options: Seq[String]
): Seq[String] = {
/* Add dummy to avoid Scalac misbehaviour for empty classpath (as of 2.9.1). */
def dummy: String = "dummy_" + Integer.toHexString(util.Random.nextInt)
def dummy: String = "dummy_" + Integer.toHexString(util.Random.nextInt())

checkScalaHomeUnset()
val cp = classpath map {
case x: PathBasedFile => x.toPath
}
val compilerClasspath = finishClasspath(cp)
val compilerClasspath = finishClasspath(classpath)
val stringClasspath =
if (compilerClasspath.isEmpty) dummy
else absString(compilerClasspath)
val classpathOption = Seq("-classpath", stringClasspath)
val bootClasspath = bootClasspathOption(hasLibrary(cp))
val sources1 = sources map {
case x: PathBasedFile => x.toPath
}
options ++ bootClasspath ++ classpathOption ++ abs(sources1)
val bootClasspath = bootClasspathOption(hasLibrary(classpath))
options ++ bootClasspath ++ classpathOption ++ abs(sources)
}

/**
Expand Down Expand Up @@ -144,7 +138,7 @@ final class CompilerArguments(

def extClasspath: Seq[Path] =
List("java.ext.dirs", "scala.ext.dirs").flatMap(
k => (IO.parseClasspath(System.getProperty(k, "")) * "*.jar").get.map(_.toPath)
k => (IO.parseClasspath(System.getProperty(k, "")) * "*.jar").get().map(_.toPath)
)

private[this] def include(flag: Boolean, jars: Path*) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package inc

import java.nio.file.Path
import sbt.internal.util.FeedbackProvidedException
import xsbti.VirtualFile
import xsbti.compile.{ ClasspathOptions, ScalaInstance => XScalaInstance }

/**
Expand Down Expand Up @@ -44,8 +43,8 @@ class RawCompiler(val scalaInstance: XScalaInstance, cp: ClasspathOptions, log:
* @param options The auxiliary options to Scala compilers.
*/
def apply(
sources: Seq[VirtualFile],
classpath: Seq[VirtualFile],
sources: Seq[Path],
classpath: Seq[Path],
outputDirectory: Path,
options: Seq[String]
): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package javac

import java.nio.file.Path

import xsbti.VirtualFile
import xsbti.{ FileConverter, VirtualFile }
import xsbti.compile.{
ClasspathOptions,
ClasspathOptionsUtil,
Expand Down Expand Up @@ -87,13 +87,15 @@ object JavaCompiler {
*/
def commandArguments(
classpath: Seq[VirtualFile],
converter: FileConverter,
options: Seq[String],
scalaInstance: ScalaInstance,
cpOptions: ClasspathOptions
): Seq[String] = {
val augmentedClasspath: Seq[VirtualFile] =
if (!cpOptions.autoBoot) classpath
else classpath ++ scalaInstance.libraryJars.map(_.toPath).map(PlainVirtualFile(_))
val cp = classpath.map(converter.toPath)
val augmentedClasspath: Seq[Path] =
if (!cpOptions.autoBoot) cp
else cp ++ scalaInstance.libraryJars.map(_.toPath)
val javaCp = ClasspathOptionsUtil.javac(cpOptions.compiler)
val compilerArgs = new CompilerArguments(scalaInstance, javaCp)
compilerArgs.makeArguments(Nil, augmentedClasspath, options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ class IncrementalCompilerImpl extends IncrementalCompiler {
val javaSrcs = sources.filter(MixedAnalyzingCompiler.javaOnly)
val outputs = output :: earlyOutput.toList
val outputJars = outputs.flatMap(out => (JarUtils.getOutputJar(out): Option[Path]).toList)
val classpathPaths = classpath.map(converter.toPath)
val outputJarsOnCp = outputJars.exists { outputJar =>
classpath.exists {
case x: PathBasedFile => x.toPath.toAbsolutePath == outputJar.toAbsolutePath
case _ => false
classpathPaths.exists { x: Path =>
x.toAbsolutePath == outputJar.toAbsolutePath
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ final class MixedAnalyzingCompiler(
if (config.currentSetup.order == Mixed) incSrc
else scalaSrcs

val cp: Seq[VirtualFile] = (extraClasspath map { x =>
config.converter.toVirtualFile(x.toAbsolutePath)
}) ++ absClasspath
val cp: Seq[Path] = (extraClasspath map { x =>
x.toAbsolutePath
}) ++ absClasspath.map(config.converter.toPath)
val arguments =
cArgs.makeArguments(Nil, cp, config.currentSetup.options.scalacOptions)
timed("Scala compilation", log) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ final class AnalyzingJavaCompiler private[sbt] (
timed(javaCompilationPhase, log) {
val args = sbt.internal.inc.javac.JavaCompiler.commandArguments(
absClasspath,
converter,
options,
scalaInstance,
classpathOptions
Expand Down

0 comments on commit 2bd16be

Please sign in to comment.