Skip to content

Commit f3c0455

Browse files
authored
Merge pull request #165 from adpi2/fix-134
Fix 134: ignore corresponding internal config
2 parents 3264787 + 0f412f3 commit f3c0455

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala

+13-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
117117
val baseDirectory = Keys.baseDirectory.value
118118
val logger = Keys.streams.value.log
119119
val state = Keys.state.value
120+
val thisProject = Keys.thisProject.value
121+
val internalConfigurationMap = Keys.internalConfigurationMap.value
120122

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

130+
// a reverse view of internalConfigurationMap (internal-test -> test)
131+
val reverseConfigurationMap =
132+
thisProject.configurations
133+
.map(c => internalConfigurationMap(c).name -> c.name)
134+
.filter { case (internal, c) => internal != c }
135+
.toMap
136+
128137
def getReference(module: ModuleID): String =
129138
crossVersion(module)
130139
.withConfigurations(None)
131140
.withExtraAttributes(Map.empty)
132141
.toString
133142

134143
def includeConfig(config: ConfigRef): Boolean =
135-
if (ignoredConfigs.contains(config.name)) {
144+
// if ignoredConfigs contain 'test' we should also ignore 'test-internal'
145+
if (
146+
ignoredConfigs.contains(config.name) || reverseConfigurationMap.get(config.name).exists(ignoredConfigs.contains)
147+
) {
136148
logger.info(s"Excluding config ${config.name} of ${moduleName} from its dependency graph")
137149
false
138150
} else true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import ch.epfl.scala.githubapi.DependencyRelationship
2+
import ch.epfl.scala.githubapi.DependencyScope
3+
import ch.epfl.scala.githubapi.Manifest
4+
import ch.epfl.scala.SubmitInput
5+
import sjsonnew.shaded.scalajson.ast.unsafe.JString
6+
7+
val checkTest = taskKey[Unit]("Check munit_3 is in the manifest ")
8+
val ignoreTestConfig = taskKey[StateTransform]("Ignore the test config in the submit input")
9+
val checkIgnoreTest = taskKey[Unit]("Check scaladoc_3 is absent in the manifest")
10+
11+
inThisBuild(
12+
Seq(
13+
organization := "ch.epfl.scala",
14+
version := "1.2.0-SNAPSHOT",
15+
scalaVersion := "3.2.1"
16+
)
17+
)
18+
19+
Global / ignoreTestConfig := {
20+
val input = SubmitInput(None, Vector.empty, ignoredConfigs = Vector("test"))
21+
StateTransform(state => state.put(githubSubmitInputKey, input))
22+
}
23+
24+
lazy val p1 = project
25+
.in(file("p1"))
26+
.settings(
27+
libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test,
28+
checkTest := {
29+
val manifest = githubDependencyManifest.value.get
30+
checkDependency(manifest, "org.scalameta:munit_3:0.7.29")(
31+
expectedRelationship = DependencyRelationship.direct,
32+
expectedScope = DependencyScope.development,
33+
expectedConfig = "test"
34+
)
35+
},
36+
checkIgnoreTest := {
37+
val manifest = githubDependencyManifest.value.get
38+
val suspicious = manifest.resolved.keys.filter(dep => dep.contains("munit_3"))
39+
assert(suspicious.isEmpty, s"The manifest should not contain munit_3, found ${suspicious.mkString(", ")}")
40+
}
41+
)
42+
43+
def checkDependency(manifest: Manifest, name: String)(
44+
expectedRelationship: DependencyRelationship = DependencyRelationship.direct,
45+
expectedScope: DependencyScope = DependencyScope.runtime,
46+
expectedConfig: String = "compile",
47+
expectedDeps: Seq[String] = Seq.empty
48+
): Unit = {
49+
val node = manifest.resolved(name)
50+
assert(node.package_url.startsWith("pkg:maven/"), s"Wrong package_url for node $name: ${node.package_url}")
51+
assert(node.relationship.contains(expectedRelationship), s"Wrong relationship for node $name: ${node.relationship}")
52+
assert(node.scope.contains(expectedScope), s"Wrong scope for node $name: ${node.scope}")
53+
val configurations = node.metadata.get("config").collect { case JString(c) => c }
54+
assert(configurations.contains(expectedConfig), s"Wrong config in metadata for node $name: $configurations")
55+
expectedDeps.foreach(d => assert(node.dependencies.contains(d), s"missing dependency $d in node $name"))
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val pluginVersion = sys.props("plugin.version")
2+
3+
addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-submission" % pluginVersion)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> p1 / checkTest
2+
> Global / ignoreTestConfig
3+
> p1 / checkIgnoreTest

0 commit comments

Comments
 (0)