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

Add .mill.sc as an alternative file extension to .mill #3461

Merged
merged 64 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
f60c6e0
.
lihaoyi Sep 4, 2024
46a7fbf
.
lihaoyi Sep 4, 2024
d299550
.
lihaoyi Sep 4, 2024
90f5d61
.
lihaoyi Sep 4, 2024
d4d2ebd
.
lihaoyi Sep 4, 2024
8d4c781
.
lihaoyi Sep 4, 2024
fd98b5f
.
lihaoyi Sep 4, 2024
5ce3539
.
lihaoyi Sep 5, 2024
dde2b8f
.
lihaoyi Sep 5, 2024
13567c0
Merge branch 'main' into mill-sc
lihaoyi Sep 5, 2024
4f271ad
.
lihaoyi Sep 5, 2024
45264b1
Merge commit 'fetch_head' into mill-sc
lihaoyi Sep 5, 2024
680f482
.
lihaoyi Sep 5, 2024
f86a8c0
.
lihaoyi Sep 5, 2024
6c2e3da
.
lihaoyi Sep 5, 2024
423319e
.
lihaoyi Sep 5, 2024
308e0e5
.
lihaoyi Sep 5, 2024
6b7484e
.
lihaoyi Sep 5, 2024
1719dd2
.
lihaoyi Sep 5, 2024
9cb20e0
.
lihaoyi Sep 5, 2024
ce0d6e4
.
lihaoyi Sep 5, 2024
ae90e40
.
lihaoyi Sep 5, 2024
abf0065
.
lihaoyi Sep 5, 2024
b6c03d5
.
lihaoyi Sep 5, 2024
44af1ca
.
lihaoyi Sep 5, 2024
37de28a
.
lihaoyi Sep 5, 2024
98fca89
.
lihaoyi Sep 5, 2024
fb3da09
.
lihaoyi Sep 5, 2024
263c808
.
lihaoyi Sep 5, 2024
217944e
.
lihaoyi Sep 5, 2024
9ffdbbe
.
lihaoyi Sep 5, 2024
51e5ef5
.
lihaoyi Sep 5, 2024
8fcb5c3
.
lihaoyi Sep 5, 2024
7fbf05c
.
lihaoyi Sep 5, 2024
bc42f20
.
lihaoyi Sep 5, 2024
2cb7ff0
.
lihaoyi Sep 5, 2024
40b24e5
.
lihaoyi Sep 5, 2024
8c50d05
.
lihaoyi Sep 5, 2024
132b5d2
.
lihaoyi Sep 5, 2024
13f5c36
.
lihaoyi Sep 5, 2024
1790aa1
Merge branch 'main' into mill-sc
lihaoyi Sep 5, 2024
9321c1a
.
lihaoyi Sep 5, 2024
ef43364
.
lihaoyi Sep 5, 2024
aba531b
.
lihaoyi Sep 5, 2024
d175942
.
lihaoyi Sep 5, 2024
e01eb6f
.
lihaoyi Sep 5, 2024
67aebc0
intergrationTest{} helper
lihaoyi Sep 5, 2024
e6cd0d1
.
lihaoyi Sep 5, 2024
a02f687
.
lihaoyi Sep 5, 2024
d202eff
makedir
lihaoyi Sep 5, 2024
64becba
makedir
lihaoyi Sep 5, 2024
4d7547e
makedir
lihaoyi Sep 5, 2024
103cda8
Merge branch 'integration-test-helper' into mill-sc
lihaoyi Sep 5, 2024
e3b325c
.
lihaoyi Sep 5, 2024
d07d694
.
lihaoyi Sep 5, 2024
7fa79bb
.
lihaoyi Sep 5, 2024
48ea1cf
.
lihaoyi Sep 5, 2024
5c510a9
.
lihaoyi Sep 5, 2024
f9c8274
.
lihaoyi Sep 5, 2024
319055d
.
lihaoyi Sep 5, 2024
cf33fcb
.
lihaoyi Sep 5, 2024
e8642c3
.
lihaoyi Sep 5, 2024
cdc0d36
.
lihaoyi Sep 5, 2024
fa551c5
.
lihaoyi Sep 5, 2024
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 build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ object Deps {
val log4j2Core = ivy"org.apache.logging.log4j:log4j-core:2.23.1"
val osLib = ivy"com.lihaoyi::os-lib:0.10.5"
val pprint = ivy"com.lihaoyi::pprint:0.9.0"
val mainargs = ivy"com.lihaoyi::mainargs:0.7.2"
val mainargs = ivy"com.lihaoyi::mainargs:0.7.4"
val millModuledefsVersion = "0.11.0-M2"
val millModuledefsString = s"com.lihaoyi::mill-moduledefs:${millModuledefsVersion}"
val millModuledefs = ivy"${millModuledefsString}"
Expand Down
4 changes: 2 additions & 2 deletions example/depth/large/11-helper-files/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ object `package` extends RootModule with MyModule{
"MY_PROJECT_VERSION" -> versions.myProjectVersion,
)
}
///** See Also: util.sc */
///** See Also: foo/package */
///** See Also: util.mill */
///** See Also: foo/package.mill */
///** See Also: foo/versions.mill */


