Skip to content

Commit

Permalink
Merge pull request #165 from adpi2/fix-134
Browse files Browse the repository at this point in the history
Fix 134: ignore corresponding internal config
  • Loading branch information
adpi2 authored Feb 28, 2024
2 parents 3264787 + 0f412f3 commit f3c0455
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
val baseDirectory = Keys.baseDirectory.value
val logger = Keys.streams.value.log
val state = Keys.state.value
val thisProject = Keys.thisProject.value
val internalConfigurationMap = Keys.internalConfigurationMap.value

val inputOpt = state.get(githubSubmitInputKey)
val buildFileOpt = state.get(githubBuildFile)
Expand All @@ -125,14 +127,24 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
val ignoredConfigs = inputOpt.toSeq.flatMap(_.ignoredConfigs).toSet
val moduleName = crossVersion(projectID).name

// a reverse view of internalConfigurationMap (internal-test -> test)
val reverseConfigurationMap =
thisProject.configurations
.map(c => internalConfigurationMap(c).name -> c.name)
.filter { case (internal, c) => internal != c }
.toMap

def getReference(module: ModuleID): String =
crossVersion(module)
.withConfigurations(None)
.withExtraAttributes(Map.empty)
.toString

def includeConfig(config: ConfigRef): Boolean =
if (ignoredConfigs.contains(config.name)) {
// if ignoredConfigs contain 'test' we should also ignore 'test-internal'
if (
ignoredConfigs.contains(config.name) || reverseConfigurationMap.get(config.name).exists(ignoredConfigs.contains)
) {
logger.info(s"Excluding config ${config.name} of ${moduleName} from its dependency graph")
false
} else true
Expand Down
56 changes: 56 additions & 0 deletions sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import ch.epfl.scala.githubapi.DependencyRelationship
import ch.epfl.scala.githubapi.DependencyScope
import ch.epfl.scala.githubapi.Manifest
import ch.epfl.scala.SubmitInput
import sjsonnew.shaded.scalajson.ast.unsafe.JString

val checkTest = taskKey[Unit]("Check munit_3 is in the manifest ")
val ignoreTestConfig = taskKey[StateTransform]("Ignore the test config in the submit input")
val checkIgnoreTest = taskKey[Unit]("Check scaladoc_3 is absent in the manifest")

inThisBuild(
Seq(
organization := "ch.epfl.scala",
version := "1.2.0-SNAPSHOT",
scalaVersion := "3.2.1"
)
)

Global / ignoreTestConfig := {
val input = SubmitInput(None, Vector.empty, ignoredConfigs = Vector("test"))
StateTransform(state => state.put(githubSubmitInputKey, input))
}

lazy val p1 = project
.in(file("p1"))
.settings(
libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test,
checkTest := {
val manifest = githubDependencyManifest.value.get
checkDependency(manifest, "org.scalameta:munit_3:0.7.29")(
expectedRelationship = DependencyRelationship.direct,
expectedScope = DependencyScope.development,
expectedConfig = "test"
)
},
checkIgnoreTest := {
val manifest = githubDependencyManifest.value.get
val suspicious = manifest.resolved.keys.filter(dep => dep.contains("munit_3"))
assert(suspicious.isEmpty, s"The manifest should not contain munit_3, found ${suspicious.mkString(", ")}")
}
)

def checkDependency(manifest: Manifest, name: String)(
expectedRelationship: DependencyRelationship = DependencyRelationship.direct,
expectedScope: DependencyScope = DependencyScope.runtime,
expectedConfig: String = "compile",
expectedDeps: Seq[String] = Seq.empty
): Unit = {
val node = manifest.resolved(name)
assert(node.package_url.startsWith("pkg:maven/"), s"Wrong package_url for node $name: ${node.package_url}")
assert(node.relationship.contains(expectedRelationship), s"Wrong relationship for node $name: ${node.relationship}")
assert(node.scope.contains(expectedScope), s"Wrong scope for node $name: ${node.scope}")
val configurations = node.metadata.get("config").collect { case JString(c) => c }
assert(configurations.contains(expectedConfig), s"Wrong config in metadata for node $name: $configurations")
expectedDeps.foreach(d => assert(node.dependencies.contains(d), s"missing dependency $d in node $name"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val pluginVersion = sys.props("plugin.version")

addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-submission" % pluginVersion)
3 changes: 3 additions & 0 deletions sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> p1 / checkTest
> Global / ignoreTestConfig
> p1 / checkIgnoreTest

0 comments on commit f3c0455

Please sign in to comment.