Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Mill plugin classpath exclusions #3221

Merged
merged 7 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ object Deps {
ivy"com.google.protobuf:protobuf-java:3.25.3",
ivy"com.google.guava:guava:33.2.1-jre",
ivy"org.yaml:snakeyaml:2.2",
ivy"org.apache.commons:commons-compress:[1.26.0,)"
ivy"org.apache.commons:commons-compress:1.26.0"
)

/** Used in tests. */
Expand Down Expand Up @@ -588,8 +588,25 @@ object main extends MillStableScalaModule with BuildInfo {
BuildInfo.Value("millBinPlatform", millBinPlatform(), "Mill binary platform version."),
BuildInfo.Value(
"millEmbeddedDeps",
T.traverse(dev.moduleDeps)(_.publishSelfDependency)()
.map(artifact => s"${artifact.group}:${artifact.id}:${artifact.version}")
(
T.traverse(
dev.recursiveModuleDeps.collect { case m: PublishModule => m }
)(
_.publishSelfDependency
)()
.map(artifact => s"${artifact.group}:${artifact.id}:${artifact.version}") ++
Lib.resolveDependenciesMetadata(
repositories = dev.repositoriesTask(),
dev.transitiveIvyDeps(),
Some(dev.mapDependencies()),
dev.resolutionCustomizer(),
Some(T.ctx()),
dev.coursierCacheCustomizer()
)._2.minDependencies.toSeq
.map(d => s"${d.module.organization.value}:${d.module.name.value}:${d.version}")
)
// T.traverse(dev.moduleDeps)(_.publishSelfDependency)()
// .map(artifact => s"${artifact.group}:${artifact.id}:${artifact.version}")
.mkString(","),
"Dependency artifacts embedded in mill assembly by default."
),
Expand Down Expand Up @@ -1009,7 +1026,6 @@ object contrib extends Module {
def ivyDeps = Agg(Deps.requests)
}


object sonatypecentral extends ContribModule {
def compileModuleDeps = Seq(scalalib)
def ivyDeps = Agg(Deps.sonatypeCentralClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
<properties>
<language-level>Scala_2_13</language-level>
<compiler-classpath>
<root url="file://$USER_HOME$/COURSIER_CACHE/v1/https/repo1.maven.org/maven2/io/github/java-diff-utils/java-diff-utils/4.12/java-diff-utils-4.12.jar"/>
<root url="file://$USER_HOME$/COURSIER_CACHE/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.14.0/jna-5.14.0.jar"/>
<root url="file://$USER_HOME$/COURSIER_CACHE/v1/https/repo1.maven.org/maven2/org/jline/jline/3.25.1/jline-3.25.1.jar"/>
<root url="file://$USER_HOME$/COURSIER_CACHE/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.14/scala-compiler-2.13.14.jar"/>
<root url="file://$USER_HOME$/COURSIER_CACHE/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar"/>
<root url="file://$USER_HOME$/COURSIER_CACHE/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.14/scala-reflect-2.13.14.jar"/>
Expand Down
7 changes: 4 additions & 3 deletions integration/feature/gen-idea/test/src/GenIdeaUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ object GenIdeaUtils {

assertPartialContentMatches(
found = actualResourceString,
expected = expectedResourceString
expected = expectedResourceString,
resource.toString()
)
}
println(
Expand All @@ -33,9 +34,9 @@ object GenIdeaUtils {
check.get
}

def assertPartialContentMatches(found: String, expected: String): Unit = {
def assertPartialContentMatches(found: String, expected: String, context: String = ""): Unit = {
if (!expected.contains(ignoreString)) {
assert(found == expected)
assert(context != null && found == expected)
}

val pattern =
Expand Down
10 changes: 10 additions & 0 deletions integration/feature/plugin-classpath/repo/build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This plugin brings a incompatible transitive version of Mill
// See https://github.com/com-lihaoyi/mill/issues/3207
import $ivy.`com.disneystreaming.smithy4s::smithy4s-mill-codegen-plugin::0.18.22`

import mill._
import mill.scalalib._

object root extends RootModule with ScalaModule {
def scalaVersion = "3.4.2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package mill.integration

import utest._

object MillPluginClasspathTest extends IntegrationTestSuite {
initWorkspace()

val embeddedModules: Seq[(String, String)] = Seq(
("com.lihaoyi", "mill-main-client"),
("com.lihaoyi", "mill-main-api_2.13"),
("com.lihaoyi", "mill-main-util_2.13"),
("com.lihaoyi", "mill-main-codesig_2.13"),
("com.lihaoyi", "mill-runner-linenumbers_2.13"),
("com.lihaoyi", "mill-bsp_2.13"),
("com.lihaoyi", "mill-scalanativelib-worker-api_2.13"),
("com.lihaoyi", "mill-testrunner-entrypoint"),
("com.lihaoyi", "mill-scalalib-api_2.13"),
("com.lihaoyi", "mill-testrunner_2.13"),
("com.lihaoyi", "mill-main-define_2.13"),
("com.lihaoyi", "mill-main-resolve_2.13"),
("com.lihaoyi", "mill-main-eval_2.13"),
("com.lihaoyi", "mill-main_2.13"),
("com.lihaoyi", "mill-scalalib_2.13"),
("com.lihaoyi", "mill-scalanativelib_2.13"),
("com.lihaoyi", "mill-scalajslib-worker-api_2.13"),
("com.lihaoyi", "mill-scalajslib_2.13"),
("com.lihaoyi", "mill-runner_2.13"),
("com.lihaoyi", "mill-idea_2.13")
)

val tests: Tests = Tests {
test("exclusions") - {
val res1 = eval("--meta-level", "1", "resolveDepsExclusions")
assert(res1)

val exclusions = metaValue[Seq[(String, String)]]("mill-build.resolveDepsExclusions")
val expectedExclusions = embeddedModules

val diff = expectedExclusions.toSet.diff(exclusions.toSet)
assert(diff.isEmpty)

}
test("runClasspath") - {
// We expect Mill core transitive dependencies to be filtered out
val res1 = eval("--meta-level", "1", "runClasspath")
assert(res1)

val runClasspath = metaValue[Seq[String]]("mill-build.runClasspath")

val unexpectedArtifacts = embeddedModules.map {
case (o, n) => s"${o.replaceAll("[.]", "/")}/${n}"
}

val unexpected = unexpectedArtifacts.flatMap { a =>
runClasspath.find(p => p.toString.contains(a)).map((a, _))
}.toMap
assert(unexpected.isEmpty)

val expected = Seq("com/disneystreaming/smithy4s/smithy4s-mill-codegen-plugin_mill0.11_2.13")
assert(expected.forall(a => runClasspath.exists(p => p.toString().contains(a))))
}

}
}
11 changes: 11 additions & 0 deletions integration/src/mill/integration/IntegrationTestSuite.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mill.integration

import mill.eval.Evaluator
import mill.resolve.SelectMode
import mill.runner.RunnerState
import os.{Path, Shellable}
Expand Down Expand Up @@ -91,6 +92,16 @@ abstract class IntegrationTestSuite extends TestSuite {
os.read(wd / "out" / segments.init / s"${segments.last}.json")
}

def metaCached(selector: String): Evaluator.Cached = {
val data = meta(selector)
upickle.default.read[Evaluator.Cached](data)
}

def metaValue[T: upickle.default.Reader](selector: String): T = {
val cached = metaCached(selector)
upickle.default.read[T](cached.value)
}

def initWorkspace(): Path = {
os.remove.all(workspacePath)
os.makeDir.all(workspacePath / os.up)
Expand Down