Expand Down
39 changes: 39 additions & 0 deletions example/depth/large/13-helper-files-mill-sc/build.mill.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package build
import mill._, scalalib._
import $file.foo.versions
import $file.util.MyModule
object `package` extends RootModule with MyModule{
def forkEnv = Map(
"MY_SCALA_VERSION" -> build.scalaVersion(),
"MY_PROJECT_VERSION" -> versions.myProjectVersion,
)
}
///** See Also: util.mill.sc */
///** See Also: foo/package.mill.sc */
///** See Also: foo/versions.mill.sc */


// Apart from having `package` files in subfolders to define modules, Mill
// also allows you to have helper code in any `*.mill` file in the same folder
// as your `build.mill` or a `package.mill`.
//
// Different helper scripts and ``build.mill``/``package`` files can all refer to
// each other using the `build` object, which marks the root object of your build.
// In this example:
//
// * `build.mill` can be referred to as simple `build`
// * `util.mill` can be referred to as simple `$file.util`
// * `foo/package` can be referred to as simple `build.foo`
// * `foo/versions.mill` can be referred to as simple `$file.foo.versions`

/** Usage

> ./mill run
Main Env build.util.myScalaVersion: 2.13.14
Main Env build.foo.versions.myProjectVersion: 0.0.1

> ./mill foo.run
Foo Env build.util.myScalaVersion: 2.13.14
Foo Env build.foo.versions.myProjectVersion: 0.0.1

*/
10 changes: 10 additions & 0 deletions example/depth/large/13-helper-files-mill-sc/foo/package.mill.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package build.foo
import mill._, scalalib._
import $file.util
import $file.foo.versions.myProjectVersion
object `package` extends RootModule with build_.util.MyModule {
def forkEnv = Map(
"MY_SCALA_VERSION" -> util.myScalaVersion,
"MY_PROJECT_VERSION" -> myProjectVersion
)
}
8 changes: 8 additions & 0 deletions example/depth/large/13-helper-files-mill-sc/foo/src/Foo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package foo

