From bf4901f9ef23166e386c9c8fa1781187c098b399 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 16 Jul 2017 16:45:08 -0400 Subject: [PATCH] Some helpful changes for update caching There's a bug in sbt/util#93 --- main/src/main/scala/sbt/Defaults.scala | 6 ++- .../sbt/internal/LibraryManagement.scala | 10 ++--- sbt/src/main/scala/Import.scala | 12 ++++- .../cache-update/build.sbt | 44 +++++++++++++++++-- 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index ed0c2d64f..7b8d535e6 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -2284,11 +2284,14 @@ object Classpaths { import UpdateLogging.{ Full, DownloadOnly, Default } val conf = updateConfiguration.value val maybeUpdateLevel = (logLevel in update).?.value - maybeUpdateLevel.orElse(state0.get(logLevel.key)) match { + val conf1 = maybeUpdateLevel.orElse(state0.get(logLevel.key)) match { case Some(Level.Debug) if conf.logging == Default => conf.withLogging(logging = Full) case Some(_) if conf.logging == Default => conf.withLogging(logging = DownloadOnly) case _ => conf } + + // logical clock is folded into UpdateConfiguration + conf1.withLogicalClock(LogicalClock(state0.hashCode)) } val evictionOptions = Def.taskDyn { @@ -2307,7 +2310,6 @@ object Classpaths { force = shouldForce, depsUpdated = transitiveUpdate.value.exists(!_.stats.cached), uwConfig = (unresolvedWarningConfiguration in update).value, - logicalClock = LogicalClock(state0.hashCode), depDir = Some(dependencyCacheDirectory.value), ewo = evictionOptions, mavenStyle = publishMavenStyle.value, diff --git a/main/src/main/scala/sbt/internal/LibraryManagement.scala b/main/src/main/scala/sbt/internal/LibraryManagement.scala index 29e1ee1a2..44093297b 100644 --- a/main/src/main/scala/sbt/internal/LibraryManagement.scala +++ b/main/src/main/scala/sbt/internal/LibraryManagement.scala @@ -9,14 +9,13 @@ import sbt.internal.util.HListFormats._ import sbt.librarymanagement._ import sbt.librarymanagement.ivy._ import sbt.librarymanagement.syntax._ -import sbt.internal.util.HListFormats._ import sbt.util.{ CacheStore, CacheStoreFactory, Logger, Tracked } -object LibraryManagement { +private[sbt] object LibraryManagement { private type UpdateInputs = IvyConfiguration :+: ModuleSettings :+: UpdateConfiguration :+: HNil - private[sbt] def cachedUpdate( + def cachedUpdate( cacheStoreFactory: CacheStoreFactory, label: String, module: IvySbt#Module, @@ -26,7 +25,6 @@ object LibraryManagement { force: Boolean, depsUpdated: Boolean, uwConfig: UnresolvedWarningConfiguration, - logicalClock: LogicalClock, depDir: Option[File], ewo: EvictionWarningOptions, mavenStyle: Boolean, @@ -118,7 +116,9 @@ object LibraryManagement { val settings = module.moduleSettings val outStore = cacheStoreFactory.make("output") val handler = if (skip && !force) skipResolve(outStore) else doResolve(outStore) - handler(ivyConfig :+: settings :+: updateConfig :+: HNil) + // Remove clock for caching purpose + val withoutClock = updateConfig.withLogicalClock(LogicalClock.unknown) + handler(ivyConfig :+: settings :+: withoutClock :+: HNil) } private[this] def fileUptodate(file: File, stamps: Map[File, Long]): Boolean = diff --git a/sbt/src/main/scala/Import.scala b/sbt/src/main/scala/Import.scala index cd0d6f274..ce277f03b 100644 --- a/sbt/src/main/scala/Import.scala +++ b/sbt/src/main/scala/Import.scala @@ -261,10 +261,14 @@ trait Import { type FileRepository = sbt.librarymanagement.FileRepository val Full = sbt.librarymanagement.Full type Full = sbt.librarymanagement.Full + val InlineConfiguration = sbt.librarymanagement.ModuleDescriptorConfiguration + type InlineConfiguration = sbt.librarymanagement.ModuleDescriptorConfiguration val IvyScala = sbt.librarymanagement.ScalaModuleInfo type IvyScala = sbt.librarymanagement.ScalaModuleInfo val JCenterRepository = sbt.librarymanagement.Resolver.JCenterRepository val JavaNet2Repository = sbt.librarymanagement.Resolver.JavaNet2Repository + type LogicalClock = sbt.librarymanagement.LogicalClock + val LogicalClock = sbt.librarymanagement.LogicalClock type MakePomConfiguration = sbt.librarymanagement.MakePomConfiguration val MakePomConfiguration = sbt.librarymanagement.MakePomConfiguration val MavenCache = sbt.librarymanagement.MavenCache @@ -275,12 +279,16 @@ trait Import { type MavenRepository = sbt.librarymanagement.MavenRepository val ModuleConfiguration = sbt.librarymanagement.ModuleConfiguration type ModuleConfiguration = sbt.librarymanagement.ModuleConfiguration + val ModuleDescriptorConfiguration = sbt.librarymanagement.ModuleDescriptorConfiguration + type ModuleDescriptorConfiguration = sbt.librarymanagement.ModuleDescriptorConfiguration val ModuleID = sbt.librarymanagement.ModuleID type ModuleID = sbt.librarymanagement.ModuleID val ModuleInfo = sbt.librarymanagement.ModuleInfo type ModuleInfo = sbt.librarymanagement.ModuleInfo val ModuleReport = sbt.librarymanagement.ModuleReport type ModuleReport = sbt.librarymanagement.ModuleReport + val ModuleSettings = sbt.librarymanagement.ModuleSettings + type ModuleSettings = sbt.librarymanagement.ModuleSettings val OrganizationArtifactReport = sbt.librarymanagement.OrganizationArtifactReport type OrganizationArtifactReport = sbt.librarymanagement.OrganizationArtifactReport val Patterns = sbt.librarymanagement.Patterns @@ -315,7 +323,9 @@ trait Import { type VersionNumber = sbt.librarymanagement.VersionNumber type VersionNumberCompatibility = sbt.librarymanagement.VersionNumberCompatibility - // sbt.internal.librarymanagement + // sbt.librarymanagement.ivy + val InlineIvyConfiguration = sbt.librarymanagement.ivy.InlineIvyConfiguration + type InlineIvyConfiguration = sbt.librarymanagement.ivy.InlineIvyConfiguration type IvyPaths = sbt.librarymanagement.ivy.IvyPaths val IvyPaths = sbt.librarymanagement.ivy.IvyPaths diff --git a/sbt/src/sbt-test/dependency-management/cache-update/build.sbt b/sbt/src/sbt-test/dependency-management/cache-update/build.sbt index 1e3dfb2f1..7be748a0a 100644 --- a/sbt/src/sbt-test/dependency-management/cache-update/build.sbt +++ b/sbt/src/sbt-test/dependency-management/cache-update/build.sbt @@ -33,7 +33,12 @@ lazy val root = (project in file(".")) val s = (streams in update).value val cacheStoreFactory = s.cacheStoreFactory sub updateCacheName.value val module = ivyModule.value - val config = updateConfiguration.value + val updateConfig = updateConfiguration.value + val ivyConfiguration0 = module.owner.configuration + val moduleSettings0 = module.moduleSettings + val inline0 = moduleSettings0 match { case x: InlineConfiguration => x } + // Remove clock for caching purpose + val updateConfig0 = updateConfig.withLogicalClock(LogicalClock.unknown) import sbt.librarymanagement.ivy.IvyConfiguration import sbt.librarymanagement.{ ModuleSettings, UpdateConfiguration } @@ -47,10 +52,41 @@ lazy val root = (project in file(".")) val f: In => Unit = Tracked.inputChanged(cacheStoreFactory make "inputs") { (inChanged: Boolean, in: In) => - if (inChanged) - sys.error(s"Update cache is invalidated: ${module.owner.configuration}, ${module.moduleSettings}, $config") + val ivyConfiguration1 = in.head + val moduleSettings1 = in.tail.head + val inline1 = moduleSettings1 match { case x: InlineConfiguration => x } + val updateConfig1 = in.tail.tail.head + + if (inChanged) { + sys.error(s""" +ivyConfiguration1 == ivyConfiguration0: ${ivyConfiguration1 == ivyConfiguration0} + +ivyConfiguration1: +$ivyConfiguration1 + +ivyConfiguration0 +$ivyConfiguration0 +----- +inline1 == inline0: ${inline1 == inline0} + +inline1: +$inline1 + +inline0 +$inline0 +----- +updateConfig1 == updateConfig0: ${updateConfig1 == updateConfig0} + +updateConfig1: +$updateConfig1 + +updateConfig0 +$updateConfig0 +""") + } } - f(module.owner.configuration :+: module.moduleSettings :+: config :+: HNil) + + f(ivyConfiguration0 :+: (inline0: ModuleSettings) :+: updateConfig0 :+: HNil) }, // https://github.com/sbt/sbt/issues/3226