-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace
import $file
syntax with flat package namespacing (#4462)
Fixes #4459 Fixes #3894 With this PR, all `.mill` files in a folder are in the same flat `package` namespace, similar to how normal Scala files work. The previous `import $file` syntax was inherited from Ammonite, and unfortunately never took off across the Scala community. In effect this makes `.mill` files behave almost exactly like `.scala` files, which is part of the longer term goal of removing special handling for `.mill` files. The code generation for the helper files is not changed at all in this PR, rather we just make use of Scala 3's `export` clauses to make them available under the main `build.mill`/`package.mill` file as well There is the caveat that the `package object`s in `.mill` files can be referenced via `build.foo.bar` without the trailing `.package`. Implementing this caveat is the cause of a lot of the hackiness in the codegen, which will hopefully go away once the upstream language feature lands scala/improvement-proposals#100 We leave the codegenned `import _root_.{build_ => $file}` in place so `import $file` will continue to work to ease in the migration, but are no longer the recommended way of referencing helper files
- Loading branch information
Showing
17 changed files
with
50 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
package build.foo | ||
import mill._, scalalib._ | ||
import $file.util | ||
import $file.foo.versions.myProjectVersion | ||
object `package` extends RootModule with build_.util.MyModule { | ||
import versions.myProjectVersion | ||
object `package` extends RootModule with build.MyModule { | ||
def forkEnv = Map( | ||
"MY_SCALA_VERSION" -> util.myScalaVersion, | ||
"MY_SCALA_VERSION" -> build.myScalaVersion, | ||
"MY_PROJECT_VERSION" -> myProjectVersion | ||
) | ||
} |
4 changes: 1 addition & 3 deletions
4
...-helper-files-mill-scala/build.mill.scala → ...-helper-files-mill-scala/build.mill.scala
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
8 changes: 8 additions & 0 deletions
8
example/large/multi/12-helper-files-mill-scala/foo/package.mill.scala
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,8 @@ | ||
package build.foo | ||
import mill._, scalalib._ | ||
object `package` extends RootModule with build.MyModule { | ||
def forkEnv = Map( | ||
"MY_SCALA_VERSION" -> build.myScalaVersion, | ||
"MY_PROJECT_VERSION" -> myProjectVersion | ||
) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
example/large/multi/13-helper-files-mill-scala/foo/package.mill.scala
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
example/large/multi/13-helper-files-mill-scala/foo/src/Foo.scala
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
example/large/multi/13-helper-files-mill-scala/src/Main.scala
This file was deleted.
Oops, something went wrong.
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