Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Mar 4, 2025
1 parent 6398ba3 commit 85f2113
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 29 deletions.
10 changes: 2 additions & 8 deletions core/exec/src/mill/exec/GroupExecution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ private trait GroupExecution {
val inputsHash =
externalInputsHash + sideHashes + classLoaderSigHash + scriptsHash + javaHomeHash


def transformResults(results: Map[Task[?], ExecResult[(Val, Option[ujson.Value])]]):
Map[Task[?], ExecResult[(Val, Int)]] = {
def transformResults(results: Map[Task[?], ExecResult[(Val, Option[ujson.Value])]])
: Map[Task[?], ExecResult[(Val, Int)]] = {
for ((k, v0) <- results)
yield k -> v0.map { case (v, jsonOpt) => (v, getValueHash(k, inputsHash, v, jsonOpt)) }
}
Expand All @@ -104,7 +103,6 @@ private trait GroupExecution {
valOpt.map((_, valueHash))
})


cachedValueAndHash match {
case Some((v, hashCode)) =>
val res = ExecResult.Success((v, hashCode))
Expand Down Expand Up @@ -141,7 +139,6 @@ private trait GroupExecution {
deps
)


val valueHash = newResults(labelled) match {
case ExecResult.Success((v, jsonOpt)) =>
val valueHash = getValueHash(labelled, inputsHash, v, jsonOpt)
Expand Down Expand Up @@ -276,8 +273,6 @@ private trait GroupExecution {
if (exclusive) (exclusiveSystemStreams, () => workspace)
else (multiLogger.systemStreams, () => makeDest())



os.ProcessOps.spawnHook.withValue(p => MillPathSerializer.setupSymlinks(p, workspace)) {
os.dynamicPwdFunction.withValue(destFunc) {
os.checker.withValue(executionChecker) {
Expand Down Expand Up @@ -443,7 +438,6 @@ private trait GroupExecution {
)
}


def getValueHash(t: Task[_], inputsHash: Int, v: Val, jsonOpt: Option[ujson.Value]): Int = {
if (t.isInstanceOf[Worker[_]]) inputsHash
else jsonOpt match {
Expand Down
26 changes: 16 additions & 10 deletions core/internal/src/mill/internal/MillPathSerializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mill.internal
import java.nio.file.Files

object MillPathSerializer {
def setupSymlinks(wd: os.Path, workspace: os.Path) ={
def setupSymlinks(wd: os.Path, workspace: os.Path) = {

os.remove(wd / "mill-home")
Files.createSymbolicLink((wd / "mill-home").toNIO, os.home.wrapped)
Expand All @@ -19,28 +19,33 @@ object MillPathSerializer {
)
}
class MillPathSerializer(mapping: Seq[(os.Path, os.SubPath)])
extends os.Path.Serializer {
extends os.Path.Serializer {

def mapPathPrefixes(path: os.Path, mapping: Seq[(os.Path, os.SubPath)]): os.FilePath = {
mapping
.collectFirst { case (from, to) if path.startsWith(from) => to / path.subRelativeTo(from) }
.getOrElse(path)
}

def mapPathPrefixes2(path: java.nio.file.Path, mapping: Seq[(os.SubPath, os.Path)]): java.nio.file.Path = {
def mapPathPrefixes2(
path: java.nio.file.Path,
mapping: Seq[(os.SubPath, os.Path)]
): java.nio.file.Path = {
mapping
.collectFirst { case (from, to) if path.startsWith(from.toNIO) || from.segments.isEmpty =>
to.wrapped.resolve(
// relativize misbehaves on empty paths
if (from.segments.isEmpty) path else from.toNIO.relativize(path)
)
.collectFirst {
case (from, to) if path.startsWith(from.toNIO) || from.segments.isEmpty =>
to.wrapped.resolve(
// relativize misbehaves on empty paths
if (from.segments.isEmpty) path else from.toNIO.relativize(path)
)
}
.getOrElse(path)
}

def normalizePath(path: os.Path): os.FilePath = mapPathPrefixes(path, mapping)

def denormalizePath(path: java.nio.file.Path): java.nio.file.Path = mapPathPrefixes2(path, mapping.map(_.swap))
def denormalizePath(path: java.nio.file.Path): java.nio.file.Path =
mapPathPrefixes2(path, mapping.map(_.swap))

def serializeString(p: os.Path): String = normalizePath(p) match {
case p: os.SubPath => p.toNIO.toString
Expand All @@ -61,7 +66,8 @@ class MillPathSerializer(mapping: Seq[(os.Path, os.SubPath)])

def deserialize(s: java.io.File) = denormalizePath(os.Path.defaultPathSerializer.deserialize(s))

def deserialize(s: java.nio.file.Path) = denormalizePath(os.Path.defaultPathSerializer.deserialize(s))
def deserialize(s: java.nio.file.Path) =
denormalizePath(os.Path.defaultPathSerializer.deserialize(s))

def deserialize(s: java.net.URI) = denormalizePath(os.Path.defaultPathSerializer.deserialize(s))

Expand Down
14 changes: 12 additions & 2 deletions core/src/mill/eval/EvaluatorImpl.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package mill.eval

import mill.api.{ColorLogger, CompileProblemReporter, DummyTestReporter, ExecResult, PathRef, TestReporter, Val}
import mill.api.{
ColorLogger,
CompileProblemReporter,
DummyTestReporter,
ExecResult,
PathRef,
TestReporter,
Val
}
import mill.constants.OutFiles
import mill.define.*
import mill.exec.{Execution, PlanImpl}
Expand Down Expand Up @@ -102,7 +110,9 @@ final class EvaluatorImpl private[mill] (
logger: ColorLogger = baseLogger,
serialCommandExec: Boolean = false,
selectiveExecution: Boolean = false
): Evaluator.Result[T] = os.Path.pathSerializer.withValue(new MillPathSerializer(MillPathSerializer.defaultMapping(workspace))) {
): Evaluator.Result[T] = os.Path.pathSerializer.withValue(new MillPathSerializer(
MillPathSerializer.defaultMapping(workspace)
)) {

val selectiveExecutionEnabled = selectiveExecution && !targets.exists(_.isExclusiveCommand)

Expand Down
5 changes: 2 additions & 3 deletions runner/src/mill/runner/FileImportGraph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ object FileImportGraph {
Seq(rootModuleAlias) ++
os.readLink.absolute(s / os.up).relativeTo(projectRoot).segments


mill.constants.DebugLog.println("")
mill.constants.DebugLog.println(""+projectRoot)
mill.constants.DebugLog.println(""+expectedImportSegments0)
mill.constants.DebugLog.println("" + projectRoot)
mill.constants.DebugLog.println("" + expectedImportSegments0)
val expectedImportSegments = expectedImportSegments0.map(backtickWrap).mkString(".")
if (
// Legacy `.sc` files have their package build be optional
Expand Down
9 changes: 7 additions & 2 deletions runner/src/mill/runner/MillBuildBootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ class MillBuildBootstrap(
val rootModuleRes = nestedState.frames.headOption match {
case None => Result.Success(nestedState.bootstrapModuleOpt.get)
case Some(nestedFrame) =>
try Result.Success(getRootModule(nestedFrame.classLoaderOpt.get, recRoot(projectRoot, depth)))
try Result.Success(getRootModule(
nestedFrame.classLoaderOpt.get,
recRoot(projectRoot, depth)
))
catch {
case e: Throwable => Result.Failure(renderFailure(e))
}
Expand Down Expand Up @@ -510,7 +513,9 @@ object MillBuildBootstrap {
def getRootModule(runClassLoader: URLClassLoader, workspace: os.Path): RootModule = {
val buildClass = runClassLoader.loadClass(s"$globalPackagePrefix.${wrapperObjectName}$$")
MillPathSerializer.setupSymlinks(os.pwd, workspace)
os.Path.pathSerializer.withValue(new MillPathSerializer(MillPathSerializer.defaultMapping(workspace))) {
os.Path.pathSerializer.withValue(new MillPathSerializer(
MillPathSerializer.defaultMapping(workspace)
)) {
os.checker.withValue(EvaluatorImpl.resolveChecker) {
buildClass.getField("MODULE$").get(buildClass).asInstanceOf[RootModule]
}
Expand Down
7 changes: 5 additions & 2 deletions scalalib/src/mill/scalalib/TestModuleUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ private[scalalib] object TestModuleUtil {
os.makeDir.all(sandbox)

os.checker.withValue(os.Checker.Nop) {
mill.constants.DebugLog.println((runClasspath ++ testrunnerEntrypointClasspath).map(_.path).mkString("\n"))
mill.constants.DebugLog.println(
(runClasspath ++ testrunnerEntrypointClasspath).map(_.path).mkString("\n")
)
mill.constants.DebugLog.println("\n" + new java.io.File(".").getAbsolutePath)
mill.constants.DebugLog.println("\n" + (if (testSandboxWorkingDir) sandbox else forkWorkingDir))
mill.constants.DebugLog.println("\n" + (if (testSandboxWorkingDir) sandbox
else forkWorkingDir))
Jvm.callProcess(
mainClass = "mill.testrunner.entrypoint.TestRunnerMain",
classPath = (runClasspath ++ testrunnerEntrypointClasspath).map(_.path),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ class ZincWorkerImpl(
.map(path => converter.toVirtualFile(os.Path.pathSerializer.value.serializePath(path)))
.toArray


val incOptions = IncOptions.of().withAuxiliaryClassFiles(
auxiliaryClassFileExtensions.map(new AuxiliaryClassFileExtension(_)).toArray
)
Expand Down
4 changes: 3 additions & 1 deletion testrunner/src/mill/testrunner/TestRunnerMain0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import mill.internal.PrintLogger
@internal object TestRunnerMain0 {
def main0(args: Array[String], classLoader: ClassLoader): Unit = {
try {
os.Path.pathSerializer.withValue(new mill.internal.MillPathSerializer(Seq(os.pwd -> os.sub))) {
os.Path.pathSerializer.withValue(
new mill.internal.MillPathSerializer(Seq(os.pwd -> os.sub))
) {
val testArgs = upickle.default.read[mill.testrunner.TestArgs](os.read(os.Path(args(1))))
val ctx = new Ctx.Log {
val log = new PrintLogger(
Expand Down

0 comments on commit 85f2113

Please sign in to comment.