Skip to content

Commit

Permalink
Support mill 0.12 series (#409)
Browse files Browse the repository at this point in the history
* Support Mill 0.12

* Set version to 0.3.17

* Fix scalafix adapters
  • Loading branch information
WojciechMazur authored Sep 16, 2024
1 parent fad6948 commit 48cd3a9
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cli/scb-cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FailedProjectException(msg: String)
with NoStackTrace

val communityBuildVersion =
sys.props.getOrElse("communitybuild.version", "v0.3.16")
sys.props.getOrElse("communitybuild.version", "v0.3.17")
private val CBRepoName = "VirtusLab/community-build3"
val projectBuilderUrl =
s"https://raw.githubusercontent.com/$CBRepoName/master/project-builder"
Expand Down
10 changes: 5 additions & 5 deletions project-builder/mill/MillCommunityBuild.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package build
import $ivy.`com.lihaoyi::upickle:3.0.0`
import $file.MillVersionCompat, MillVersionCompat.compat.{
import MillVersionCompat.compat.{
CoursierModule,
JavaModule,
PublishModule,
Expand All @@ -11,7 +12,7 @@ import $file.MillVersionCompat, MillVersionCompat.compat.{
Val,
toZincWorker
}
import $file.CommunityBuildCore, CommunityBuildCore.Scala3CommunityBuild.{
import CommunityBuildCore.Scala3CommunityBuild.{
TestingMode => _,
ProjectBuildConfig => _,
ProjectOverrides => _,
Expand Down Expand Up @@ -188,8 +189,8 @@ class MillTaskEvaluator()(implicit ctx: Ctx) extends TaskEvaluator[NamedTask] {

// Main entry point for Mill community build
// Evaluate tasks until first failure and publish report
def runBuild(configJson: String, targets: Seq[String])(implicit ctx: Ctx) = {

def runBuild(configJson: String, projectDir: String, targets: Seq[String])(implicit ctx: Ctx) = {
val outputDir: os.Path = os.Path.expandUser(projectDir) / os.up
println(s"Build config: ${configJson}")
val config = read[ProjectBuildConfig](configJson)
println(s"Parsed config: ${config}")
Expand Down Expand Up @@ -305,7 +306,6 @@ def runBuild(configJson: String, targets: Seq[String])(implicit ctx: Ctx) = {
|************************"
|""".stripMargin)

val outputDir = os.pwd / os.up
os.write.over(outputDir / "build-summary.txt", buildSummary.toJson)

val failedModules = projectsBuildResults
Expand Down
3 changes: 2 additions & 1 deletion project-builder/mill/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ echo Project projectConfig: $projectConfig
echo '##################################'

scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
projectDir=$PWD/$repoDir

cd $repoDir

Expand All @@ -42,7 +43,7 @@ millSettings=(
function tryBuild() {
mill=$1
echo "Try build using $mill"
$mill "${millSettings[@]}" runCommunityBuild "$scalaVersion" "${projectConfig}" "${targets[@]}"
$mill "${millSettings[@]}" runCommunityBuild --scalaVersion="$scalaVersion" --configJson="${projectConfig}" --projectDir=$projectDir "${targets[@]}"
}


Expand Down
16 changes: 16 additions & 0 deletions project-builder/mill/compat/0.12.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package build
// Same as 0.11
object compat {
type CoursierModule = mill.scalalib.CoursierModule
type JavaModule = mill.scalalib.JavaModule
type PublishModule = mill.scalalib.PublishModule
type ScalaModule = mill.scalalib.ScalaModule
type TestModule = mill.scalalib.TestModule
type ZincWorkerModule = mill.scalalib.ZincWorkerModule
type TestResult = mill.testrunner.TestResult
type Val = mill.api.Val
val Val = mill.api.Val
type Task[+T] = mill.Task[T]

def toZincWorker(v: ZincWorkerModule) = mill.define.ModuleRef(v)
}
50 changes: 34 additions & 16 deletions project-builder/mill/prepare-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export OPENCB_PROJECT_DIR=$repoDir

scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

MILL_0_11=0.11.6
MILL_0_12="0.12.0-RC2"
MILL_0_11=0.11.12
MILL_0_10=0.10.15
MILL_0_9=0.9.12
RESOLVE="resolve _"
Expand All @@ -39,7 +40,7 @@ else
fi
if [[ "$millVersion" == "" ]]; then
echo "Trying one of predefiend mill versions"
for v in $MILL_0_11 $MILL_0_10 $MILL_0_9; do
for v in $MILL_0_12 $MILL_0_11 $MILL_0_10 $MILL_0_9; do
if `${scriptDir}/millw --mill-version $v $RESOLVE > /dev/null 2>/dev/null`; then
echo "Successfully applied build using mill $v"
millVersion=$v
Expand All @@ -63,8 +64,8 @@ echo "Detected mill version=$millVersion, binary version: $millBinaryVersion"
millBinaryVersionMajor=`echo $millVersion | cut -d . -f 1`
millBinaryVersionMinor=`echo $millVersion | cut -d . -f 2`
# 0.9 is the minimal verified supported version
# 0.12 does not exit yet
if [[ "$millBinaryVersionMajor" -ne "0" || ( "$millBinaryVersionMinor" -lt "9" || "$millBinaryVersionMinor" -gt "11" ) ]]; then
# 0.13 does not exit yet
if [[ "$millBinaryVersionMajor" -ne "0" || ( "$millBinaryVersionMinor" -lt "9" || "$millBinaryVersionMinor" -gt "12" ) ]]; then
echo "Unsupported mill version"
exit 1
fi
Expand Down Expand Up @@ -98,30 +99,47 @@ fi

# Rename build.sc to build.scala - Scalafix does ignore .sc files
# Use scala 3 dialect to allow for top level defs
adaptedFiles=($PWD/build.sc )
millBuildExt="mill"
if [[ "$millBinaryVersionMajor" -eq "0" && "$millBinaryVersionMinor" -le "11" ]]; then
millBuildExt=sc
fi
adaptedFiles=( $PWD/build.${millBuildExt} )
if [[ -d ./project ]]; then
adaptedFiles+=(`find ./project -type f -name "*.sc"`)
adaptedFiles+=(`find ./project -type f -name "*.$millBuildExt"`)
fi
for scFile in "${adaptedFiles[@]}"; do
echo "Apply scalafix rules to $scFile"
scalaFile="${scFile%.sc}.scala"
cp $scFile $scalaFile
for buildFile in "${adaptedFiles[@]}"; do
echo "Apply scalafix rules to $buildFile"
scalaFile="${buildFile%.$millBuildExt}.scala"
cp $buildFile $scalaFile
scalafix \
--rules file:${scriptDir}/scalafix/rules/src/main/scala/fix/Scala3CommunityBuildMillAdapter.scala \
--files $scalaFile \
--stdout \
--syntactic \
--settings.Scala3CommunityBuildMillAdapter.targetScalaVersion "$scalaVersion" \
--settings.Scala3CommunityBuildMillAdapter.millBinaryVersion "$millBinaryVersion" \
--scala-version 3.1.0 > ${scFile}.adapted \
&& mv ${scFile}.adapted $scFile \
|| (echo "Failed to adapted $scFile, ignoring changes"; cat ${scFile}.adapted; rm -f ${scFile}.adapted)
--scala-version 3.1.0 > ${buildFile}.adapted \
&& mv ${buildFile}.adapted $buildFile \
|| (echo "Failed to adapt $buildFile, ignoring changes"; cat ${buildFile}.adapted; rm -f ${buildFile}.adapted)
rm $scalaFile
done

for f in "${adaptedFiles[@]}"; do
dir="$(dirname $(realpath "$f"))"
ln -fs $scriptDir/../shared/CommunityBuildCore.scala ${dir}/CommunityBuildCore.sc
ln -fs $scriptDir/MillCommunityBuild.sc ${dir}/MillCommunityBuild.sc
ln -fs $scriptDir/compat/$millBinaryVersion.sc ${dir}/MillVersionCompat.sc
cp $scriptDir/MillCommunityBuild.sc ${dir}/MillCommunityBuild.$millBuildExt
cp $scriptDir/compat/$millBinaryVersion.sc ${dir}/MillVersionCompat.$millBuildExt

if [[ "$millBinaryVersionMajor" -gt "0" || "$millBinaryVersionMinor" -ge "12" ]]; then
# Compat for Mill 0.12+ sources
echo "package build" | cat - $scriptDir/../shared/CommunityBuildCore.scala > ${dir}/CommunityBuildCore.$millBuildExt
else
# Compat for Mill 0.11+ sources
cp $scriptDir/../shared/CommunityBuildCore.scala ${dir}/CommunityBuildCore.$millBuildExt
for fileCopy in ${dir}/CommunityBuildCore.$millBuildExt ${dir}/MillCommunityBuild.$millBuildExt ${dir}/MillVersionCompat.$millBuildExt; do
scala-cli $scriptDir/../shared/searchAndReplace.scala -- $fileCopy "package build\n" ""
scala-cli $scriptDir/../shared/searchAndReplace.scala -- $fileCopy "import CommunityBuildCore." "import \$file.CommunityBuildCore, CommunityBuildCore."
scala-cli $scriptDir/../shared/searchAndReplace.scala -- $fileCopy "import MillVersionCompat." "import \$file.MillVersionCompat, MillVersionCompat."
done
fi

done
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Scala3CommunityBuildMillAdapter(
"Scala_3",
"scala_3",
"scala",
"Scala"
// "Scala" - explicitly ignored
)

val Scala3Literal = raw""""3.\d+.\d+(?:-RC\d+)?"""".r
Expand Down
13 changes: 6 additions & 7 deletions project-builder/sbt/CommunityBuildPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.collection.JavaConverters._
import scala.collection.mutable

import Scala3CommunityBuild._
import Scala3CommunityBuild.Utils._
import Scala3CommunityBuild.Utils.{LibraryDependency, logOnce}
import TaskEvaluator.EvalResult

class SbtTaskEvaluator(val project: ProjectRef, private var state: State)
Expand Down Expand Up @@ -94,13 +94,12 @@ object CommunityBuildPlugin extends AutoPlugin {
private def extraLibraryDependencies(
buildScalaVersion: Option[String],
projectScalaVersion: String
) =
): Seq[ModuleID] =
if (!projectScalaVersion.startsWith("3.")) Nil
else
Scala3CommunityBuild.Utils
.extraLibraryDependencies(buildScalaVersion.getOrElse(projectScalaVersion))
Utils.extraLibraryDependencies(buildScalaVersion.getOrElse(projectScalaVersion))
.map {
case Scala3CommunityBuild.Utils.LibraryDependency(
case LibraryDependency(
org,
artifact,
version,
Expand Down Expand Up @@ -194,7 +193,7 @@ object CommunityBuildPlugin extends AutoPlugin {
if (scalaVersion.startsWith("3.")) remove
else remove ++ appendScala3Exclusive

Scala3CommunityBuild.Utils.mapScalacOptions(
Utils.mapScalacOptions(
current = currentScalacOptions,
append = filteredAppend,
remove = filteredRemove
Expand Down Expand Up @@ -420,7 +419,7 @@ object CommunityBuildPlugin extends AutoPlugin {
case "*%*" :: _ => originalModuleIds.keys.toSeq
case ids => ids
}
val filteredIds = filterTargets(idsToUse, config.projects.exclude.map(_.r))
val filteredIds = Utils.filterTargets(idsToUse, config.projects.exclude.map(_.r))

println("Starting build...")
// Find projects that matches maven
Expand Down
2 changes: 1 addition & 1 deletion scripts/bisect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.nio.file.attribute.PosixFilePermissions
import java.nio.charset.StandardCharsets
import java.nio.file._

val communityBuildVersion = "v0.3.16"
val communityBuildVersion = "v0.3.17"

@main def run(args: String*): Unit =
val config = scopt.OParser
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ $# -ne 1 ]; then
fi

VERSION="$1"
export PREV_CB_VERSION="v0.3.15"
export PREV_CB_VERSION="v0.3.16"

javaDefault=11
javaAccessoryVersions=(8 17 21)
Expand Down

0 comments on commit 48cd3a9

Please sign in to comment.