Skip to content

Commit

Permalink
Report when we could not detect the declaring parent of a target (#2885)
Browse files Browse the repository at this point in the history
We now report the target name in case we weren't able to detect it's
declaring parent class.

Tested manually with a Mill version before the merge of #2883.

```scala
// /tmp/mill-2844/build.sc
import mill._

object mod extends Module {

  object foo extends Module {
    def bar = T {
      baz()
    }
  }

  private def baz = T { "baz" }
}
```

```
> mill -i dev.run /tmp/mill-2844 -i mod.foo.bar
[1691/1691] dev.run 
[info] compiling 1 Scala source to /tmp/mill-2844/out/mill-build/compile.dest/classes ...
[info] done compiling
Could not detect the parent class of target mod.baz. Please report this at https://github.com/com-lihaoyi/mill/issues/new/choose. As a workaround, you can run Mill with `--disable-callgraph-invalidation` option.
```

Pull request: #2885
  • Loading branch information
lefou authored Nov 19, 2023
1 parent d6f56f8 commit 9e0ec9a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
21 changes: 15 additions & 6 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object Settings {
val githubRepo = "mill"
val projectUrl = s"https://github.com/${githubOrg}/${githubRepo}"
val changelogUrl = s"${projectUrl}#changelog"
val newIssueUrl = s"${projectUrl}/issues/new/choose"
val docUrl = "https://mill-build.com"
// the exact branches containing a doc root
val docBranches = Seq()
Expand Down Expand Up @@ -109,7 +110,8 @@ object Deps {
object Play_3_0 extends Play {
val playVersion = "3.0.0"
}
val play = Seq(Play_3_0, Play_2_9, Play_2_8, Play_2_7, Play_2_6).map(p => (p.playBinVersion, p)).toMap
val play =
Seq(Play_3_0, Play_2_9, Play_2_8, Play_2_7, Play_2_6).map(p => (p.playBinVersion, p)).toMap

val acyclic = ivy"com.lihaoyi:::acyclic:0.3.9"
val ammoniteVersion = "3.0.0-M0-53-084f7f4e"
Expand Down Expand Up @@ -493,7 +495,12 @@ object main extends MillStableScalaModule with BuildInfo {
def buildInfoPackageName = "mill.api"
def buildInfoMembers = Seq(
BuildInfo.Value("millVersion", millVersion(), "Mill version."),
BuildInfo.Value("millDocUrl", Settings.docUrl, "Mill documentation url.")
BuildInfo.Value("millDocUrl", Settings.docUrl, "Mill documentation url."),
BuildInfo.Value(
"millReportNewIssueUrl",
Settings.newIssueUrl,
"URL to create a new issue in Mills issue tracker."
)
)

def ivyDeps = Agg(
Expand Down Expand Up @@ -1417,15 +1424,17 @@ object dev extends MillPublishScalaModule {
case wd0 +: rest =>
val wd = os.Path(wd0, T.workspace)
os.makeDir.all(wd)
try Jvm.runSubprocess(
try {
Jvm.runSubprocess(
Seq(launcher().path.toString) ++ rest,
forkEnv(),
workingDir = wd
)
catch {
case e: Throwable => () /*ignore to avoid confusing stacktrace and error messages*/
mill.api.Result.Success(())
} catch {
case e: Throwable =>
mill.api.Result.Failure(s"dev.run failed with an exception. ${e.getMessage()}")
}
mill.api.Result.Success(())
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions main/eval/src/mill/eval/GroupEvaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ private[mill] trait GroupEvaluator {
m.getName == (c.getName.replace('.', '$') + "$" + encodedTaskName)
} yield m

val methodClass = methods.head.getDeclaringClass.getName
val methodClass = methods
.headOption
.getOrElse(throw new MillException(
s"Could not detect the parent class of target ${namedTask}. " +
s"Please report this at ${BuildInfo.millReportNewIssueUrl} . " +
s"As a workaround, you can run Mill with `--disable-callgraph-invalidation` option."
))
.getDeclaringClass.getName
val name = namedTask.ctx.segment.pathSegments.last
val expectedName = methodClass + "#" + name + "()mill.define.Target"

Expand All @@ -123,15 +130,16 @@ private[mill] trait GroupEvaluator {
ctx.enclosingModule match {
case null => None
case m: mill.define.Module => Some((m, m.millOuterCtx))
case unknown => sys.error(s"Unknown ctx: $unknown")
case unknown =>
throw new MillException(s"Unknown ctx of target ${namedTask}: $unknown")
}
}

val constructorHashes = allEnclosingModules
.map(m =>
constructorHashSignatures.get(m.getClass.getName) match {
case Some(Seq((singleMethod, hash))) => hash
case Some(multiple) => sys.error(
case Some(multiple) => throw new MillException(
s"Multiple constructors found for module $m: ${multiple.mkString(",")}"
)
case None => 0
Expand Down

0 comments on commit 9e0ec9a

Please sign in to comment.