Skip to content
This repository has been archived by the owner on Apr 8, 2021. It is now read-only.

Commit

Permalink
fix tree generation on projects with cached resolution
Browse files Browse the repository at this point in the history
Before 7992dc9, a custom, non-cached-resolution-aware update task was
used to generate the report that the tree is based on, effectively
ignoring the cached resolution flag at the project level.

Starting 7992dc9, this plugin, when run with sbt 0.13.8 or sbt 1.2.5+,
relies on cached-resolution-backed reports for projects that have
the engine enabled via `updateOptions`. Other 1.x releases are not
directly impacted as sbt had a buggy implementation of the feature
anyway, see sbt/sbt#3761.

Cached resolution has the side effect of generating an ivy report
with artificial module descriptors which makes it hard to reconstruct
the tree without inlining sbt internals (see below), so this
effectively ignores it *for the purpose of the tree generation*, even
if the project enabled it for the regular report.

ModuleId(
  org.scala-sbt.temp,
  temp-resolve-e2a956132f02c038285b41b374c02f5838076f37,
  1.0
)

https://github.com/sbt/librarymanagement/blob/984de6f/ivy/src/main/scala/sbt/internal/librarymanagement/ivyint/CachedResolutionResolveEngine.scala#L137
  • Loading branch information
github-brice-jaglin committed Aug 27, 2019
1 parent 625f87a commit 31d9355
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ trait DependencyGraphKeys {
"Aggregates and shows information about the licenses of dependencies")

// internal
private[graph] val ignoreMissingUpdate = TaskKey[UpdateReport]("dependencyUpdate", "sbt-dependency-graph version of update")
private[graph] val dependencyUpdate = TaskKey[UpdateReport]("dependencyUpdate", "sbt-dependency-graph version of update")
private[graph] val moduleGraphStore = TaskKey[ModuleGraph]("module-graph-store", "The stored module-graph from the last run")
val whatDependsOn = InputKey[String]("what-depends-on", "Shows information about what depends on the given module")
private[graph] val crossProjectId = SettingKey[ModuleID]("dependency-graph-cross-project-id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,28 @@ object DependencyGraphSettings {

def baseSettings = Seq(
ivyReportFunction := ivyReportFunctionTask.value,
updateConfiguration in ignoreMissingUpdate := updateConfiguration.value.withMissingOk(true),

ignoreMissingUpdate :=
// inTask will make sure the new definition will pick up `updateConfiguration in ignoreMissingUpdate`
SbtAccess.inTask(ignoreMissingUpdate, Classpaths.updateTask).value,
// disable the cached resolution engine (exposing a scoped `ivyModule` used directly by `updateTask`), as it
// generates artificial module descriptors which are internal to sbt, making it hard to reconstruct the
// dependency tree
updateOptions in dependencyUpdate := updateOptions.value.withCachedResolution(false),
ivyConfiguration in dependencyUpdate :=
// inTask will make sure the new definition will pick up `updateOptions in dependencyUpdate`
SbtAccess.inTask(dependencyUpdate, Classpaths.mkIvyConfiguration).value,
ivyModule in dependencyUpdate := {
// concatenating & inlining ivySbt & ivyModule default task implementations, as `SbtAccess.inTask` does
// NOT correctly force the scope when applied to `TaskKey.toTask` instances (as opposed to raw
// implementations like `Classpaths.mkIvyConfiguration` or `Classpaths.updateTask`)
val is = new IvySbt((ivyConfiguration in dependencyUpdate).value)
new is.Module(moduleSettings.value)
},

// don't fail on missing dependencies
updateConfiguration in dependencyUpdate := updateConfiguration.value.withMissingOk(true),

dependencyUpdate :=
// inTask will make sure the new definition will pick up `ivyModule/updateConfiguration in dependencyUpdate`
SbtAccess.inTask(dependencyUpdate, Classpaths.updateTask).value,

filterScalaLibrary in Global := true)

Expand All @@ -57,10 +74,10 @@ object DependencyGraphSettings {

def ivyReportForConfig(config: Configuration) = inConfig(config)(
Seq(
ivyReport := { Def.task { ivyReportFunction.value.apply(config.toString) } dependsOn (ignoreMissingUpdate) }.value,
ivyReport := { Def.task { ivyReportFunction.value.apply(config.toString) } dependsOn (dependencyUpdate) }.value,
crossProjectId := sbt.CrossVersion(scalaVersion.value, scalaBinaryVersion.value)(projectID.value),
moduleGraphSbt :=
ignoreMissingUpdate.value.configuration(configuration.value).map(report SbtUpdateReport.fromConfigurationReport(report, crossProjectId.value)).getOrElse(ModuleGraph.empty),
dependencyUpdate.value.configuration(configuration.value).map(report SbtUpdateReport.fromConfigurationReport(report, crossProjectId.value)).getOrElse(ModuleGraph.empty),
moduleGraphIvyReport := IvyReport.fromReportFile(absoluteReportPath(ivyReport.value)),
moduleGraph := {
sbtVersion.value match {
Expand Down
17 changes: 17 additions & 0 deletions src/sbt-test/sbt-dependency-graph/cachedResolution/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
scalaVersion := "2.12.9"

libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.28"
updateOptions := updateOptions.value.withCachedResolution(true)

TaskKey[Unit]("check") := {
val report = (ivyReport in Test).value
val graph = (asciiTree in Test).value

def sanitize(str: String): String = str.split('\n').drop(1).mkString("\n")
val expectedGraph =
"""default:cachedresolution_2.12:0.1.0-SNAPSHOT
| +-org.slf4j:slf4j-api:1.7.28
| """.stripMargin
require(sanitize(graph) == sanitize(expectedGraph), "Graph for report %s was '\n%s' but should have been '\n%s'" format (report, sanitize(graph), sanitize(expectedGraph)))
()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % sys.props("project.version"))
1 change: 1 addition & 0 deletions src/sbt-test/sbt-dependency-graph/cachedResolution/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> check

0 comments on commit 31d9355

Please sign in to comment.