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

feat: introduce crossbuilding #88

Merged
merged 1 commit into from
Apr 28, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:

- name: Test
run:
./mill -i --debug itest
./mill -i --debug itest[_].test
28 changes: 22 additions & 6 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ import de.tobiasroeser.mill.vcs.version.VcsVersion
import io.kipp.mill.ci.release.CiReleaseModule
import io.kipp.mill.ci.release.SonatypeHost

val millVersion = "0.10.12"
val millVersions = Seq("0.10.12", "0.11.0-M8")
val millBinaryVersions = millVersions.map(scalaNativeBinaryVersion)
val scala213 = "2.13.8"
val artifactBase = "mill-github-dependency-graph"

def millBinaryVersion(millVersion: String) = scalaNativeBinaryVersion(
millVersion
)

def millVersion(binaryVersion: String) =
millVersions.find(v => millBinaryVersion(v) == binaryVersion).get

trait Common
extends ScalaModule
with CiReleaseModule
Expand Down Expand Up @@ -57,14 +61,23 @@ object domain extends Common {
override def artifactName = "github-dependency-graph-domain"
}

object plugin extends Common with BuildInfo {
object plugin extends Cross[Plugin](millBinaryVersions: _*)
class Plugin(millBinaryVersion: String) extends Common with BuildInfo {

override def millSourcePath = super.millSourcePath / os.up

override def sources = T.sources {
super.sources() ++ Seq(
millSourcePath / s"src-mill${millVersion(millBinaryVersion).split('.').take(2).mkString(".")}"
).map(PathRef(_))
}

override def artifactName =
s"${artifactBase}_mill${millBinaryVersion(millVersion)}"
s"${artifactBase}_mill${millBinaryVersion}"

override def moduleDeps = Seq(domain)
override def compileIvyDeps = super.compileIvyDeps() ++ Agg(
ivy"com.lihaoyi::mill-scalalib:$millVersion"
ivy"com.lihaoyi::mill-scalalib:${millVersion(millBinaryVersion)}"
)

override def ivyDeps = super.ivyDeps() ++ Agg(
Expand All @@ -84,11 +97,14 @@ object plugin extends Common with BuildInfo {
)
}

object itest extends MillIntegrationTestModule {
object itest extends Cross[ItestCross](millVersions: _*)
class ItestCross(millVersion: String) extends MillIntegrationTestModule {

override def millSourcePath = super.millSourcePath / os.up

def millTestVersion = millVersion

def pluginsUnderTest = Seq(plugin)
def pluginsUnderTest = Seq(plugin(millBinaryVersion(millVersion)))

def testBase = millSourcePath / "src"

Expand Down
2 changes: 1 addition & 1 deletion itest/src/cyclical/build.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mill._, scalalib._
import $exec.plugins
import $file.plugins
import io.kipp.mill.github.dependency.graph.Graph
import io.kipp.mill.github.dependency.graph.Writers._
import mill.eval.Evaluator
Expand Down
2 changes: 1 addition & 1 deletion itest/src/directRelationship/build.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mill._, scalalib._
import $exec.plugins
import $file.plugins
import io.kipp.mill.github.dependency.graph.Graph
import mill.eval.Evaluator
import $ivy.`org.scalameta::munit:0.7.29`
Expand Down
2 changes: 1 addition & 1 deletion itest/src/eviction/build.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mill._, scalalib._
import $exec.plugins
import $file.plugins
import io.kipp.mill.github.dependency.graph.Graph
import mill.eval.Evaluator
import $ivy.`org.scalameta::munit:0.7.29`
Expand Down
2 changes: 1 addition & 1 deletion itest/src/minimal/build.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mill._, scalalib._
import $exec.plugins
import $file.plugins
import io.kipp.mill.github.dependency.graph.Graph
import io.kipp.mill.github.dependency.graph.Writers._
import mill.eval.Evaluator
Expand Down
2 changes: 1 addition & 1 deletion itest/src/range/build.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mill._, scalalib._
import $exec.plugins
import $file.plugins
import io.kipp.mill.github.dependency.graph.Graph
import mill.eval.Evaluator
import $ivy.`org.scalameta::munit:0.7.29`
Expand Down
2 changes: 1 addition & 1 deletion itest/src/reconciledRange/build.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mill._, scalalib._
import $exec.plugins
import $file.plugins
import io.kipp.mill.github.dependency.graph.Graph
import mill.eval.Evaluator
import $ivy.`org.scalameta::munit:0.7.29`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.kipp.mill.github.dependency.graph

import mill.main.EvaluatorScopt

private[graph] object Reader {
implicit def millScoptEvaluatorReads[A]: EvaluatorScopt[A] =
new EvaluatorScopt[A]()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.kipp.mill.github.dependency.graph

private[graph] object Reader {
implicit def millEvaluatorTokenReader =
mill.main.TokenReaders.millEvaluatorTokenReader
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.kipp.mill.github.dependency.graph

import coursier.graph.DependencyTree
import mill._
import mill.eval.Evaluator
import mill.scalalib.JavaModule
import mill.scalalib.Lib

/** Utils to help find all your modules and resolve their dependencies.
*/
object Resolver {

/** Given an evaluator and your javaModules, use coursier to resolve all of
* their dependencies into trees.
*
* @param evaluator Evaluator passed in from the command
* @param javaModules All the JavaModules to resolve dependencies from
* @return A collection of ModuleTrees
*/
private[graph] def resolveModuleTrees(
evaluator: Evaluator,
javaModules: Seq[JavaModule]
): Seq[ModuleTrees] = Evaluator.evalOrThrow(evaluator) {
javaModules.map { javaModule =>
T.task {

val deps =
javaModule.transitiveCompileIvyDeps() ++ javaModule
.transitiveIvyDeps()
val repos = javaModule.repositoriesTask()
val mapDeps = javaModule.mapDependencies()
val custom = javaModule.resolutionCustomizer()

val (dependencies, resolution) =
Lib.resolveDependenciesMetadata(
repositories = repos,
deps = deps,
mapDependencies = Some(mapDeps),
customizer = custom,
ctx = Some(T.log)
)

val trees =
DependencyTree(resolution = resolution, roots = dependencies)

ModuleTrees(
javaModule,
trees
)
}
}
}

private[graph] def computeModules(ev: Evaluator) =
ev.rootModule.millInternal.modules.collect { case j: JavaModule => j }
}
6 changes: 1 addition & 5 deletions plugin/src/io/kipp/mill/github/dependency/graph/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import mill.define.Command
import mill.define.Discover
import mill.define.ExternalModule
import mill.eval.Evaluator
import mill.main.EvaluatorScopt

object Graph extends ExternalModule {

Expand All @@ -28,9 +27,6 @@ object Graph extends ExternalModule {
manifests
}

implicit def millScoptEvaluatorReads[T]: EvaluatorScopt[T] =
new mill.main.EvaluatorScopt[T]()

import Reader._
lazy val millDiscover: Discover[this.type] = mill.define.Discover[this.type]

}