From 0f412f32f4ae390e4bd79c7bd78de1a63e0e6b64 Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Wed, 28 Feb 2024 14:35:01 +0100 Subject: [PATCH] Fix 134: ignore corresponding internal config --- .../scala/GithubDependencyGraphPlugin.scala | 14 ++++- .../dependency-manifest/ignore-test/build.sbt | 56 +++++++++++++++++++ .../ignore-test/project/plugins.sbt | 3 + .../dependency-manifest/ignore-test/test | 3 + 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt create mode 100644 sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/project/plugins.sbt create mode 100644 sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/test diff --git a/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala b/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala index a68648f..ba385c4 100644 --- a/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala +++ b/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala @@ -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) @@ -125,6 +127,13 @@ 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) @@ -132,7 +141,10 @@ object GithubDependencyGraphPlugin extends AutoPlugin { .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 diff --git a/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt new file mode 100644 index 0000000..dbfa89f --- /dev/null +++ b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt @@ -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")) +} diff --git a/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/project/plugins.sbt b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/project/plugins.sbt new file mode 100644 index 0000000..f607e8f --- /dev/null +++ b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/project/plugins.sbt @@ -0,0 +1,3 @@ +val pluginVersion = sys.props("plugin.version") + +addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-submission" % pluginVersion) diff --git a/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/test b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/test new file mode 100644 index 0000000..65fd529 --- /dev/null +++ b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/test @@ -0,0 +1,3 @@ +> p1 / checkTest +> Global / ignoreTestConfig +> p1 / checkIgnoreTest