Skip to content

Commit c594690

Browse files
authored
Fix "Can't clean external worker" (#6559)
Fixes #6549
1 parent c03fa73 commit c594690

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

libs/util/src/mill/util/MainModule.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ trait MainModule extends RootModule0, MainModuleApi, JdkCommandsModule {
243243
val allPaths = ts.flatMap { segments =>
244244
val evPaths = ExecutionPaths.resolve(rootDir, segments)
245245
val paths = Seq(evPaths.dest, evPaths.meta, evPaths.log)
246-
val potentialModulePath = rootDir / segments.parts
246+
val potentialModulePath =
247+
rootDir / segments.parts.map(ExecutionPaths.sanitizePathSegment)
247248
if (os.exists(potentialModulePath)) {
248249
// this is either because of some pre-Mill-0.10 files lying around
249250
// or most likely because the segments denote a module but not a task

libs/util/test/src/mill/util/MainModuleTests.scala

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import mill.api.{ExecResult, Result, Val}
44
import mill.constants.{OutFolderMode}
55
import mill.constants.OutFiles.OutFiles
66
import mill.{Task, given}
7-
import mill.api.{Cross, DefaultTaskModule, Discover, Module, PathRef}
7+
import mill.api.{Cross, DefaultTaskModule, Discover, ExternalModule, Module, PathRef}
88
import mill.testkit.UnitTester
99
import mill.testkit.TestRootModule
1010
import mill.util.MainModule
@@ -15,6 +15,17 @@ import scala.collection.mutable
1515
import scala.concurrent.duration.DurationInt
1616
import scala.util.Properties
1717

18+
// External module for testing clean command with external workers
19+
object TestExternalWorkerModule extends ExternalModule {
20+
def externalWorker = Task.Worker {
21+
new AutoCloseable {
22+
def close() = ()
23+
override def toString = "externalWorkerInstance"
24+
}
25+
}
26+
lazy val millDiscover = Discover[this.type]
27+
}
28+
1829
object MainModuleTests extends TestSuite {
1930

2031
object mainModule extends TestRootModule with MainModule {
@@ -707,6 +718,31 @@ object MainModuleTests extends TestSuite {
707718
assert(workers.size == 2)
708719
}
709720
}
721+
722+
test("external-module") {
723+
// Test cleaning external module workers (issue #6549)
724+
// External modules have segments ending with '/' which need special handling
725+
object externalModuleBuild extends TestRootModule with MainModule {
726+
def useExternalWorker = Task {
727+
TestExternalWorkerModule.externalWorker()
728+
"done"
729+
}
730+
lazy val millDiscover = Discover[this.type]
731+
}
732+
UnitTester(externalModuleBuild, null).scoped { ev =>
733+
// First run the task that uses the external worker
734+
val r1 = ev.evaluator.execute(Seq(externalModuleBuild.useExternalWorker)).executionResults
735+
assert(r1.transitiveFailing.size == 0)
736+
737+
// Now try to clean the external worker - this should not throw an error
738+
// Previously this would fail with: "[mill.util.TestExternalWorkerModule/] is not a valid path segment"
739+
val r2 = ev.evaluator.execute(Seq(externalModuleBuild.clean(
740+
ev.evaluator,
741+
"mill.util.TestExternalWorkerModule/externalWorker"
742+
))).executionResults
743+
assert(r2.transitiveFailing.size == 0)
744+
}
745+
}
710746
}
711747
}
712748
}

0 commit comments

Comments
 (0)