-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The problem: We currently don't detect cycles in transitive `moduleDeps` and `compileModuleDeps`. Cycles in these result in a `StackOverflowError`. To solve this, we first need to detect cycles. This is the newly added `ModuleUtils.recursive` method. Instead of `moduleDeps` we use the `moduleDepsChecked` in some places to ensure we checked for cycles before accessing module dependencies. Unfortunately, we can't easily report the detected cycle at evaluation time, as `moduleDeps` needs to be evaluated before we can create a task graph (via `T.traverse`), hence we need an alternative way to propagate the exception. The current approach throws an `BuildScriptException` which itself derives from `mill.api.MillException`. In `MillMain` as well as `MillClientMain`, our central entry points to Mill, we catch the `MillException` and report the error to the user. Pull request: #2790
- Loading branch information
Showing
10 changed files
with
168 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package mill.scalalib | ||
|
||
import mill.api.BuildScriptException | ||
import mill.util.{TestEvaluator, TestUtil} | ||
import utest.framework.TestPath | ||
import utest.{TestSuite, Tests, compileError, intercept, test, assert} | ||
|
||
object CycleTests extends TestSuite { | ||
|
||
object CycleBase extends TestUtil.BaseModule { | ||
// See issue: https://github.com/com-lihaoyi/mill/issues/2341 | ||
object a extends ScalaModule { | ||
override def moduleDeps = Seq(a) | ||
override def scalaVersion = sys.props.getOrElse("TEST_SCALA_VERSION", ???) | ||
} | ||
object b extends JavaModule { | ||
override def moduleDeps = Seq(c) | ||
object c extends JavaModule { | ||
override def moduleDeps = Seq(d) | ||
} | ||
object d extends JavaModule { | ||
override def moduleDeps = Seq(b) | ||
} | ||
} | ||
object e extends JavaModule { | ||
override def moduleDeps = Seq(b) | ||
} | ||
object f extends JavaModule { | ||
override def compileModuleDeps = Seq(f) | ||
} | ||
} | ||
|
||
def workspaceTest[T](m: TestUtil.BaseModule)(t: TestEvaluator => T)(implicit tp: TestPath): T = { | ||
val eval = new TestEvaluator(m) | ||
os.remove.all(m.millSourcePath) | ||
os.remove.all(eval.outPath) | ||
os.makeDir.all(m.millSourcePath / os.up) | ||
t(eval) | ||
} | ||
|
||
override def tests: Tests = Tests { | ||
test("moduleDeps") { | ||
test("self-reference") - workspaceTest(CycleBase) { eval => | ||
val ex = intercept[BuildScriptException] { | ||
eval.apply(CycleBase.a.compile) | ||
} | ||
assert(ex.getMessage.contains("a.moduleDeps: cycle detected: a -> a")) | ||
} | ||
test("cycle-in-deps") - workspaceTest(CycleBase) { eval => | ||
val ex = intercept[BuildScriptException] { | ||
eval.apply(CycleBase.e.compile) | ||
} | ||
assert(ex.getMessage.contains("e.moduleDeps: cycle detected: b -> b.c -> b.d -> b")) | ||
} | ||
} | ||
test("compileModuleDeps") { | ||
test("self-reference") - workspaceTest(CycleBase) { eval => | ||
val ex = intercept[BuildScriptException] { | ||
eval.apply(CycleBase.f.compile) | ||
} | ||
assert(ex.getMessage.contains("f.compileModuleDeps: cycle detected: f -> f")) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters