Skip to content
This repository was archived by the owner on May 4, 2025. It is now read-only.

Commit 9ca9b7c

Browse files
authored
Merge pull request #34 from ckipp01/rangeFix
fix: ensure ranges don't end up in manifest
2 parents 902d991 + 670a0b1 commit 9ca9b7c

File tree

5 files changed

+64
-42
lines changed

5 files changed

+64
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.bsp/
33
.metals/
44
out/
5+
manifest.json

build.sc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ object itest extends MillIntegrationTestModule {
9797
),
9898
PathRef(testBase / "eviction") -> Seq(
9999
TestInvocation.Targets(Seq("verify"), noServer = true)
100+
),
101+
PathRef(testBase / "range") -> Seq(
102+
TestInvocation.Targets(Seq("verify"), noServer = true)
100103
)
101104
)
102105
}

itest/src/minimal/manifests.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dependencies": [
1313
"com.lihaoyi:fansi_3:0.3.1",
1414
"com.lihaoyi:sourcecode_3:0.2.8",
15-
"org.scala-lang:scala3-library_3:3.0.2"
15+
"org.scala-lang:scala3-library_3:3.1.3"
1616
],
1717
"relationship": "direct",
1818
"package_url": "pkg:maven/com.lihaoyi/pprint_3@0.7.3"
@@ -23,7 +23,7 @@
2323
},
2424
"dependencies": [
2525
"com.lihaoyi:sourcecode_3:0.2.8",
26-
"org.scala-lang:scala3-library_3:3.0.2"
26+
"org.scala-lang:scala3-library_3:3.1.3"
2727
],
2828
"relationship": "indirect",
2929
"package_url": "pkg:maven/com.lihaoyi/fansi_3@0.3.1"
@@ -33,7 +33,7 @@
3333

3434
},
3535
"dependencies": [
36-
"org.scala-lang:scala3-library_3:3.0.0"
36+
"org.scala-lang:scala3-library_3:3.1.3"
3737
],
3838
"relationship": "indirect",
3939
"package_url": "pkg:maven/com.lihaoyi/sourcecode_3@0.2.8"
@@ -76,7 +76,7 @@
7676
"dependencies": [
7777
"com.lihaoyi:fansi_3:0.3.1",
7878
"com.lihaoyi:sourcecode_3:0.2.8",
79-
"org.scala-lang:scala3-library_3:3.0.2"
79+
"org.scala-lang:scala3-library_3:3.1.3"
8080
],
8181
"relationship": "direct",
8282
"package_url": "pkg:maven/com.lihaoyi/pprint_3@0.7.3"
@@ -98,7 +98,7 @@
9898
},
9999
"dependencies": [
100100
"com.lihaoyi:sourcecode_3:0.2.8",
101-
"org.scala-lang:scala3-library_3:3.0.2"
101+
"org.scala-lang:scala3-library_3:3.1.3"
102102
],
103103
"relationship": "indirect",
104104
"package_url": "pkg:maven/com.lihaoyi/fansi_3@0.3.1"
@@ -118,8 +118,8 @@
118118

119119
},
120120
"dependencies": [
121-
"junit:junit:4.13.1",
122-
"org.scala-lang:scala3-library_3:3.0.1",
121+
"junit:junit:4.13.2",
122+
"org.scala-lang:scala3-library_3:3.1.3",
123123
"org.scalameta:junit-interface:0.7.29"
124124
],
125125
"relationship": "direct",
@@ -140,7 +140,7 @@
140140

141141
},
142142
"dependencies": [
143-
"org.scala-lang:scala3-library_3:3.0.0"
143+
"org.scala-lang:scala3-library_3:3.1.3"
144144
],
145145
"relationship": "indirect",
146146
"package_url": "pkg:maven/com.lihaoyi/sourcecode_3@0.2.8"

itest/src/range/build.sc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import mill._, scalalib._
2+
import $exec.plugins
3+
import io.kipp.mill.github.dependency.graph.Graph
4+
import mill.eval.Evaluator
5+
import $ivy.`org.scalameta::munit:0.7.29`
6+
import munit.Assertions._
7+
8+
object minimal extends ScalaModule {
9+
def scalaVersion = "3.1.3"
10+
11+
def ivyDeps = Agg(
12+
ivy"org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.12.0"
13+
)
14+
}
15+
16+
def verify(ev: Evaluator) = T.command {
17+
val manifestMapping = Graph.generate(ev)()
18+
assert(manifestMapping.size == 1)
19+
20+
// We want to ensure that the transitive dependency of the above, which has a
21+
// range dependency doesn't end up in the actualy manifest as a range, but
22+
// the reconciled version. So we want to ensure `2.8.9` and not
23+
// `[2.8.6,2.0)`.
24+
val expected = Set(
25+
"org.scala-lang:scala-library:2.13.8",
26+
"org.scala-lang:scala3-library_3:3.1.3",
27+
"org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.12.0",
28+
"com.google.code.gson:gson:2.8.9"
29+
)
30+
31+
assertEquals(manifestMapping.head._2.resolved.keys, expected)
32+
}

plugin/src/io/kipp/mill/github/dependency/graph/ModuleTrees.scala

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,22 @@ final case class ModuleTrees(
3333
def toNode(tree: DependencyTree, root: Boolean): Unit = {
3434
val dep = tree.dependency
3535
val moduleOrgName = dep.module.orgName
36-
val name = s"${moduleOrgName}:${dep.version}"
36+
val reconciledVersion = tree.reconciledVersion
37+
val name = s"${moduleOrgName}:${reconciledVersion}"
3738

3839
def putTogether: DependencyNode = {
3940
// TODO consider classifiers
4041
val packageUrl =
41-
s"pkg:maven/${dep.module.organization.value}/${dep.module.name.value}@${dep.version}"
42+
s"pkg:maven/${dep.module.organization.value}/${dep.module.name.value}@${reconciledVersion}"
4243
val relationShip: DependencyRelationship =
4344
if (root) DependencyRelationship.direct
4445
else DependencyRelationship.indirect
4546
val dependencies = tree.children.map { child =>
46-
s"${child.dependency.module.orgName}:${child.dependency.version}"
47+
s"${child.dependency.module.orgName}:${child.reconciledVersion}"
4748
}
4849
DependencyNode(
4950
Some(packageUrl),
51+
// TODO we can check if original == reconciled here and add metadata that it is a reconciled version
5052
Map.empty,
5153
Some(relationShip),
5254
None,
@@ -57,37 +59,21 @@ final case class ModuleTrees(
5759
def verifyRelationship(node: DependencyNode) =
5860
(root && node.isDirectDependency) || (!root && !node.isDirectDependency)
5961

60-
val getsEvicted = dep.version != tree.retainedVersion
61-
// So the idea here is that if the retained version doesn't match the dep
62-
// version, we know that the dep ends up getting evicted, so we don't
63-
// actually need it as an entry since it won't end up on the classpath.
64-
// However if it's a root node, we need to ensure we later go back and
65-
// mark it as direct. We don't do it while iterating because we may have
66-
// already seen the dep that evicted it. See the evicted test for an
67-
// example.
68-
if (getsEvicted && root) {
69-
reconciledDirects += s"${moduleOrgName}:${tree.retainedVersion}"
70-
} else if (getsEvicted) {
71-
// If we know it's evicted here, but we're not at the root level, then
72-
// it doesn't matter because it's still not a direct dep.
73-
()
74-
} else {
75-
allDependencies.get(name) match {
76-
// If the node is found and the relationship is correct just do nothing
77-
case Some(node) if verifyRelationship(node) => ()
78-
// If the node is found and the relationship is incorrect, but it's a
79-
// root node, then make sure to mark it as direct
80-
case Some(node) if root =>
81-
val updated =
82-
node.copy(relationship = Some(DependencyRelationship.direct))
83-
allDependencies += ((name, updated))
84-
// Should never really happen, but it it does do nothing
85-
case Some(_) => ()
86-
// Unseen dependency, create a node for it
87-
case None =>
88-
val node = putTogether
89-
allDependencies += ((name, node))
90-
}
62+
allDependencies.get(name) match {
63+
// If the node is found and the relationship is correct just do nothing
64+
case Some(node) if verifyRelationship(node) => ()
65+
// If the node is found and the relationship is incorrect, but it's a
66+
// root node, then make sure to mark it as direct
67+
case Some(node) if root =>
68+
val updated =
69+
node.copy(relationship = Some(DependencyRelationship.direct))
70+
allDependencies += ((name, updated))
71+
// Should never really happen, but it it does do nothing
72+
case Some(_) => ()
73+
// Unseen dependency, create a node for it
74+
case None =>
75+
val node = putTogether
76+
allDependencies += ((name, node))
9177
}
9278

9379
tree.children.foreach(toNode(_, root = false))

0 commit comments

Comments
 (0)