Skip to content

Commit

Permalink
Add classpath parameter to compile
Browse files Browse the repository at this point in the history
Fixes #871

This is a minor refactoring to add `classpath` parameter to `AnalyzingCompiler#compile(...)` like all other methods.
  • Loading branch information
eed3si9n committed Aug 14, 2020
1 parent 21cf93c commit 864444c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,14 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
}
val sources = srcFiles.toArray[VirtualFile]
val (si, sc) = mkScalaCompiler(baseDir)
val cp = (si.allJars).map(_.toPath) ++ Array(targetDir)
val compArgs = new CompilerArguments(si, sc.classpathOptions)
val arguments = compArgs.makeArguments(Nil, cp, Nil)
val cp = ((si.allJars).map(_.toPath) ++ Array(targetDir)).map(converter.toVirtualFile)
val reporter = mkReporter
sc.compile(
sources = sources,
classpath = cp,
converter = converter,
changes = emptyChanges,
options = arguments.toArray,
options = Array(),
output = CompileOutput(targetDir),
callback = analysisCallback,
reporter = reporter,
Expand Down
43 changes: 0 additions & 43 deletions internal/compiler-bridge/src/main/scala/xsbt/Command.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import xsbti.compile._
import scala.tools.nsc.Settings
import scala.collection.mutable
import scala.reflect.io.AbstractFile
import scala.tools.nsc.CompilerCommand
import Log.debug
import java.io.File

Expand Down Expand Up @@ -64,8 +65,11 @@ private final class WeakLog(private[this] var log: Logger, private[this] var del
}
}

private final class CachedCompiler0(args: Array[String], output: Output, initialLog: WeakLog)
extends CachedCompilerCompat
private final class CachedCompiler0(
args: Array[String],
output: Output,
initialLog: WeakLog
) extends CachedCompilerCompat
with java.io.Closeable {

/////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -86,7 +90,7 @@ private final class CachedCompiler0(args: Array[String], output: Output, initial
settings.outputDirs.setSingleOutput(outputFilepath.toString)
}

val command = Command(args.toList, settings)
val command = new CompilerCommand(args.toList, settings)
private[this] val dreporter = DelegatingReporter(settings, initialLog.reporter)
try {
if (!noErrors(dreporter)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Compat._

private object DelegatingReporter {
def apply(settings: scala.tools.nsc.Settings, delegate: xsbti.Reporter): DelegatingReporter =
new DelegatingReporter(Command.getWarnFatal(settings), Command.getNoWarn(settings), delegate)
new DelegatingReporter(settings.fatalWarnings.value, settings.nowarn.value, delegate)

class PositionImpl(
sourcePath0: Option[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package xsbt
import xsbti.{ Logger, VirtualFile }
import scala.reflect.io.AbstractFile
import Log.debug
import scala.tools.nsc.CompilerCommand

class ScaladocBridge extends xsbti.compile.ScaladocInterface2 {
def run(sources: Array[VirtualFile], args: Array[String], log: Logger, delegate: xsbti.Reporter) =
Expand All @@ -29,7 +30,7 @@ private class Runner(
import scala.tools.nsc.{ doc, Global, reporters }
import reporters.Reporter
val docSettings: doc.Settings = new doc.Settings(Log.settingsError(log))
val command = Command(args.toList, docSettings)
val command = new CompilerCommand(args.toList, docSettings)
val reporter = DelegatingReporter(docSettings, delegate)
def noErrors = !reporter.hasErrors && command.ok

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public interface ScalaCompiler {
* will report on the file being compiled.
*/
void compile(VirtualFile[] sources,
VirtualFile[] classpath,
FileConverter converter,
DependencyChanges changes,
String[] options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ final class AnalyzingCompiler(

override def compile(
sources: Array[VirtualFile],
classpath: Array[VirtualFile],
converter: FileConverter,
changes: DependencyChanges,
options: Array[String],
Expand All @@ -80,10 +81,12 @@ final class AnalyzingCompiler(
log: xLogger
): Unit = {
val progress = if (progressOpt.isPresent) progressOpt.get else IgnoreProgress
val cp = classpath.map(converter.toPath)
val arguments = compArgs.makeArguments(Nil, cp, options).toArray

loadService(classOf[CompilerInterface2], log) match {
case Some(intf) =>
intf.run(sources, changes, options, output, callback, reporter, progress, log)
intf.run(sources, changes, arguments, output, callback, reporter, progress, log)
case _ =>
// fall back to old reflection if CompilerInterface2 is not supported
val compilerBridgeClassName = "xsbt.CompilerInterface"
Expand All @@ -93,7 +96,7 @@ final class AnalyzingCompiler(
classOf[Output],
classOf[xLogger],
classOf[Reporter]
)(options, output, log, reporter).asInstanceOf[CachedCompiler]: @silent
)(arguments, output, log, reporter).asInstanceOf[CachedCompiler]: @silent
val fileSources: Array[File] = sources.map(converter.toPath(_).toFile)
try {
invoke(bridge, bridgeClass, "run", log)(
Expand Down
15 changes: 5 additions & 10 deletions zinc/src/main/scala/sbt/internal/inc/MixedAnalyzingCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ final class MixedAnalyzingCompiler(
) {
private[this] val absClasspath = config.classpath.map(toAbsolute(_))

/** Mechanism to work with compiler arguments. */
private[this] val cArgs =
new CompilerArguments(config.compiler.scalaInstance, config.compiler.classpathOptions)

/**
* Compile java and run analysis.
*/
Expand Down Expand Up @@ -159,17 +155,16 @@ final class MixedAnalyzingCompiler(
if (config.currentSetup.order == Mixed) incSrc
else scalaSrcs

val cp: Seq[Path] = (extraClasspath map { x =>
x.toAbsolutePath
}) ++ absClasspath.map(config.converter.toPath)
val arguments =
cArgs.makeArguments(Nil, cp, scalacOpts)
val cp: Seq[VirtualFile] = (extraClasspath map { x =>
config.converter.toVirtualFile(x.toAbsolutePath)
}) ++ absClasspath
timed("Scala compilation", log) {
config.compiler.compile(
sources.toArray,
cp.toArray,
config.converter,
changes,
arguments.toArray,
scalacOpts.toArray,
output,
callback,
config.reporter,
Expand Down

0 comments on commit 864444c

Please sign in to comment.