com-lihaoyi / mill

Mill is a fast JVM build tool that supports Java and Scala. 2-4x faster than Gradle and 5-10x faster than Maven for common workflows, Mill aims to make your project’s build process performant, maintainable, and flexible
https://mill-build.org/
MIT License
2.18k stars 347 forks source link

Generated sources not being marked as `true` when using Bloop contrib. #2230

Open ckipp01 opened 1 year ago

ckipp01 commented 1 year ago

When using Mill as a build server the response to buildTarget/sources doesn't correctly mark generated sources as such. For example when using build info you'll notice that generated is false. You can see this for example in Scalatags.

  {
      "target": {
        "uri": "file:/Users/ckipp/Documents/scala-workspace/com-lihaoyi/scalatags/scalatags/jvm/?id\u003dscalatags.jvm[3.1.3].test"
      },
      "sources": [
        {
          "uri": "file:///Users/ckipp/Documents/scala-workspace/com-lihaoyi/scalatags/scalatags/jvm/test/src/",
          "kind": 2,
          "generated": false
        },
        {
          "uri": "file:///Users/ckipp/Documents/scala-workspace/com-lihaoyi/scalatags/scalatags/test/src/",
          "kind": 2,
          "generated": false
        },
        ....
        {
          "uri": "file:///Users/ckipp/Documents/scala-workspace/com-lihaoyi/scalatags/out/scalatags/jvm/3.1.3/test/generatedBuildInfo.dest/",
          "kind": 2,
          "generated": false
        }
      ]
    }

In this situation the generatedBuildInfo.dest should be marked as true for generated.

Refs: https://github.com/scalameta/metals/issues/4787

ckipp01 commented 1 year ago

I actually don't get why this is happening since this looks correct when you look at the generatedSources:

❯ mill showNamed scalatags.jvm\[3.1.3\].test.generatedSources
[1/1] showNamed
{
  "scalatags.jvm[3.1.3].test.generatedSources": [
    "ref:7d898225:/Users/ckipp/Documents/scala-workspace/com-lihaoyi/scalatags/out/scalatags/jvm/3.1.3/test/generatedBuildInfo.dest"
  ]
}

Plus this looks right as well.

https://github.com/com-lihaoyi/mill/blob/9004ff8f923f43f40a33b3998857c7dbe4147769/bsp/src/mill/bsp/MillBuildServer.scala#L361-L366

lefou commented 1 year ago

I just checked, both, the source code and the log of the BSP protocol suggests, we properly mark JavaModule.generatedSources with SourceItem.generated = true.

The generatedBuildInfo target comes from the BuildInfo contrib plugin, so this is probably specific to that plugin. Although, a first look shows, it is also extending JavaModule.generatedSources, so it should work as expected.

ckipp01 commented 1 year ago

Ah shoot, I was still on Bloop instead of mill-bsp. Ugh, sorry. So this is actually an issue then probably with the Bloop export.

Actually looking further I don't even see how to do this with the Bloop export. I wonder if this just isn't possible? I'll check. Don't spend time on this @lefou I'll either fix it or close it.

ckipp01 commented 1 year ago

Alright... digging even further. I think the only way we can do this with Bloop would be to utilize sourceGenerators. However looking at https://github.com/scalacenter/bloop/pull/1774 it's not super clear to me how this is meant to work with a tool like Mill. Would the command just be a mill command to regenerate? That might be hard to configure correctly.

lefou commented 1 year ago

Yeah, when I first looked into the sourceGenerators thing, I also thought, that it will not match easily with build tools, it's more suited when you use bloop as your primary tool.