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

[POC] Use Unroll plugin for binary compatibility #3008

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,13 @@ trait MillScalaModule extends ScalaModule with MillJavaModule with ScalafixModul
def scalacPluginIvyDeps =
super.scalacPluginIvyDeps() ++
Agg(Deps.acyclic) ++
Agg(ivy"com.lihaoyi::unroll-plugin:0.1.12") ++
Agg.when(scalaVersion().startsWith("2.13."))(Deps.millModuledefsPlugin)

def mandatoryIvyDeps =
super.mandatoryIvyDeps() ++
Agg.when(scalaVersion().startsWith("2.13."))(Deps.millModuledefs)
Seq(ivy"com.lihaoyi::unroll-annotation:0.1.12") ++
Agg.when(scalaVersion().startsWith("2.13."))(Deps.millModuledefs)

/** Default tests module. */
lazy val test: MillScalaTests = new MillScalaTests {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
package mill.contrib.scoverage.api

import mill.api.Ctx
import scala.annotation.unroll

trait ScoverageReportWorkerApi {
import ScoverageReportWorkerApi._

@deprecated("Use other overload instead.", "Mill after 0.10.7")
def report(
reportType: ReportType,
sources: Seq[os.Path],
dataDirs: Seq[os.Path]
)(implicit
ctx: Ctx
): Unit = {
report(reportType, sources, dataDirs, ctx.workspace)
}

def report(
reportType: ReportType,
sources: Seq[os.Path],
dataDirs: Seq[os.Path],
sourceRoot: os.Path
@unroll sourceRoot: os.Path = null
)(implicit
ctx: Ctx
): Unit = {
// FIXME: We only call the deprecated version here, to preserve binary compatibility. Remove when appropriate.
ctx.log.error(
"Binary compatibility stub may cause infinite loops with StackOverflowError. You need to implement: def report(ReportType, Seq[Path], Seq[Path], os.Path): Unit"
)
report(reportType, sources, dataDirs)
}
): Unit
}

object ScoverageReportWorkerApi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import mill.contrib.scoverage.api.ScoverageReportWorkerApi
import _root_.scoverage.reporter.{CoverageAggregator, ScoverageHtmlWriter, ScoverageXmlWriter}
import mill.api.Ctx
import mill.contrib.scoverage.api.ScoverageReportWorkerApi.ReportType
import scala.annotation.unroll

