Skip to content
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
87 changes: 45 additions & 42 deletions libs/main/src/mill/main/MainModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,63 +142,66 @@ 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)
}

/**
* Deletes the given targets from the out directory. Providing no targets
* 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
*/
Expand Down
6 changes: 4 additions & 2 deletions runner/daemon/src/mill/daemon/MillMain0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -408,7 +409,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")
Expand Down