Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be stricter about requiring build. prefix for cross-package.mill-file references #3456

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object RootSubfolderModuleCollisionTests extends IntegrationTestSuite {
test("success") {
val res = eval(("resolve", "_"))
assert(res.isSuccess == false)
assert(res.err.contains("sub is already defined as object sub"))
assert(res.err.contains("cannot override final member"))
assert(res.err.contains(
" final lazy val sub: _root_.build_.sub.package_.type = _root_.build_.sub.package_ // subfolder module referenc"
))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package build
import mill._

val x = sub.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package build.sub

import mill._
object `package` extends RootModule{
def y = 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package mill.integration

import mill.testkit.IntegrationTestSuite

import utest._

object SubfolderMissingBuildPrefix extends IntegrationTestSuite {
val tests: Tests = Tests {
initWorkspace()

test("success") {
val res = eval(("resolve", "_"))
assert(res.isSuccess == false)
assert(res.err.contains("object y is not a member of package build_.sub"))
}
}
}
8 changes: 3 additions & 5 deletions integration/ide/bsp-modules/repo/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ trait HelloBspModule extends ScalaModule {

object HelloBsp extends HelloBspModule {
// Explicitly depends on proj1
def moduleDeps: Seq[JavaModule] = Seq(proj1)
def moduleDeps: Seq[JavaModule] = Seq(build.proj1)
// Explicitly depends on proj2
def compileModuleDeps: Seq[JavaModule] = Seq(proj2)
def compileModuleDeps: Seq[JavaModule] = Seq(build.proj2)
// Implicitly depends on proj3 via a target
override def unmanagedClasspath: T[Agg[PathRef]] = T {
Agg(proj3.jar())
}
override def unmanagedClasspath: T[Agg[PathRef]] = Agg(build.proj3.jar())
}

def validate() = T.command {
Expand Down
18 changes: 9 additions & 9 deletions integration/invalidation/invalidation/repo/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ import mill._
import $ivy.`org.scalaj::scalaj-http:2.4.2`

def task = T {
a.input()
b.input()
c.input()
build.a.input()
build.b.input()
build.c.input()
}

object module extends Module {
def task = T {
println("task")
a.input()
b.input()
c.input()
build.a.input()
build.b.input()
build.c.input()
}
}

def taskE = T {
println("taskE")
e.input()
build.e.input()
}

def taskSymbols = T {
println("taskSymbols")
`-#!+→&%=~`.input()
build.`-#!+→&%=~`.input()
}

def taskSymbolsInFile = T {
println("taskSymbolsInFile")
`-#+&%`.input()
build.`-#+&%`.input()
}
25 changes: 9 additions & 16 deletions runner/src/mill/runner/CodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ object CodeGen {
val prelude = topBuildPrelude(
scriptFolderPath,
enclosingClasspath,
millTopLevelProjectRoot,
childAliases
millTopLevelProjectRoot
)
val segments = scriptFolderPath.relativeTo(projectRoot).segments
val instrument = new ObjectDataInstrument(scriptCode)
Expand Down Expand Up @@ -173,12 +172,9 @@ object CodeGen {
s"""$pkgLine
|$aliasImports
|$prelude
|${topBuildHeader(segments, scriptFolderPath, millTopLevelProjectRoot)}
|${topBuildHeader(segments, scriptFolderPath, millTopLevelProjectRoot, childAliases)}
|$markerComment
|$scriptCode
|// define this after user code so in case of conflict these lines are what turn
|// up in the error message, so we can add a comment and control what the user sees
|$childAliases
|}""".stripMargin

}
Expand All @@ -187,8 +183,7 @@ object CodeGen {
def topBuildPrelude(
scriptFolderPath: os.Path,
enclosingClasspath: Seq[os.Path],
millTopLevelProjectRoot: os.Path,
childAliases: String
millTopLevelProjectRoot: os.Path
): String = {
s"""import _root_.mill.runner.MillBuildRootModule
|@_root_.scala.annotation.nowarn
Expand All @@ -197,20 +192,16 @@ object CodeGen {
| ${literalize(scriptFolderPath.toString)},
| ${literalize(millTopLevelProjectRoot.toString)},
| _root_.mill.define.Discover[$wrapperObjectName.type]
|){
| // aliases so child modules can be referred to directly as `foo` rather
| // than `foo.module`. Need to be outside `MillPackageClass` in case they are
| // referenced in the combined `extends` clause
| $childAliases
|}
|)
|import MillMiscInfo._
|""".stripMargin
}

def topBuildHeader(
segs: Seq[String],
scriptFolderPath: os.Path,
millTopLevelProjectRoot: os.Path
millTopLevelProjectRoot: os.Path,
childAliases: String
): String = {
val extendsClause = if (segs.isEmpty) {
if (millTopLevelProjectRoot == scriptFolderPath) {
Expand All @@ -225,7 +216,9 @@ object CodeGen {

// User code needs to be put in a separate class for proper submodule
// object initialization due to https://github.com/scala/scala3/issues/21444
s"""object $wrapperObjectName extends $wrapperObjectName
s"""object $wrapperObjectName extends $wrapperObjectName{
| $childAliases
|}
|class $wrapperObjectName $extendsClause {""".stripMargin

}
Expand Down
Loading