/**
* Scoverage Worker for Scoverage 2.x
Expand All @@ -14,8 +15,9 @@ class ScoverageReportWorkerImpl extends ScoverageReportWorkerApi {
reportType: ReportType,
sources: Seq[os.Path],
dataDirs: Seq[os.Path],
sourceRoot: os.Path
)(implicit ctx: Ctx): Unit =
sourceRoot0: os.Path = null
)(implicit ctx: Ctx): Unit = {
val sourceRoot = Option(sourceRoot0).getOrElse(ctx.workspace)
try {
ctx.log.info(s"Processing coverage data for ${dataDirs.size} data locations")
CoverageAggregator.aggregate(dataDirs.map(_.toIO), sourceRoot.toIO) match {
Expand Down Expand Up @@ -43,4 +45,5 @@ class ScoverageReportWorkerImpl extends ScoverageReportWorkerApi {
e.printStackTrace()
throw e
}
}
}
67 changes: 67 additions & 0 deletions example/basic/1-simple-scala/mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env sh

# This is a wrapper script, that automatically download mill from GitHub release pages
# You can give the required mill version with MILL_VERSION env variable
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION

set -e

if [ -z "${DEFAULT_MILL_VERSION}" ] ; then
DEFAULT_MILL_VERSION=0.11.7
fi

if [ -z "$MILL_VERSION" ] ; then
if [ -f ".mill-version" ] ; then
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
elif [ -f ".config/mill-version" ] ; then
MILL_VERSION="$(head -n 1 .config/mill-version 2> /dev/null)"
elif [ -f "mill" ] && [ "$0" != "mill" ] ; then
MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2)
else
MILL_VERSION=$DEFAULT_MILL_VERSION
fi
fi

if [ "x${XDG_CACHE_HOME}" != "x" ] ; then
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download"
else
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download"
fi
MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}"

version_remainder="$MILL_VERSION"
MILL_MAJOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"
MILL_MINOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"

if [ ! -s "$MILL_EXEC_PATH" ] ; then
mkdir -p "$MILL_DOWNLOAD_PATH"
if [ "$MILL_MAJOR_VERSION" -gt 0 ] || [ "$MILL_MINOR_VERSION" -ge 5 ] ; then
ASSEMBLY="-assembly"
fi
DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
MILL_VERSION_TAG=$(echo $MILL_VERSION | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
MILL_DOWNLOAD_URL="https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/$MILL_VERSION/mill-dist-$MILL_VERSION.jar"
curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
chmod +x "$DOWNLOAD_FILE"
mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
unset DOWNLOAD_FILE
unset MILL_DOWNLOAD_URL
fi

if [ -z "$MILL_MAIN_CLI" ] ; then
MILL_MAIN_CLI="${0}"
fi

MILL_FIRST_ARG=""

# first arg is a long flag for "--interactive" or starts with "-i"
if [ "$1" = "--bsp" ] || [ "${1%"-i"*}" != "$1" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then
# Need to preserve the first position of those listed options
MILL_FIRST_ARG=$1
shift
fi

unset MILL_DOWNLOAD_PATH
unset MILL_VERSION

exec $MILL_EXEC_PATH $MILL_FIRST_ARG -D "mill.main.cli=${MILL_MAIN_CLI}" "$@"
79 changes: 5 additions & 74 deletions scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import mill.api.{CompileProblemReporter, PathRef}
import mill.api.Loose.Agg

import scala.annotation.nowarn
import scala.annotation.unroll

object ZincWorkerApi {
type Ctx = mill.api.Ctx.Dest with mill.api.Ctx.Log with mill.api.Ctx.Home
Expand All @@ -18,36 +19,9 @@ trait ZincWorkerApi {
javacOptions: Seq[String],
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean,
incrementalCompilation: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] =
compileJava(
upstreamCompileOutput = upstreamCompileOutput,
sources = sources,
compileClasspath = compileClasspath,
javacOptions = javacOptions,
reporter = reporter,
reportCachedProblems = reportCachedProblems
): @nowarn("cat=deprecation")
@unroll incrementalCompilation: Boolean = true
)(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] = ???

/** Compile a Java-only project */
@deprecated("Use override with `incrementalCompilation` parameter", "Mill 0.11.6")
def compileJava(
upstreamCompileOutput: Seq[CompilationResult],
sources: Agg[os.Path],
compileClasspath: Agg[os.Path],
javacOptions: Seq[String],
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] =
compileJava(
upstreamCompileOutput = upstreamCompileOutput,
sources = sources,
compileClasspath = compileClasspath,
javacOptions = javacOptions,
reporter = reporter,
reportCachedProblems = reportCachedProblems,
incrementalCompilation = true
)

/** Compile a mixed Scala/Java or Scala-only project */
def compileMixed(
Expand All @@ -62,51 +36,8 @@ trait ZincWorkerApi {
scalacPluginClasspath: Agg[PathRef],
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean,
incrementalCompilation: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] =
compileMixed(
upstreamCompileOutput = upstreamCompileOutput,
sources = sources,
compileClasspath = compileClasspath,
javacOptions = javacOptions,
scalaVersion = scalaVersion,
scalaOrganization = scalaOrganization,
scalacOptions = scalacOptions,
compilerClasspath = compilerClasspath,
scalacPluginClasspath = scalacPluginClasspath,
reporter = reporter,
reportCachedProblems = reportCachedProblems
): @nowarn("cat=deprecation")

/** Compile a mixed Scala/Java or Scala-only project */
@deprecated("Use override with `incrementalCompilation` parameter", "Mill 0.11.6")
def compileMixed(
upstreamCompileOutput: Seq[CompilationResult],
sources: Agg[os.Path],
compileClasspath: Agg[os.Path],
javacOptions: Seq[String],
scalaVersion: String,
scalaOrganization: String,
scalacOptions: Seq[String],
compilerClasspath: Agg[PathRef],
scalacPluginClasspath: Agg[PathRef],
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] =
compileMixed(
upstreamCompileOutput = upstreamCompileOutput,
sources = sources,
compileClasspath = compileClasspath,
javacOptions = javacOptions,
scalaVersion = scalaVersion,
scalaOrganization = scalaOrganization,
scalacOptions = scalacOptions,
compilerClasspath = compilerClasspath,
scalacPluginClasspath = scalacPluginClasspath,
reporter = reporter,
reportCachedProblems = reportCachedProblems,
incrementalCompilation = true
)
@unroll incrementalCompilation: Boolean = true
)(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] = ???

