From 82db4fc7f1349390ca5857dfd24e30b4fc316c5c Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 4 Jul 2025 18:33:29 +0800 Subject: [PATCH 1/4] . --- runner/daemon/src/mill/daemon/MillMain0.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runner/daemon/src/mill/daemon/MillMain0.scala b/runner/daemon/src/mill/daemon/MillMain0.scala index 3ef827b73a5b..81e736450a92 100644 --- a/runner/daemon/src/mill/daemon/MillMain0.scala +++ b/runner/daemon/src/mill/daemon/MillMain0.scala @@ -408,7 +408,8 @@ object MillMain0 { (!errored, RunnerState(None, Nil, None)) } else if ( config.leftoverArgs.value == Seq("mill.idea.GenIdea/idea") || - config.leftoverArgs.value == Seq("mill.idea.GenIdea/") + config.leftoverArgs.value == Seq("mill.idea.GenIdea/") || + config.leftoverArgs.value == Seq("mill.idea/") ) { val runnerState = runMillBootstrap(false, None, Seq("version"), streams, "BSP:initialize") From 64afbcf1820f947b06943391af4db423a9fefc7d Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 4 Jul 2025 18:46:00 +0800 Subject: [PATCH 2/4] . --- runner/daemon/src/mill/daemon/MillMain0.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runner/daemon/src/mill/daemon/MillMain0.scala b/runner/daemon/src/mill/daemon/MillMain0.scala index 81e736450a92..a5c85950c5f2 100644 --- a/runner/daemon/src/mill/daemon/MillMain0.scala +++ b/runner/daemon/src/mill/daemon/MillMain0.scala @@ -171,7 +171,8 @@ object MillMain0 { val viaEmulatedExternalCommand = Option.when( !config.bsp.value && - config.leftoverArgs.value.headOption.contains("mill.bsp.BSP/install") + (config.leftoverArgs.value.headOption.contains("mill.bsp.BSP/install") || + config.leftoverArgs.value.headOption.contains("mill.bsp/install")) ) { config.leftoverArgs.value.tail match { case Seq() => defaultJobCount From 936aa740878776d69f451fdea0dac16cc7b784ca Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 4 Jul 2025 19:17:55 +0800 Subject: [PATCH 3/4] . --- libs/main/src/mill/main/MainModule.scala | 86 ++++++++++++------------ 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/libs/main/src/mill/main/MainModule.scala b/libs/main/src/mill/main/MainModule.scala index 9ef949a1c8e5..6ae8166567f5 100644 --- a/libs/main/src/mill/main/MainModule.scala +++ b/libs/main/src/mill/main/MainModule.scala @@ -142,7 +142,7 @@ trait MainModule extends BaseModule with MainModuleApi { evaluator: EvaluatorApi, tasks: String* ): TaskApi[Seq[java.nio.file.Path]] = Task.Anon { - clean(evaluator.asInstanceOf[Evaluator], tasks*)().map(_.path.toNIO) + cleanTask(evaluator.asInstanceOf[Evaluator], tasks*)().map(_.path.toNIO) } /** @@ -150,55 +150,57 @@ trait MainModule extends BaseModule with MainModuleApi { * will clean everything. */ def clean(evaluator: Evaluator, tasks: String*): Command[Seq[PathRef]] = - Task.Command(exclusive = true) { - val rootDir = evaluator.outPath + Task.Command(exclusive = true) { cleanTask(evaluator, tasks*)() } - val KeepPattern = "(mill-.+)".r.anchored + def cleanTask(evaluator: Evaluator, tasks: String*) = Task.Anon{ + val rootDir = evaluator.outPath - def keepPath(path: os.Path) = path.last match { - case KeepPattern(_) => true - case _ => false - } + val KeepPattern = "(mill-.+)".r.anchored - val pathsToRemove = - if (tasks.isEmpty) - Result.Success((os.list(rootDir).filterNot(keepPath), List(mill.api.Segments()))) - else - evaluator.resolveSegments(tasks, SelectMode.Multi).map { ts => - val allPaths = ts.flatMap { segments => - val evPaths = ExecutionPaths.resolve(rootDir, segments) - val paths = Seq(evPaths.dest, evPaths.meta, evPaths.log) - val potentialModulePath = rootDir / segments.parts - if (os.exists(potentialModulePath)) { - // this is either because of some pre-Mill-0.10 files lying around - // or most likely because the segments denote a module but not a task - // in which case we want to remove the module and all its sub-modules - // (If this logic is later found to be too harsh, we could further guard it, - // to when none of the other paths exists.) - paths :+ potentialModulePath - } else paths - } - (allPaths, ts) - } + def keepPath(path: os.Path) = path.last match { + case KeepPattern(_) => true + case _ => false + } - (pathsToRemove: @unchecked).map { - case (paths, allSegments) => - for { - workerSegments <- evaluator.workerCache.keys.toList - if allSegments.exists(x => workerSegments.startsWith(x.render)) - case (_, Val(closeable: AutoCloseable)) <- - evaluator.workerCache.remove(workerSegments) - } { - closeable.close() + val pathsToRemove = + if (tasks.isEmpty) + Result.Success((os.list(rootDir).filterNot(keepPath), List(mill.api.Segments()))) + else + evaluator.resolveSegments(tasks, SelectMode.Multi).map { ts => + val allPaths = ts.flatMap { segments => + val evPaths = ExecutionPaths.resolve(rootDir, segments) + val paths = Seq(evPaths.dest, evPaths.meta, evPaths.log) + val potentialModulePath = rootDir / segments.parts + if (os.exists(potentialModulePath)) { + // this is either because of some pre-Mill-0.10 files lying around + // or most likely because the segments denote a module but not a task + // in which case we want to remove the module and all its sub-modules + // (If this logic is later found to be too harsh, we could further guard it, + // to when none of the other paths exists.) + paths :+ potentialModulePath + } else paths } + (allPaths, ts) + } - val existing = paths.filter(p => os.exists(p)) - Task.log.debug(s"Cleaning ${existing.size} paths ...") - existing.foreach(os.remove.all(_, ignoreErrors = true)) - existing.map(PathRef(_)) - } + (pathsToRemove: @unchecked).map { + case (paths, allSegments) => + for { + workerSegments <- evaluator.workerCache.keys.toList + if allSegments.exists(x => workerSegments.startsWith(x.render)) + case (_, Val(closeable: AutoCloseable)) <- + evaluator.workerCache.remove(workerSegments) + } { + closeable.close() + } + + val existing = paths.filter(p => os.exists(p)) + Task.log.debug(s"Cleaning ${existing.size} paths ...") + existing.foreach(os.remove.all(_, ignoreErrors = true)) + existing.map(PathRef(_)) } + } /** * Renders the dependencies between the given tasks as a SVG for you to look at */ From 3487b72c9fd773dde9b67ba3ec8da2dba85f2c84 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 4 Jul 2025 19:18:53 +0800 Subject: [PATCH 4/4] . --- libs/main/src/mill/main/MainModule.scala | 3 ++- runner/daemon/src/mill/daemon/MillMain0.scala | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/main/src/mill/main/MainModule.scala b/libs/main/src/mill/main/MainModule.scala index 6ae8166567f5..e8c81a6c720d 100644 --- a/libs/main/src/mill/main/MainModule.scala +++ b/libs/main/src/mill/main/MainModule.scala @@ -152,7 +152,7 @@ trait MainModule extends BaseModule with MainModuleApi { def clean(evaluator: Evaluator, tasks: String*): Command[Seq[PathRef]] = Task.Command(exclusive = true) { cleanTask(evaluator, tasks*)() } - def cleanTask(evaluator: Evaluator, tasks: String*) = Task.Anon{ + def cleanTask(evaluator: Evaluator, tasks: String*) = Task.Anon { val rootDir = evaluator.outPath val KeepPattern = "(mill-.+)".r.anchored @@ -201,6 +201,7 @@ trait MainModule extends BaseModule with MainModuleApi { } } + /** * Renders the dependencies between the given tasks as a SVG for you to look at */ diff --git a/runner/daemon/src/mill/daemon/MillMain0.scala b/runner/daemon/src/mill/daemon/MillMain0.scala index a5c85950c5f2..05046c5ca0f5 100644 --- a/runner/daemon/src/mill/daemon/MillMain0.scala +++ b/runner/daemon/src/mill/daemon/MillMain0.scala @@ -172,7 +172,7 @@ object MillMain0 { val viaEmulatedExternalCommand = Option.when( !config.bsp.value && (config.leftoverArgs.value.headOption.contains("mill.bsp.BSP/install") || - config.leftoverArgs.value.headOption.contains("mill.bsp/install")) + config.leftoverArgs.value.headOption.contains("mill.bsp/install")) ) { config.leftoverArgs.value.tail match { case Seq() => defaultJobCount