Skip to content

Commit

Permalink
Add --no-wait-for-build-lock option
Browse files Browse the repository at this point in the history
Mainly meant to be used in integration tests
  • Loading branch information
alexarchambault committed Oct 7, 2024
1 parent ba19f3c commit 80acc92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 5 additions & 2 deletions main/api/src/mill/api/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ trait Logger extends Closeable {
finally removePromptLine()
}

def waitForLock(lock: Lock): Locked = {
def waitForLock(lock: Lock, waitingAllowed: Boolean): Locked = {
val tryLocked = lock.tryLock()
if (tryLocked.isLocked())
tryLocked
else {
else if (waitingAllowed) {
info("Another Mill process is running tasks, waiting for it to be done...")
lock.lock()
} else {
error("Cannot proceed, another Mill process is running tasks")
throw new Exception("Cannot acquire lock on Mill output directory")
}
}
}
8 changes: 7 additions & 1 deletion runner/src/mill/runner/MillCliConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ case class MillCliConfig(
doc =
"""Evaluate tasks / commands without acquiring an exclusive lock on the Mill output directory"""
)
noBuildLock: Flag = Flag()
noBuildLock: Flag = Flag(),
@arg(
hidden = true,
doc =
"""Do not wait for an exclusive lock on the Mill output directory to evaluate tasks / commands. Fail if waiting for a lock is needed."""
)
noWaitForBuildLock: Flag = Flag()
)

import mainargs.ParserForClass
Expand Down
5 changes: 4 additions & 1 deletion runner/src/mill/runner/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ object MillMain {
)
Using.resources(
logger,
logger.waitForLock(outLock)
logger.waitForLock(
outLock,
waitingAllowed = !config.noWaitForBuildLock.value
)
) { (_, _) =>
new MillBuildBootstrap(
projectRoot = WorkspaceRoot.workspaceRoot,
Expand Down

0 comments on commit 80acc92

Please sign in to comment.