Merge pull request #6414 from adpi2/fix-6410

Fix internal dependency configurations
This commit is contained in:
eugene yokota 2021-03-23 16:13:53 -04:00 committed by GitHub
commit 3e125fa040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 6 deletions

View File

@ -14,19 +14,21 @@ private[sbt] object InternalDependencies {
def configurations: Def.Initialize[Seq[(ProjectRef, Set[String])]] = Def.setting {
val allConfigs = Classpaths.allConfigs(configuration.value).map(_.name).toSet
val ref = thisProjectRef.value
val projectDependencies = buildDependencies.value.classpath.get(ref).toSeq.flatten
val applicableConfigs = allConfigs + "*"
((ref -> allConfigs) +: buildDependencies.value.classpath
.get(ref)
.toSeq
.flatMap(_.flatMap {
((ref -> allConfigs) +:
projectDependencies.flatMap {
case ResolvedClasspathDependency(p, rawConfigs) =>
val configs = rawConfigs.getOrElse("*->compile").split(";").flatMap { config =>
config.split("->") match {
case Array(n, c) if applicableConfigs.contains(n) => Some(c)
case _ => None
case Array(n) if applicableConfigs.contains(n) =>
// "test" is equivalent to "compile->test"
Some("compile")
case _ => None
}
}
if (configs.isEmpty) None else Some(p -> configs.toSet)
})).distinct
}).distinct
}
}

View File

@ -0,0 +1,19 @@
lazy val a = project.in(file("a")).dependsOn(b % Test)
lazy val b = project.in(file("b")).dependsOn(c)
lazy val c = project.in(file("c"))
def getConfigs(key: SettingKey[Seq[(ProjectRef, Set[ConfigKey])]]):
Def.Initialize[Map[String, Set[String]]] =
Def.setting(key.value.map { case (p, c) => p.project -> c.map(_.name) }.toMap)
TaskKey[Unit]("check") := {
val testDeps = getConfigs(a / Test / bspInternalDependencyConfigurations).value
val expected = Map(
"a" -> Set("compile", "test"),
"b" -> Set("compile"),
"c" -> Set("compile")
)
assert(testDeps == expected)
}

View File

@ -0,0 +1 @@
> check