def discoverMainClasses(compilationResult: CompilationResult): Seq[String]

Expand Down
7 changes: 2 additions & 5 deletions scalalib/src/mill/scalalib/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import mill.define.{Command, Discover, ExternalModule}
import mill.eval.Evaluator
import mill.scalalib.dependency.{DependencyUpdatesImpl, Format}
import mill.scalalib.dependency.updates.ModuleDependenciesUpdates
import scala.annotation.unroll

object Dependency extends ExternalModule {

Expand All @@ -27,14 +28,10 @@ object Dependency extends ExternalModule {
def showUpdates(
ev: Evaluator,
allowPreRelease: Boolean = false,
format: Format = Format.PerModule
@unroll format: Format = Format.PerModule
): Command[Unit] = T.command {
DependencyUpdatesImpl.showAllUpdates(updates(ev, allowPreRelease)(), format)
}

@deprecated("Use other overload instead", "Mill after 0.11.6")
def showUpdates(ev: Evaluator, allowPreRelease: Boolean): Command[Unit] =
Dependency.showUpdates(ev, allowPreRelease, Format.PerModule)

lazy val millDiscover: Discover[Dependency.this.type] = Discover[this.type]
}
9 changes: 2 additions & 7 deletions scalalib/src/mill/scalalib/TestModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import mill.api.{Ctx, PathRef, Result}
import mill.util.Jvm
import mill.scalalib.bsp.{BspBuildTarget, BspModule}
import mill.testrunner.{Framework, TestArgs, TestResult, TestRunner}
import scala.annotation.unroll

trait TestModule extends TaskModule with TestModule.JavaModuleBase {

Expand Down Expand Up @@ -259,16 +260,10 @@ object TestModule {
override def testFramework: T[String] = "zio.test.sbt.ZTestFramework"
}

@deprecated("Use other overload instead", "Mill after 0.10.2")
def handleResults(
doneMsg: String,
results: Seq[TestResult]
): Result[(String, Seq[TestResult])] = handleResults(doneMsg, results, None)

def handleResults(
doneMsg: String,
results: Seq[TestResult],
ctx: Option[Ctx.Env]
@unroll ctx: Option[Ctx.Env] = None
): Result[(String, Seq[TestResult])] = {

val badTests: Seq[TestResult] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import mill.scalalib.dependency.updates.{
UpdatesFinder
}
import mill.scalalib.dependency.versions.{ModuleDependenciesVersions, VersionsFinder}
import scala.annotation.unroll

object DependencyUpdatesImpl {

Expand All @@ -33,13 +34,9 @@ object DependencyUpdatesImpl {
allUpdates
}

@deprecated("Use other overload instead", "Mill after 0.11.6")
def showAllUpdates(updates: Seq[ModuleDependenciesUpdates]): Unit =
showAllUpdates(updates, format = Format.PerModule)

def showAllUpdates(
updates: Seq[ModuleDependenciesUpdates],
format: Format = Format.PerModule
@unroll format: Format = Format.PerModule
): Unit = {
val theUpdates =
updates.map(u => if (u.modulePath.isEmpty) u.copy(modulePath = "root module") else u)
Expand Down