From d01410e0f0ffed78d34553e1f1de5f5ca9a7afb3 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 17:20:48 +0800 Subject: [PATCH 01/10] naive check --- core/define/src/mill/define/internal/ResolveChecker.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/define/src/mill/define/internal/ResolveChecker.scala b/core/define/src/mill/define/internal/ResolveChecker.scala index 27775fbec0c1..1472717cec89 100644 --- a/core/define/src/mill/define/internal/ResolveChecker.scala +++ b/core/define/src/mill/define/internal/ResolveChecker.scala @@ -1,7 +1,10 @@ package mill.define.internal class ResolveChecker(workspace: os.Path) extends os.Checker { - def onRead(path: os.ReadablePath): Unit = () + def onRead(path: os.ReadablePath): Unit = path match { + case path: os.Path => sys.error(s"Reading from ${path.relativeTo(workspace)} not allowed during resolution phase") + case _ => + } def onWrite(path: os.Path): Unit = { sys.error(s"Writing to ${path.relativeTo(workspace)} not allowed during resolution phase") From 93de06e7b6c1c747f4ca3f536b7b8621419acdfc Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 17:31:23 +0800 Subject: [PATCH 02/10] restrict filesystem reads during resolution phase --- .../src/mill/define/internal/ResolveChecker.scala | 8 +++++--- .../failure/os-checker/src/OsCheckerTests.scala | 10 +++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/define/src/mill/define/internal/ResolveChecker.scala b/core/define/src/mill/define/internal/ResolveChecker.scala index 1472717cec89..534dd0e5bbe5 100644 --- a/core/define/src/mill/define/internal/ResolveChecker.scala +++ b/core/define/src/mill/define/internal/ResolveChecker.scala @@ -1,9 +1,11 @@ package mill.define.internal class ResolveChecker(workspace: os.Path) extends os.Checker { - def onRead(path: os.ReadablePath): Unit = path match { - case path: os.Path => sys.error(s"Reading from ${path.relativeTo(workspace)} not allowed during resolution phase") - case _ => + def onRead(path: os.ReadablePath): Unit = { + path match { + case path: os.Path => sys.error(s"Reading from ${path.relativeTo(workspace)} not allowed during resolution phase") + case _ => + } } def onWrite(path: os.Path): Unit = { diff --git a/integration/failure/os-checker/src/OsCheckerTests.scala b/integration/failure/os-checker/src/OsCheckerTests.scala index c2de6b8cf815..958a8f61ad82 100644 --- a/integration/failure/os-checker/src/OsCheckerTests.scala +++ b/integration/failure/os-checker/src/OsCheckerTests.scala @@ -10,7 +10,6 @@ object OsCheckerTests extends UtestIntegrationTestSuite { import tester._ val res = tester.eval("foo.bar") - val sep = if (mill.constants.Util.isWindows) "\\" else "/" assert(res.isSuccess == false) assert(res.err.contains( s"Writing to foo not allowed during resolution phase" @@ -31,6 +30,15 @@ object OsCheckerTests extends UtestIntegrationTestSuite { s"Writing to not allowed during resolution phase" )) + tester.modifyFile(workspacePath / "build.mill", _.replace("if (true)", "if (false)")) + tester.modifyFile(workspacePath / "build.mill", _ + "\nprintln(os.read(mill.define.WorkspaceRoot.workspaceRoot / \"build.mill\"))") + val res4 = tester.eval("baz") + + assert(res4.isSuccess == false) + assert(res4.err.contains( + s"Reading from build.mill not allowed during resolution phase" + )) + } } } From 85170d1f4ed581e580a22e94c34c8328ddfccd4c Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 17:34:09 +0800 Subject: [PATCH 03/10] cleanup fmt --- core/constants/src/mill/constants/Util.java | 1 - core/define/src/mill/define/internal/ResolveChecker.scala | 3 ++- core/util/src/mill/util/Jvm.scala | 1 - integration/failure/os-checker/src/OsCheckerTests.scala | 5 ++++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/constants/src/mill/constants/Util.java b/core/constants/src/mill/constants/Util.java index 353fdf58f860..f4ad202a81e0 100644 --- a/core/constants/src/mill/constants/Util.java +++ b/core/constants/src/mill/constants/Util.java @@ -124,7 +124,6 @@ public static String interpolateEnvVars( matcher.appendReplacement(result, "\\$"); } else { String envVarValue; - mill.constants.DebugLog.println("MATCH " + match); envVarValue = env.containsKey(match) ? env.get(match) : onMissing.apply(match); matcher.appendReplacement(result, envVarValue); } diff --git a/core/define/src/mill/define/internal/ResolveChecker.scala b/core/define/src/mill/define/internal/ResolveChecker.scala index 534dd0e5bbe5..e31c9c8e1d5f 100644 --- a/core/define/src/mill/define/internal/ResolveChecker.scala +++ b/core/define/src/mill/define/internal/ResolveChecker.scala @@ -3,7 +3,8 @@ package mill.define.internal class ResolveChecker(workspace: os.Path) extends os.Checker { def onRead(path: os.ReadablePath): Unit = { path match { - case path: os.Path => sys.error(s"Reading from ${path.relativeTo(workspace)} not allowed during resolution phase") + case path: os.Path => + sys.error(s"Reading from ${path.relativeTo(workspace)} not allowed during resolution phase") case _ => } } diff --git a/core/util/src/mill/util/Jvm.scala b/core/util/src/mill/util/Jvm.scala index 404bd25d724d..822877893559 100644 --- a/core/util/src/mill/util/Jvm.scala +++ b/core/util/src/mill/util/Jvm.scala @@ -682,7 +682,6 @@ object Jvm { case cp => cp.split(';').map { s => val url = os.Path(s).toNIO.toUri.toURL - mill.constants.DebugLog.println("MILL_LOCAL_TEST_OVERRIDE_CLASSPATH " + url) new java.net.URLClassLoader(Array(url)) }.toList } diff --git a/integration/failure/os-checker/src/OsCheckerTests.scala b/integration/failure/os-checker/src/OsCheckerTests.scala index 958a8f61ad82..7bf7ec8da23a 100644 --- a/integration/failure/os-checker/src/OsCheckerTests.scala +++ b/integration/failure/os-checker/src/OsCheckerTests.scala @@ -31,7 +31,10 @@ object OsCheckerTests extends UtestIntegrationTestSuite { )) tester.modifyFile(workspacePath / "build.mill", _.replace("if (true)", "if (false)")) - tester.modifyFile(workspacePath / "build.mill", _ + "\nprintln(os.read(mill.define.WorkspaceRoot.workspaceRoot / \"build.mill\"))") + tester.modifyFile( + workspacePath / "build.mill", + _ + "\nprintln(os.read(mill.define.WorkspaceRoot.workspaceRoot / \"build.mill\"))" + ) val res4 = tester.eval("baz") assert(res4.isSuccess == false) From a03ea68ed5d7005f614e30bd1e9a98c16d7de92b Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 18:55:14 +0800 Subject: [PATCH 04/10] whitelist watchValue calls --- .../watch-source-input/resources/build.mill | 9 +++++---- libs/main/src/mill/main/MainModule.scala | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/integration/invalidation/watch-source-input/resources/build.mill b/integration/invalidation/watch-source-input/resources/build.mill index 757a69a945c7..c9dca024a6dc 100644 --- a/integration/invalidation/watch-source-input/resources/build.mill +++ b/integration/invalidation/watch-source-input/resources/build.mill @@ -43,8 +43,9 @@ def writeCompletionMarker(name: String) = { } writeCompletionMarker("initialized") - -if (os.read(moduleDir / "watchValue.txt").contains("exit")) { - Thread.sleep(1000) - System.exit(0) +os.checker.withValue(os.Checker.Nop) { + if (os.read(moduleDir / "watchValue.txt").contains("exit")) { + Thread.sleep(1000) + System.exit(0) + } } diff --git a/libs/main/src/mill/main/MainModule.scala b/libs/main/src/mill/main/MainModule.scala index b9db102b23c9..9bad10aeee26 100644 --- a/libs/main/src/mill/main/MainModule.scala +++ b/libs/main/src/mill/main/MainModule.scala @@ -26,14 +26,16 @@ trait MainModule extends BaseModule with MainModuleApi { protected[mill] val evalWatchedValues: mutable.Buffer[Watchable] = mutable.Buffer.empty[Watchable] object interp { def watchValue[T](v0: => T)(implicit fn: sourcecode.FileName, ln: sourcecode.Line): T = { - val v = v0 - val watchable = Watchable.Value( - () => v0.hashCode, - v.hashCode(), - fn.value + ":" + ln.value - ) - watchedValues.append(watchable) - v + os.checker.withValue(os.Checker.Nop) { + val v = v0 + val watchable = Watchable.Value( + () => v0.hashCode, + v.hashCode(), + fn.value + ":" + ln.value + ) + watchedValues.append(watchable) + v + } } def watch(p: os.Path): os.Path = { From 2e5c5671f3eae778e3eec1e907ef24ca13e16039 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 19:57:57 +0800 Subject: [PATCH 05/10] . --- build.mill | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.mill b/build.mill index fc91c5961c84..c673f1c76b43 100644 --- a/build.mill +++ b/build.mill @@ -159,7 +159,7 @@ object Deps { val junitInterface = mvn"com.github.sbt:junit-interface:0.13.3" val commonsIo = mvn"commons-io:commons-io:2.18.0" val log4j2Core = mvn"org.apache.logging.log4j:log4j-core:2.24.3" - val osLib = mvn"com.lihaoyi::os-lib:0.11.5-M2" + val osLib = mvn"com.lihaoyi::os-lib:0.11.5-M6" val pprint = mvn"com.lihaoyi::pprint:0.9.0" val mainargs = mvn"com.lihaoyi::mainargs:0.7.6" val millModuledefsVersion = "0.11.3-M5" From e6d7c8977f345d89de7a1457edace3ef63abd9d9 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 20:11:45 +0800 Subject: [PATCH 06/10] . --- runner/meta/src/mill/runner/meta/MillBuildRootModule.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runner/meta/src/mill/runner/meta/MillBuildRootModule.scala b/runner/meta/src/mill/runner/meta/MillBuildRootModule.scala index 32a90eaca9a7..22b384c3da5c 100644 --- a/runner/meta/src/mill/runner/meta/MillBuildRootModule.scala +++ b/runner/meta/src/mill/runner/meta/MillBuildRootModule.scala @@ -52,7 +52,9 @@ class MillBuildRootModule()(implicit def parseBuildFiles: T[FileImportGraph] = Task { scriptSources() - MillBuildRootModule.parseBuildFiles(compilerWorker(), rootModuleInfo) + os.checker.withValue(os.Checker.Nop) { + MillBuildRootModule.parseBuildFiles(compilerWorker(), rootModuleInfo) + } } private[runner] def compilerWorker: Worker[ScalaCompilerWorkerApi] = Task.Worker { From 272efcd6117704fceebffe443c158bfc2539fe95 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 20:30:55 +0800 Subject: [PATCH 07/10] fixes --- contrib/jmh/src/mill/contrib/jmh/JmhModule.scala | 6 +++--- .../meta/src/mill/runner/meta/MillBuildRootModule.scala | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/contrib/jmh/src/mill/contrib/jmh/JmhModule.scala b/contrib/jmh/src/mill/contrib/jmh/JmhModule.scala index 15ec3cc0d794..47ab47d0cd5d 100644 --- a/contrib/jmh/src/mill/contrib/jmh/JmhModule.scala +++ b/contrib/jmh/src/mill/contrib/jmh/JmhModule.scala @@ -42,7 +42,7 @@ trait JmhModule extends JavaModule { Jvm.callProcess( mainClass = "org.openjdk.jmh.Main", classPath = (runClasspath() ++ generatorDeps()).map(_.path) ++ - Seq(compileGeneratedSources().path, resources), + Seq(compileGeneratedSources().path, resources.path), mainArgs = args, cwd = Task.ctx().dest, javaHome = jvmWorker().javaHome().map(_.path), @@ -58,7 +58,7 @@ trait JmhModule extends JavaModule { Task { val dest = Task.ctx().dest val (sourcesDir, _) = generateBenchmarkSources() - val sources = os.walk(sourcesDir).filter(os.isFile) + val sources = os.walk(sourcesDir.path).filter(os.isFile) os.proc( Jvm.jdkTool("javac"), @@ -101,7 +101,7 @@ trait JmhModule extends JavaModule { stdout = os.Inherit ) - (sourcesDir, resourcesDir) + (PathRef(sourcesDir), PathRef(resourcesDir)) } def generatorDeps = Task { diff --git a/runner/meta/src/mill/runner/meta/MillBuildRootModule.scala b/runner/meta/src/mill/runner/meta/MillBuildRootModule.scala index 22b384c3da5c..10d51c475d06 100644 --- a/runner/meta/src/mill/runner/meta/MillBuildRootModule.scala +++ b/runner/meta/src/mill/runner/meta/MillBuildRootModule.scala @@ -38,9 +38,11 @@ class MillBuildRootModule()(implicit override def scalaVersion: T[String] = BuildInfo.scalaVersion - val scriptSourcesPaths = FileImportGraph - .walkBuildFiles(rootModuleInfo.projectRoot / os.up, rootModuleInfo.output) - .sorted + val scriptSourcesPaths = os.checker.withValue(os.Checker.Nop) { + FileImportGraph + .walkBuildFiles(rootModuleInfo.projectRoot / os.up, rootModuleInfo.output) + .sorted + } /** * All script files (that will get wrapped later) From 48e430b04c3ac01ce7f5b1222513c0b5ba591eb7 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 21:06:40 +0800 Subject: [PATCH 08/10] whitelist javascriptlib valuation --- .../mill/javascriptlib/TypeScriptModule.scala | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libs/javascriptlib/src/mill/javascriptlib/TypeScriptModule.scala b/libs/javascriptlib/src/mill/javascriptlib/TypeScriptModule.scala index e724a842f6f2..f1e3f7ed6e6f 100644 --- a/libs/javascriptlib/src/mill/javascriptlib/TypeScriptModule.scala +++ b/libs/javascriptlib/src/mill/javascriptlib/TypeScriptModule.scala @@ -152,21 +152,21 @@ trait TypeScriptModule extends Module { outer => if (!os.exists(T.dest)) os.makeDir.all(T.dest) // Copy everything except "build.mill" and the "/out" directory from Task.workspace - os.walk(moduleDir, skip = _.last == "out") - .filter(_.last != "build.mill") - .filter(_.last != "mill") - .filter(_.last != "package.json") - .filter(_.last != "package-lock.json") - .filter(_.last != "tsconfig.json") - .foreach { path => - val relativePath = path.relativeTo(moduleDir) - val destination = T.dest / relativePath - - if (os.isDir(path)) os.makeDir.all(destination) - else os.checker.withValue(os.Checker.Nop) { - os.copy.over(path, destination) + os.checker.withValue(os.Checker.Nop) { + os.walk(moduleDir, skip = _.last == "out") + .filter(_.last != "build.mill") + .filter(_.last != "mill") + .filter(_.last != "package.json") + .filter(_.last != "package-lock.json") + .filter(_.last != "tsconfig.json") + .foreach { path => + val relativePath = path.relativeTo(moduleDir) + val destination = T.dest / relativePath + + if (os.isDir(path)) os.makeDir.all(destination) + else os.copy.over(path, destination) } - } + } object IsSrcDirectory { def unapply(path: Path): Option[Path] = From d2f0ab8a229ecaa93f5bb1185d8eb5829391bd54 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 21:25:11 +0800 Subject: [PATCH 09/10] fixes --- core/util/src/mill/util/Jvm.scala | 8 +++++--- .../resources/extended/idea/mill_modules/mill-build.iml | 3 ++- .../extended/idea/mill_modules/mill-build.mill-build.iml | 3 ++- .../resources/hello-idea/idea/mill_modules/mill-build.iml | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/util/src/mill/util/Jvm.scala b/core/util/src/mill/util/Jvm.scala index 822877893559..81395a28594d 100644 --- a/core/util/src/mill/util/Jvm.scala +++ b/core/util/src/mill/util/Jvm.scala @@ -576,9 +576,11 @@ object Jvm { artifactTypes, resolutionParams ).map { res => - res.files - .map(os.Path(_)) - .map(PathRef(_, quick = true)) + os.checker.withValue(os.Checker.Nop) { + res.files + .map(os.Path(_)) + .map(PathRef(_, quick = true)) + } } def jvmIndex( diff --git a/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml b/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml index e6021df5fe0e..65d83e2eb69d 100644 --- a/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml +++ b/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml @@ -85,7 +85,8 @@ - + + diff --git a/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml b/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml index 8635cacbc023..08dee7c42acb 100644 --- a/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml +++ b/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml @@ -86,7 +86,8 @@ - + + diff --git a/integration/ide/gen-idea/resources/hello-idea/idea/mill_modules/mill-build.iml b/integration/ide/gen-idea/resources/hello-idea/idea/mill_modules/mill-build.iml index fa22630ee139..e33a60962aaa 100644 --- a/integration/ide/gen-idea/resources/hello-idea/idea/mill_modules/mill-build.iml +++ b/integration/ide/gen-idea/resources/hello-idea/idea/mill_modules/mill-build.iml @@ -81,7 +81,8 @@ - + + From 2170a691457b154aa802703ca7d7a84ad86dbf92 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 May 2025 22:08:38 +0800 Subject: [PATCH 10/10] downgrade os-lib --- build.mill | 2 +- .../resources/extended/idea/mill_modules/mill-build.iml | 3 +-- .../extended/idea/mill_modules/mill-build.mill-build.iml | 3 +-- .../resources/hello-idea/idea/mill_modules/mill-build.iml | 3 +-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/build.mill b/build.mill index c673f1c76b43..fc91c5961c84 100644 --- a/build.mill +++ b/build.mill @@ -159,7 +159,7 @@ object Deps { val junitInterface = mvn"com.github.sbt:junit-interface:0.13.3" val commonsIo = mvn"commons-io:commons-io:2.18.0" val log4j2Core = mvn"org.apache.logging.log4j:log4j-core:2.24.3" - val osLib = mvn"com.lihaoyi::os-lib:0.11.5-M6" + val osLib = mvn"com.lihaoyi::os-lib:0.11.5-M2" val pprint = mvn"com.lihaoyi::pprint:0.9.0" val mainargs = mvn"com.lihaoyi::mainargs:0.7.6" val millModuledefsVersion = "0.11.3-M5" diff --git a/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml b/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml index 65d83e2eb69d..e6021df5fe0e 100644 --- a/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml +++ b/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml @@ -85,8 +85,7 @@ - - + diff --git a/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml b/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml index 08dee7c42acb..8635cacbc023 100644 --- a/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml +++ b/integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml @@ -86,8 +86,7 @@ - - + diff --git a/integration/ide/gen-idea/resources/hello-idea/idea/mill_modules/mill-build.iml b/integration/ide/gen-idea/resources/hello-idea/idea/mill_modules/mill-build.iml index e33a60962aaa..fa22630ee139 100644 --- a/integration/ide/gen-idea/resources/hello-idea/idea/mill_modules/mill-build.iml +++ b/integration/ide/gen-idea/resources/hello-idea/idea/mill_modules/mill-build.iml @@ -81,8 +81,7 @@ - - +