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

Move .mill.sc extension to .mill.scala #3521

Merged
merged 5 commits into from
Sep 12, 2024
Merged
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
2 changes: 1 addition & 1 deletion contrib/errorprone/readme.adoc
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ https://errorprone.info/index[Error Prone] augments the Java compiler's type che

You just need to mix the `ErrorProneModule` into your `JavaModule` and it will automatically run with every compilation.

.`build.mill.sc`: Enable `ErrorProne` in a module
.`build.mill.scala`: Enable `ErrorProne` in a module
[source,scala]
----
package build
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@ object `package` extends RootModule with MyModule{
"MY_PROJECT_VERSION" -> versions.myProjectVersion,
)
}
///** See Also: util.mill.sc */
///** See Also: foo/package.mill.sc */
///** See Also: foo/versions.mill.sc */
///** See Also: util.mill.scala */
///** See Also: foo/package.mill.scala */
///** See Also: foo/versions.mill.scala */


// Apart from having `package` files in subfolders to define modules, Mill
6 changes: 3 additions & 3 deletions main/client/src/mill/main/client/CodeGenConstants.java
Original file line number Diff line number Diff line change
@@ -21,17 +21,17 @@ public class CodeGenConstants {
/**
* The name of the root build file
*/
final public static String[] rootBuildFileNames = {"build.mill", "build.mill.sc", "build.sc"};
final public static String[] rootBuildFileNames = {"build.mill", "build.mill.scala", "build.sc"};

/**
* The name of any sub-folder build files
*/
final public static String[] nestedBuildFileNames = {"package.mill", "package.mill.sc", "package.sc"};
final public static String[] nestedBuildFileNames = {"package.mill", "package.mill.scala", "package.sc"};

/**
* The extensions used by build files
*/
final public static String[] buildFileExtensions = {"mill", "mill.sc", "sc"};
final public static String[] buildFileExtensions = {"mill", "mill.scala", "sc"};

/**
* The user-facing name for the root of the module tree.
12 changes: 9 additions & 3 deletions mill-build/src/ExampleParser.scala
Original file line number Diff line number Diff line change
@@ -6,9 +6,15 @@ object ExampleParser {
val states = collection.mutable.Buffer("scala")
val chunks = collection.mutable.Buffer(collection.mutable.Buffer.empty[String])

val rootBuildFileNames = Seq("build.sc", "build.mill", "build.mill.sc")
val buildFile = rootBuildFileNames.map(testRepoRoot / _).find(os.exists)
for (line <- os.read.lines(buildFile.get)) {
val rootBuildFileNames = Seq("build.sc", "build.mill", "build.mill.scala")
val buildFile = rootBuildFileNames.map(testRepoRoot / _)
.find(os.exists)
Copy link
Member

@lefou lefou Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should report multiple detected root files. If we have a strong precedence, just reporting a warning should be enough. E.g. to allow for sym-linking build.mill to build.mill.scala without build failures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a logged warning

.getOrElse(
sys.error(
s"No build file named ${rootBuildFileNames.mkString("/")} found in $testRepoRoot"
)
)
for (line <- os.read.lines(buildFile)) {
val (newState, restOpt) = line match {
case s"/** Usage" => ("example", None)
case s"/** See Also: $path */" =>
20 changes: 14 additions & 6 deletions runner/src/mill/runner/FileImportGraph.scala
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ object FileImportGraph {
val expectedImportSegments = expectedImportSegments0.map(backtickWrap).mkString(".")
if (
// Legacy `.sc` files have their package build be optional
(s.last.endsWith(".mill") || s.last.endsWith(".mill.sc")) &&
(s.last.endsWith(".mill") || s.last.endsWith(".mill.scala")) &&
expectedImportSegments != importSegments &&
// Root build.mill file has its `package build` be optional
!(importSegments == "" && rootBuildFileNames.contains(s.last))
@@ -136,7 +136,7 @@ object FileImportGraph {
case ImportTree(Seq(("$file", end0), rest @ _*), mapping, start, end) =>
// Only recursively explore imports from legacy `.sc` files, as new `.mill` files
// do file discovery via scanning folders containing `package.mill` files
if (s.last.endsWith(".sc") && !s.last.endsWith(".mill.sc")) {
if (s.last.endsWith(".sc") && !s.last.endsWith(".mill.scala")) {
val nextPaths = mapping.map { case (lhs, rhs) =>
nextPathFor(s, rest.map(_._1) :+ lhs)
}
@@ -161,10 +161,18 @@ object FileImportGraph {
}

val rootBuildFiles = rootBuildFileNames
.find(rootBuildFileName => os.exists(projectRoot / rootBuildFileName))

val useDummy = rootBuildFiles.isEmpty
val foundRootBuildFileName: String = rootBuildFiles.getOrElse(rootBuildFileNames.head)
.filter(rootBuildFileName => os.exists(projectRoot / rootBuildFileName))

val (useDummy, foundRootBuildFileName) = rootBuildFiles.toSeq match {
case Nil => (true, rootBuildFileNames.head)
case Seq(single) => (false, single)
case multiple =>
System.err.println(
"Multiple root build files found: " + multiple.mkString(",") +
", picking " + multiple.head
)
(false, multiple.head)
}

val buildFileExtension =
buildFileExtensions.find(ex => foundRootBuildFileName.endsWith(s".$ex")).get