Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
46 build-idea.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+BASE=idea
+
+COMPILER=$BASE/incremental-compiler.jar
+SOURCES=$BASE/compiler-interface-sources.jar
+INTERFACE=$BASE/sbt-interface.jar
+
+if [ -d $BASE ]; then
+ if ls $BASE/* &> /dev/null; then
+ echo Cleaning the output directory...
+ rm -r $BASE/*
+ fi
+else
+ echo Creating an output directory...
+ mkdir $BASE
+fi
+
+echo -e "Creating a JAR with SBT compiler implementation:\t$COMPILER ..."
+jar -cf $COMPILER -C compile/target/classes .
+jar -uf $COMPILER -C compile/api/target/classes .
+jar -uf $COMPILER -C compile/inc/target/classes .
+jar -uf $COMPILER -C compile/integration/target/classes .
+jar -uf $COMPILER -C compile/persist/target/classes .
+
+jar -uf $COMPILER -C util/classfile/target/classes .
+jar -uf $COMPILER -C util/classpath/target/classes .
+jar -uf $COMPILER -C util/collection/target/classes .
+jar -uf $COMPILER -C util/control/target/classes .
+jar -uf $COMPILER -C util/io/target/classes .
+jar -uf $COMPILER -C util/log/target/classes .
+jar -uf $COMPILER -C util/process/target/classes .
+jar -uf $COMPILER -C util/relation/target/classes .
+
+TEMP_SBINARY=$(mktemp -d /tmp/sbinary.XXXX)
+(cd $TEMP_SBINARY && jar -xf $HOME/.ivy2/cache/org.scala-tools.sbinary/sbinary_2.10/jars/sbinary_2.10-0.4.2.jar)
+jar -uf $COMPILER -C $TEMP_SBINARY .
+
+
+echo -e "Creating a JAR with SBT compiler interface sources:\t$SOURCES ..."
+jar -cf $SOURCES -C compile/interface/src/main/scala/xsbt .
+
+echo -e "Copying a JAR with SBT compiler interface API:\t\t$INTERFACE ..."
+cp interface/target/interface-0.13.0.jar $INTERFACE
+
+echo "Done."
View
5 compile/inc/src/main/scala/sbt/inc/Compile.scala
@@ -17,13 +17,14 @@ object IncrementalCompile
previous: Analysis,
forEntry: File => Option[Analysis],
output: Output, log: Logger,
- options: IncOptions): (Boolean, Analysis) =
+ options: IncOptions,
+ deletionListener: Option[File => Unit] = None): (Boolean, Analysis) =
{
val current = Stamps.initial(Stamp.exists, Stamp.hash, Stamp.lastModified)
val internalMap = (f: File) => previous.relations.produced(f).headOption
val externalAPI = getExternalAPI(entry, forEntry)
try {
- Incremental.compile(sources, entry, previous, current, forEntry, doCompile(compile, internalMap, externalAPI, current, output, options), log, options)
+ Incremental.compile(sources, entry, previous, current, forEntry, doCompile(compile, internalMap, externalAPI, current, output, options), log, options, deletionListener)
} catch {
case e: xsbti.CompileCancelled =>
log.info("Compilation has been cancelled")
View
21 compile/inc/src/main/scala/sbt/inc/Incremental.scala
@@ -19,7 +19,8 @@ object Incremental
forEntry: File => Option[Analysis],
doCompile: (Set[File], DependencyChanges) => Analysis,
log: Logger,
- options: IncOptions)(implicit equivS: Equiv[Stamp]): (Boolean, Analysis) =
+ options: IncOptions,
+ deletionListener: Option[File => Unit] = None)(implicit equivS: Equiv[Stamp]): (Boolean, Analysis) =
{
val initialChanges = changedInitial(entry, sources, previous, current, forEntry, options, log)
val binaryChanges = new DependencyChanges {
@@ -30,7 +31,7 @@ object Incremental
val initialInv = invalidateInitial(previous.relations, initialChanges, log)
log.debug("All initially invalidated sources: " + initialInv + "\n")
val analysis = manageClassfiles(options) { classfileManager =>
- cycle(initialInv, sources, binaryChanges, previous, doCompile, classfileManager, 1, log, options)
+ cycle(initialInv, sources, binaryChanges, previous, doCompile, classfileManager, 1, log, options, deletionListener)
}
(!initialInv.isEmpty, analysis)
}
@@ -59,7 +60,8 @@ object Incremental
// TODO: the Analysis for the last successful compilation should get returned + Boolean indicating success
// TODO: full external name changes, scopeInvalidations
@tailrec def cycle(invalidatedRaw: Set[File], allSources: Set[File], binaryChanges: DependencyChanges, previous: Analysis,
- doCompile: (Set[File], DependencyChanges) => Analysis, classfileManager: ClassfileManager, cycleNum: Int, log: Logger, options: IncOptions): Analysis =
+ doCompile: (Set[File], DependencyChanges) => Analysis, classfileManager: ClassfileManager, cycleNum: Int, log: Logger, options: IncOptions,
+ deletionListener: Option[File => Unit]): Analysis =
if(invalidatedRaw.isEmpty)
previous
else
@@ -67,7 +69,7 @@ object Incremental
def debug(s: => String) = if (incDebug(options)) log.debug(s) else ()
val withPackageObjects = invalidatedRaw ++ invalidatedPackageObjects(invalidatedRaw, previous.relations)
val invalidated = expand(withPackageObjects, allSources, log, options)
- val pruned = prune(invalidated, previous, classfileManager)
+ val pruned = prune(invalidated, previous, classfileManager, deletionListener)
debug("********* Pruned: \n" + pruned.relations + "\n*********")
val fresh = doCompile(invalidated, binaryChanges)
@@ -80,7 +82,7 @@ object Incremental
debug("\nChanges:\n" + incChanges)
val transitiveStep = options.transitiveStep
val incInv = invalidateIncremental(merged.relations, incChanges, invalidated, cycleNum >= transitiveStep, log)
- cycle(incInv, allSources, emptyChanges, merged, doCompile, classfileManager, cycleNum+1, log, options)
+ cycle(incInv, allSources, emptyChanges, merged, doCompile, classfileManager, cycleNum+1, log, options, deletionListener)
}
private[this] def emptyChanges: DependencyChanges = new DependencyChanges {
val modifiedBinaries = new Array[File](0)
@@ -286,12 +288,15 @@ object Incremental
newInv ++ initialDependsOnNew
}
- def prune(invalidatedSrcs: Set[File], previous: Analysis): Analysis =
- prune(invalidatedSrcs, previous, ClassfileManager.deleteImmediately())
+ def prune(invalidatedSrcs: Set[File], previous: Analysis, deletionListener: Option[File => Unit]): Analysis =
+ prune(invalidatedSrcs, previous, ClassfileManager.deleteImmediately(), deletionListener)
- def prune(invalidatedSrcs: Set[File], previous: Analysis, classfileManager: ClassfileManager): Analysis =
+ def prune(invalidatedSrcs: Set[File], previous: Analysis, classfileManager: ClassfileManager, deletionListener: Option[File => Unit]): Analysis =
{
+ val filesToDelete = invalidatedSrcs.flatMap(previous.relations.products)
classfileManager.delete( invalidatedSrcs.flatMap(previous.relations.products) )
+ deletionListener.foreach(listener => filesToDelete.foreach(listener(_)))
+
previous -- invalidatedSrcs
}
View
40 compile/integration/src/main/scala/sbt/compiler/AggressiveCompile.scala
@@ -17,12 +17,14 @@ import inc._
import xsbti.{ Reporter, AnalysisCallback }
import xsbti.api.Source
- import xsbti.compile.{CompileOrder, DependencyChanges, GlobalsCache, Output, SingleOutput, MultipleOutput, CompileProgress}
+ import xsbti.compile.{CompileOrder, DependencyChanges, GlobalsCache, Output, SingleOutput, MultipleOutput, CompileProgress, ExtendedCompileProgress}
import CompileOrder.{JavaThenScala, Mixed, ScalaThenJava}
final class CompileConfiguration(val sources: Seq[File], val classpath: Seq[File],
val previousAnalysis: Analysis, val previousSetup: Option[CompileSetup], val currentSetup: CompileSetup, val progress: Option[CompileProgress], val getAnalysis: File => Option[Analysis], val definesClass: DefinesClass,
- val reporter: Reporter, val compiler: AnalyzingCompiler, val javac: xsbti.compile.JavaCompiler, val cache: GlobalsCache, val incOptions: IncOptions)
+ val reporter: Reporter, val compiler: AnalyzingCompiler, val javac: xsbti.compile.JavaCompiler, val cache: GlobalsCache, val incOptions: IncOptions) {
+ def compilerOpt: Option[AnalyzingCompiler] = Option(compiler)
+}
class AggressiveCompile(cacheFile: File)
{
@@ -41,7 +43,8 @@ class AggressiveCompile(cacheFile: File)
skip: Boolean = false,
incrementalCompilerOptions: IncOptions)(implicit log: Logger): Analysis =
{
- val setup = new CompileSetup(output, new CompileOptions(options, javacOptions), compiler.scalaInstance.actualVersion, compileOrder)
+ val version = if (compiler == null) "" else compiler.scalaInstance.actualVersion
+ val setup = new CompileSetup(output, new CompileOptions(options, javacOptions), version, compileOrder)
compile1(sources, classpath, setup, progress, store, analysisMap, definesClass,
compiler, javac, reporter, skip, cache, incrementalCompilerOptions)
}
@@ -79,11 +82,15 @@ class AggressiveCompile(cacheFile: File)
import currentSetup._
val absClasspath = classpath.map(_.getAbsoluteFile)
val apiOption = (api: Either[Boolean, Source]) => api.right.toOption
- val cArgs = new CompilerArguments(compiler.scalaInstance, compiler.cp)
- val searchClasspath = explicitBootClasspath(options.options) ++ withBootclasspath(cArgs, absClasspath)
+ val cArgsOpt: Option[CompilerArguments] = compilerOpt.map(compiler => new CompilerArguments(compiler.scalaInstance, compiler.cp))
+ val searchClasspath = explicitBootClasspath(options.options) ++ cArgsOpt.map(it => withBootclasspath(it, absClasspath)).getOrElse(absClasspath)
val entry = Locate.entry(searchClasspath, definesClass)
- val compile0 = (include: Set[File], changes: DependencyChanges, callback: AnalysisCallback) => {
+ val compile0 = (include: Set[File], changes: DependencyChanges, externalCallback: AnalysisCallback) => {
+ val callback = progress match {
+ case Some(ext: ExtendedCompileProgress) => new AnalysisCallbackAdapter(ext, externalCallback)
+ case _ => externalCallback
+ }
val outputDirs = outputDirectories(output)
outputDirs foreach (IO.createDirectory)
val incSrc = sources.filter(include)
@@ -92,11 +99,13 @@ class AggressiveCompile(cacheFile: File)
def compileScala() =
if(!scalaSrcs.isEmpty)
{
- val sources = if(order == Mixed) incSrc else scalaSrcs
- val arguments = cArgs(Nil, absClasspath, None, options.options)
- timed("Scala compilation", log) {
- compiler.compile(sources, changes, arguments, output, callback, reporter, cache, log, progress)
- }
+ for (comp <- compilerOpt; cargs <- cArgsOpt) {
+ val sources = if(order == Mixed) incSrc else scalaSrcs
+ val arguments = cargs(Nil, absClasspath, None, options.options)
+ timed("Scala compilation", log) {
+ compiler.compile(sources, changes, arguments, output, callback, reporter, cache, log, progress)
+ }
+ }
}
def compileJava() =
if(!javaSrcs.isEmpty)
@@ -142,12 +151,17 @@ class AggressiveCompile(cacheFile: File)
if(order == JavaThenScala) { compileJava(); compileScala() } else { compileScala(); compileJava() }
}
+ val deletionListener = (file: File) => config.progress.foreach {
+ case ext: ExtendedCompileProgress => ext.deleted(file)
+ case _ =>
+ }
+
val sourcesSet = sources.toSet
val analysis = previousSetup match {
case Some(previous) if equiv.equiv(previous, currentSetup) => previousAnalysis
- case _ => Incremental.prune(sourcesSet, previousAnalysis)
+ case _ => Incremental.prune(sourcesSet, previousAnalysis, Some(deletionListener))
}
- IncrementalCompile(sourcesSet, entry, compile0, analysis, getAnalysis, output, log, incOptions)
+ IncrementalCompile(sourcesSet, entry, compile0, analysis, getAnalysis, output, log, incOptions, Some(deletionListener))
}
private[this] def outputDirectories(output: Output): Seq[File] = output match {
case single: SingleOutput => List(single.outputDirectory)
View
34 compile/src/main/scala/sbt/compiler/AnalysisCallbackAdapter.scala
@@ -0,0 +1,34 @@
+package sbt.compiler
+
+import xsbti.{Severity, Position, AnalysisCallback}
+import xsbti.compile.ExtendedCompileProgress
+import java.io.File
+import xsbti.api.SourceAPI
+
+class AnalysisCallbackAdapter(progress: ExtendedCompileProgress, delegate: AnalysisCallback) extends xsbti.AnalysisCallback{
+
+ def beginSource(source: File) =
+ delegate.beginSource(source)
+
+ def problem(what: String, pos: Position, msg: String, severity: Severity, reported: Boolean) =
+ delegate.problem(what, pos, msg, severity, reported)
+
+ def api(sourceFile: File, source: SourceAPI) =
+ delegate.api(sourceFile, source)
+
+ def endSource(sourcePath: File) =
+ delegate.endSource(sourcePath)
+
+ def generatedClass(source: File, module: File, name: String) = {
+ // NON BOILERPLATE
+ progress.generated(source, module, name)
+
+ delegate.generatedClass(source, module, name)
+ }
+
+ def binaryDependency(binary: File, name: String, source: File, publicInherited: Boolean) =
+ delegate.binaryDependency(binary, name, source, publicInherited)
+
+ def sourceDependency(dependsOn: File, source: File, publicInherited: Boolean) =
+ delegate.sourceDependency(dependsOn, source, publicInherited)
+}
View
2 interface/src/main/java/xsbti/compile/CompileProgress.java
@@ -4,4 +4,4 @@
void startUnit(String phase, String unitPath);
boolean advance(int current, int total);
-}
+}
View
9 interface/src/main/java/xsbti/compile/ExtendedCompileProgress.java
@@ -0,0 +1,9 @@
+package xsbti.compile;
+
+import java.io.File;
+
+public interface ExtendedCompileProgress extends CompileProgress {
+ void generated(File source, File module, String name);
+
+ void deleted(File module);
+}

No commit comments for this range

Something went wrong with that request. Please try again.