From 680713f6663f3c6339394bbc5e905d26b99ce54c Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Thu, 8 May 2014 20:26:22 +0200 Subject: [PATCH] Add Ant-style incremental compilation mode. This commit implements an Ant-style incremental compilation mode. This mode emulates what Ant's scalac command does. It recompiles just changed source files and does not perform any invalidation of dependencies. This is a very naive mode of incremental compilation that very often leads to broken binaries. The Ant-style mode is being introduced because Scala team needs it for migration of Scala compiler to sbt. The name hashing algorithm doesn't work well with Scala compiler sources due to deep inheritance chains. There's a plan to refactor compiler's code to use more composition instead of inheritance. Once Scala compiler sources are refactored to work well with name hashing algorithm, Ant-style mode will be deleted immediately. --- .../src/main/scala/sbt/inc/Incremental.scala | 27 ++++++++++++++++--- .../compiler-project/inc-ant-style/build.sbt | 2 +- .../inc-ant-style/{pending => test} | 0 3 files changed, 25 insertions(+), 4 deletions(-) rename sbt/src/sbt-test/compiler-project/inc-ant-style/{pending => test} (100%) diff --git a/compile/inc/src/main/scala/sbt/inc/Incremental.scala b/compile/inc/src/main/scala/sbt/inc/Incremental.scala index ccce0065e..01f3a8749 100644 --- a/compile/inc/src/main/scala/sbt/inc/Incremental.scala +++ b/compile/inc/src/main/scala/sbt/inc/Incremental.scala @@ -21,10 +21,12 @@ object Incremental { options: IncOptions)(implicit equivS: Equiv[Stamp]): (Boolean, Analysis) = { val incremental: IncrementalCommon = - if (!options.nameHashing) - new IncrementalDefaultImpl(log, options) - else + if (options.nameHashing) new IncrementalNameHashing(log, options) + else if (options.antStyle) + new IncrementalAntStyle(log, options) + else + new IncrementalDefaultImpl(log, options) val initialChanges = incremental.changedInitial(entry, sources, previous, current, forEntry) val binaryChanges = new DependencyChanges { val modifiedBinaries = initialChanges.binaryDeps.toArray @@ -573,3 +575,22 @@ private final class IncrementalNameHashing(log: Logger, options: IncOptions) ext f => relations.memberRef.internal.reverse(f) } + +private final class IncrementalAntStyle(log: Logger, options: IncOptions) extends IncrementalCommon(log, options) { + + /** Ant-style mode doesn't do anything special with package objects */ + override protected def invalidatedPackageObjects(invalidated: Set[File], relations: Relations): Set[File] = Set.empty + + /** In Ant-style mode we don't need to compare APIs because we don't perform any invalidation */ + override protected def sameAPI[T](src: T, a: Source, b: Source): Option[APIChange[T]] = None + + /** In Ant-style mode we don't perform any invalidation */ + override protected def invalidateByExternal(relations: Relations, externalAPIChange: APIChange[String]): Set[File] = Set.empty + + /** In Ant-style mode we don't perform any invalidation */ + override protected def invalidateSource(relations: Relations, change: APIChange[File]): Set[File] = Set.empty + + /** In Ant-style mode we don't need to perform any dependency analysis hence we can always return an empty set. */ + override protected def allDeps(relations: Relations): File => Set[File] = _ => Set.empty + +} diff --git a/sbt/src/sbt-test/compiler-project/inc-ant-style/build.sbt b/sbt/src/sbt-test/compiler-project/inc-ant-style/build.sbt index b38650b6f..b25805b13 100644 --- a/sbt/src/sbt-test/compiler-project/inc-ant-style/build.sbt +++ b/sbt/src/sbt-test/compiler-project/inc-ant-style/build.sbt @@ -1,6 +1,6 @@ logLevel := Level.Debug -incOptions := incOptions.value.withNameHashing(true) +incOptions := incOptions.value.withAntStyle(true) /* Performs checks related to compilations: * a) checks in which compilation given set of files was recompiled diff --git a/sbt/src/sbt-test/compiler-project/inc-ant-style/pending b/sbt/src/sbt-test/compiler-project/inc-ant-style/test similarity index 100% rename from sbt/src/sbt-test/compiler-project/inc-ant-style/pending rename to sbt/src/sbt-test/compiler-project/inc-ant-style/test