Skip to content

Commit 598aaea

Browse files
authored
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
1 parent 23563b4 commit 598aaea

File tree

17 files changed

+50
-103
lines changed

17 files changed

+50
-103
lines changed

docs/modules/ROOT/pages/large/multi-file-builds.adoc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,5 @@ include::partial$example/large/multi/10-multi-file-builds.adoc[]
99

1010
include::partial$example/large/multi/11-helper-files.adoc[]
1111

12-
== Legacy `.sc` extension
13-
14-
include::partial$example/large/multi/12-helper-files-sc.adoc[]
1512

1613

example/large/multi/11-helper-files/build.mill

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
package build
66
import $packages._
77
import mill._, scalalib._
8-
import $file.foo.versions
9-
import $file.util.MyModule
8+
import foo.versions
109

1110
object `package` extends RootModule with MyModule {
1211
def forkEnv = Map(
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package build.foo
22
import mill._, scalalib._
3-
import $file.util
4-
import $file.foo.versions.myProjectVersion
5-
object `package` extends RootModule with build_.util.MyModule {
3+
import versions.myProjectVersion
4+
object `package` extends RootModule with build.MyModule {
65
def forkEnv = Map(
7-
"MY_SCALA_VERSION" -> util.myScalaVersion,
6+
"MY_SCALA_VERSION" -> build.myScalaVersion,
87
"MY_PROJECT_VERSION" -> myProjectVersion
98
)
109
}

example/large/multi/13-helper-files-mill-scala/build.mill.scala renamed to example/large/multi/12-helper-files-mill-scala/build.mill.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package build
22
import $packages._
33
import mill._, scalalib._
4-
import $file.foo.versions
5-
import $file.util.MyModule
64

75
object `package` extends RootModule with MyModule {
86
def forkEnv = Map(
97
"MY_SCALA_VERSION" -> build.scalaVersion(),
10-
"MY_PROJECT_VERSION" -> versions.myProjectVersion
8+
"MY_PROJECT_VERSION" -> build.foo.myProjectVersion
119
)
1210
}
1311
///** See Also: util.mill.scala */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package build.foo
2+
import mill._, scalalib._
3+
object `package` extends RootModule with build.MyModule {
4+
def forkEnv = Map(
5+
"MY_SCALA_VERSION" -> build.myScalaVersion,
6+
"MY_PROJECT_VERSION" -> myProjectVersion
7+
)
8+
}

example/large/multi/12-helper-files-sc/build.sc

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)