object Foo {
def main(args: Array[String]): Unit = {
println("Foo Env build.util.myScalaVersion: " + sys.env("MY_SCALA_VERSION"))
println("Foo Env build.foo.versions.myProjectVersion: " + sys.env("MY_PROJECT_VERSION"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package build.foo

def myProjectVersion = "0.0.1"
6 changes: 6 additions & 0 deletions example/depth/large/13-helper-files-mill-sc/src/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Main {
def main(args: Array[String]): Unit = {
println("Main Env build.util.myScalaVersion: " + sys.env("MY_SCALA_VERSION"))
println("Main Env build.foo.versions.myProjectVersion: " + sys.env("MY_PROJECT_VERSION"))
}
}
9 changes: 9 additions & 0 deletions example/depth/large/13-helper-files-mill-sc/util.mill.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package build

import mill._, scalalib._

def myScalaVersion = "2.13.14"

trait MyModule extends ScalaModule {
def scalaVersion = myScalaVersion
}
6 changes: 3 additions & 3 deletions main/client/src/mill/main/client/CodeGenConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public class CodeGenConstants {
/**
* The name of the root build file
*/
final public static String[] rootBuildFileNames = {"build.mill", "build.sc"};
final public static String[] rootBuildFileNames = {"build.mill", "build.mill.sc", "build.sc"};

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

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

/**
* The user-facing name for the root of the module tree.
Expand Down
2 changes: 1 addition & 1 deletion mill-build/src/ExampleParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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")
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 (newState, restOpt) = line match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LineNumberPlugin(val global: Global) extends Plugin {

object LineNumberPlugin {
def apply(g: Global)(unit: g.CompilationUnit): Unit = {
if (buildFileExtensions.exists(g.currentSource.file.hasExtension(_))) {
if (buildFileExtensions.exists(ex => g.currentSource.file.name.endsWith(s".$ex"))) {

val str = new String(g.currentSource.content)
val lines = str.linesWithSeparators.toVector
Expand Down
7 changes: 3 additions & 4 deletions runner/src/mill/runner/CodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ object CodeGen {
millTopLevelProjectRoot: os.Path
): Unit = {
for (scriptSource <- scriptSources) {
// pprint.log(scriptSource)
val scriptPath = scriptSource.path
val specialNames = (nestedBuildFileNames ++ rootBuildFileNames).toSet

val isBuildScript = specialNames(scriptPath.last)
val scriptFolderPath = scriptPath / os.up

if (scriptFolderPath == projectRoot && scriptPath.baseName == "package") {
if (scriptFolderPath == projectRoot && scriptPath.last.split('.').head == "package") {
throw Result.Failure(s"Mill ${scriptPath.last} files can only be in subfolders")
}

if (scriptFolderPath != projectRoot && scriptPath.baseName == "build") {
if (scriptFolderPath != projectRoot && scriptPath.last.split('.').head == "build") {
throw Result.Failure(s"Mill ${scriptPath.last} files can only be in the project root")
}

Expand Down Expand Up @@ -86,7 +85,7 @@ object CodeGen {
if (!isBuildScript) {
s"""$pkgLine
|$aliasImports
|object ${backtickWrap(scriptPath.baseName)} {
|object ${backtickWrap(scriptPath.last.split('.').head)} {
|$markerComment
|$scriptCode
|}""".stripMargin
Expand Down
13 changes: 7 additions & 6 deletions runner/src/mill/runner/FileImportGraph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ object FileImportGraph {
var millImport = false

def processScript(s: os.Path, useDummy: Boolean = false): Unit = {

val readFileEither = scala.util.Try {
val content = if (useDummy) "" else os.read(s)
val fileName = s.relativeTo(topLevelProjectRoot).toString
Expand All @@ -67,7 +66,7 @@ object FileImportGraph {
val expectedImportSegments = expectedImportSegments0.map(backtickWrap).mkString(".")
if (
// Legacy `.sc` files have their package build be optional
s.ext == "mill" &&
(s.last.endsWith(".mill") || s.last.endsWith(".mill.sc")) &&
expectedImportSegments != importSegments &&
// Root build.mill file has its `package build` be optional
!(importSegments == "" && rootBuildFileNames.contains(s.last))
Expand Down Expand Up @@ -137,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.ext == "sc") {
if (s.last.endsWith(".sc") && !s.last.endsWith(".mill.sc")) {
val nextPaths = mapping.map { case (lhs, rhs) =>
nextPathFor(s, rest.map(_._1) :+ lhs)
}
Expand Down Expand Up @@ -167,8 +166,10 @@ object FileImportGraph {
val useDummy = rootBuildFiles.isEmpty
val foundRootBuildFileName: String = rootBuildFiles.getOrElse(rootBuildFileNames.head)

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

val nestedBuildFileName = s"package.$buildFileExtension"

processScript(projectRoot / foundRootBuildFileName, useDummy)
val buildFiles = os
Expand All @@ -184,7 +185,7 @@ object FileImportGraph {

val adjacentScripts = (projectRoot +: buildFiles.map(_ / os.up))
.flatMap(os.list(_))
.filter(_.ext == buildFileExtension)
.filter(_.last.endsWith(s".$buildFileExtension"))

(buildFiles ++ adjacentScripts).foreach(processScript(_))

Expand Down
4 changes: 3 additions & 1 deletion scalalib/src/mill/scalalib/Lib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ object Lib {
root <- sources
if os.exists(root.path)
path <- (if (os.isDir(root.path)) os.walk(root.path) else Seq(root.path))
if os.isFile(path) && (extensions.exists(path.ext == _) && !isHiddenFile(path))
if os.isFile(path) && (extensions.exists(ex => path.last.endsWith(s".$ex")) && !isHiddenFile(
path
))
} yield path
}

Expand Down
4 changes: 3 additions & 1 deletion scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ trait ScalafmtModule extends JavaModule {
file <- {
if (os.isDir(pathRef.path)) {
os.walk(pathRef.path).filter(file =>
os.isFile(file) && (file.ext == "scala" || buildFileExtensions.contains(file.ext))
os.isFile(file) && (file.ext == "scala" || buildFileExtensions.exists(ex =>
file.last.endsWith(s".$ex")
))
)
} else {
Seq(pathRef.path)
Expand Down
Loading