Skip to content

Commit

Permalink
Allow users to pass a custom output dir on the command-line
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Sep 12, 2024
1 parent 5588448 commit cd73580
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 19 deletions.
7 changes: 6 additions & 1 deletion main/client/src/mill/main/client/OutFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ public class OutFiles {
/**
* Path of the Mill `out/` folder
*/
final public static String out = "out";
final public static String defaultOut = "out";

/**
* Path of the Mill `out/` folder for Mill server-related internal files
*/
final public static String serverOut = ".mill";

/**
* Path of the Mill "meta-build", used to compile the `build.sc` file so we can
Expand Down
4 changes: 2 additions & 2 deletions runner/client/src/mill/runner/client/MillClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public void initServer(String serverDir, boolean setJnaNoSys, Locks locks) throw
MillProcessLauncher.launchMillServer(serverDir, setJnaNoSys);
}
};
int exitCode = launcher.acquireLocksAndRun(OutFiles.out).exitCode;
int exitCode = launcher.acquireLocksAndRun(OutFiles.serverOut).exitCode;
if (exitCode == Util.ExitServerCodeWhenVersionMismatch()) {
exitCode = launcher.acquireLocksAndRun(OutFiles.out).exitCode;
exitCode = launcher.acquireLocksAndRun(OutFiles.serverOut).exitCode;
}
System.exit(exitCode);
} catch (ServerCouldNotBeStarted e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static int launchMillNoServer(String[] args) throws Exception {
final String sig = String.format("%08x", UUID.randomUUID().hashCode());

boolean interrupted = false;
final String sandbox = out + "/" + millNoServer + "-" + sig;
final String sandbox = serverOut + "/" + millNoServer + "-" + sig;
try {
return configureRunMillProcess(builder, sandbox).waitFor();

Expand Down
12 changes: 9 additions & 3 deletions runner/src/mill/runner/CodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ object CodeGen {
allScriptCode: Map[os.Path, String],
targetDest: os.Path,
enclosingClasspath: Seq[os.Path],
millTopLevelProjectRoot: os.Path
millTopLevelProjectRoot: os.Path,
output: os.Path
): Unit = {
for (scriptSource <- scriptSources) {
val scriptPath = scriptSource.path
Expand Down Expand Up @@ -94,6 +95,7 @@ object CodeGen {
projectRoot,
enclosingClasspath,
millTopLevelProjectRoot,
output,
scriptPath,
scriptFolderPath,
childAliases,
Expand All @@ -112,6 +114,7 @@ object CodeGen {
projectRoot: os.Path,
enclosingClasspath: Seq[os.Path],
millTopLevelProjectRoot: os.Path,
output: os.Path,
scriptPath: os.Path,
scriptFolderPath: os.Path,
childAliases: String,
Expand All @@ -126,7 +129,8 @@ object CodeGen {
segments,
scriptFolderPath,
enclosingClasspath,
millTopLevelProjectRoot
millTopLevelProjectRoot,
output
)

val instrument = new ObjectDataInstrument(scriptCode)
Expand Down Expand Up @@ -182,13 +186,15 @@ object CodeGen {
segments: Seq[String],
scriptFolderPath: os.Path,
enclosingClasspath: Seq[os.Path],
millTopLevelProjectRoot: os.Path
millTopLevelProjectRoot: os.Path,
output: os.Path
): String = {
s"""import _root_.mill.runner.MillBuildRootModule
|@_root_.scala.annotation.nowarn
|object MillMiscInfo extends MillBuildRootModule.MillMiscInfo(
| ${enclosingClasspath.map(p => literalize(p.toString))},
| ${literalize(scriptFolderPath.toString)},
| ${literalize(output.toString)},
| ${literalize(millTopLevelProjectRoot.toString)},
| _root_.scala.Seq(${segments.map(pprint.Util.literalize(_)).mkString(", ")})
|)
Expand Down
8 changes: 6 additions & 2 deletions runner/src/mill/runner/FileImportGraph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ object FileImportGraph {
* starting from `build.mill`, collecting the information necessary to
* instantiate the [[MillRootModule]]
*/
def parseBuildFiles(topLevelProjectRoot: os.Path, projectRoot: os.Path): FileImportGraph = {
def parseBuildFiles(
topLevelProjectRoot: os.Path,
projectRoot: os.Path,
output: os.Path
): FileImportGraph = {
val seenScripts = mutable.Map.empty[os.Path, String]
val seenIvy = mutable.Set.empty[String]
val seenRepo = mutable.ListBuffer.empty[(String, os.Path)]
Expand Down Expand Up @@ -185,7 +189,7 @@ object FileImportGraph {
projectRoot,
followLinks = true,
skip = p =>
p == projectRoot / out ||
p == output ||
p == projectRoot / millBuild ||
(os.isDir(p) && !os.exists(p / nestedBuildFileName))
)
Expand Down
19 changes: 11 additions & 8 deletions runner/src/mill/runner/MillBuildBootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import mill.eval.Evaluator
import mill.main.RunScript
import mill.resolve.SelectMode
import mill.define.{BaseModule, Discover, Segments}
import mill.main.client.OutFiles._
import mill.main.client.OutFiles.{millBuild, millRunnerState}

import java.net.URLClassLoader

Expand All @@ -30,6 +30,7 @@ import java.net.URLClassLoader
@internal
class MillBuildBootstrap(
projectRoot: os.Path,
output: os.Path,
home: os.Path,
keepGoing: Boolean,
imports: Seq[String],
Expand All @@ -46,15 +47,15 @@ class MillBuildBootstrap(
) {
import MillBuildBootstrap._

val millBootClasspath: Seq[os.Path] = prepareMillBootClasspath(projectRoot / out)
val millBootClasspath: Seq[os.Path] = prepareMillBootClasspath(output)
val millBootClasspathPathRefs: Seq[PathRef] = millBootClasspath.map(PathRef(_, quick = true))

def evaluate(): Watching.Result[RunnerState] = CliImports.withValue(imports) {
val runnerState = evaluateRec(0)

for ((frame, depth) <- runnerState.frames.zipWithIndex) {
os.write.over(
recOut(projectRoot, depth) / millRunnerState,
recOut(output, depth) / millRunnerState,
upickle.default.write(frame.loggedData, indent = 4),
createFolders = true
)
Expand Down Expand Up @@ -102,7 +103,8 @@ class MillBuildBootstrap(
} else {
val parsedScriptFiles = FileImportGraph.parseBuildFiles(
projectRoot,
recRoot(projectRoot, depth) / os.up
recRoot(projectRoot, depth) / os.up,
output
)

if (parsedScriptFiles.millImport) evaluateRec(depth + 1)
Expand All @@ -111,6 +113,7 @@ class MillBuildBootstrap(
new MillBuildRootModule.BootstrapModule(
projectRoot,
recRoot(projectRoot, depth),
output,
millBootClasspath
)(
mill.main.RootModule.Info(
Expand Down Expand Up @@ -340,8 +343,8 @@ class MillBuildBootstrap(
mill.eval.EvaluatorImpl(
home,
projectRoot,
recOut(projectRoot, depth),
recOut(projectRoot, depth),
recOut(output, depth),
recOut(output, depth),
rootModule,
PrefixLogger(logger, "", tickerContext = bootLogPrefix),
classLoaderSigHash = millClassloaderSigHash,
Expand Down Expand Up @@ -422,8 +425,8 @@ object MillBuildBootstrap {
projectRoot / Seq.fill(depth)(millBuild)
}

def recOut(projectRoot: os.Path, depth: Int): os.Path = {
projectRoot / out / Seq.fill(depth)(millBuild)
def recOut(output: os.Path, depth: Int): os.Path = {
output / Seq.fill(depth)(millBuild)
}

}
11 changes: 9 additions & 2 deletions runner/src/mill/runner/MillBuildRootModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ abstract class MillBuildRootModule()(implicit
parsed.seenScripts,
T.dest,
millBuildRootModuleInfo.enclosingClasspath,
millBuildRootModuleInfo.topLevelProjectRoot
millBuildRootModuleInfo.topLevelProjectRoot,
millBuildRootModuleInfo.output
)
Result.Success(Seq(PathRef(T.dest)))
}
Expand Down Expand Up @@ -264,12 +265,14 @@ object MillBuildRootModule {
class BootstrapModule(
topLevelProjectRoot0: os.Path,
projectRoot: os.Path,
output: os.Path,
enclosingClasspath: Seq[os.Path]
)(implicit baseModuleInfo: RootModule.Info) extends MillBuildRootModule()(
implicitly,
MillBuildRootModule.Info(
enclosingClasspath,
projectRoot,
output,
topLevelProjectRoot0
)
) {
Expand All @@ -280,25 +283,29 @@ object MillBuildRootModule {
case class Info(
enclosingClasspath: Seq[os.Path],
projectRoot: os.Path,
output: os.Path,
topLevelProjectRoot: os.Path
)

def parseBuildFiles(millBuildRootModuleInfo: MillBuildRootModule.Info): FileImportGraph = {
FileImportGraph.parseBuildFiles(
millBuildRootModuleInfo.topLevelProjectRoot,
millBuildRootModuleInfo.projectRoot / os.up
millBuildRootModuleInfo.projectRoot / os.up,
millBuildRootModuleInfo.output
)
}

class MillMiscInfo(
enclosingClasspath: Seq[String],
projectRoot: String,
output: String,
topLevelProjectRoot: String,
segments: Seq[String]
) {
implicit lazy val millBuildRootModuleInfo: MillBuildRootModule.Info = MillBuildRootModule.Info(
enclosingClasspath.map(os.Path(_)),
os.Path(projectRoot),
os.Path(output),
os.Path(topLevelProjectRoot)
)
implicit lazy val millBaseModuleInfo: RootModule.Info = RootModule.Info(
Expand Down
65 changes: 65 additions & 0 deletions runner/src/mill/runner/MillCliConfig.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mill.runner

import mainargs.{Flag, Leftover, arg}
import mill.api.WorkspaceRoot
import mill.main.client.OutFiles

class MillCliConfig private (
@arg(
Expand All @@ -10,6 +12,12 @@ class MillCliConfig private (
where it looks for config and caches."""
)
val home: os.Path,
@arg(
short = 'o',
doc =
"""(internal) The directory to write Mill tasks output to."""
)
val output: os.Path,
// We need to keep it, otherwise, a given --repl would be silently parsed as target and result in misleading error messages.
// Instead we fail programmatically when this flag is set.
@deprecated("No longer supported.", "Mill 0.11.0-M8")
Expand Down Expand Up @@ -164,6 +172,7 @@ object MillCliConfig {
*/
def apply(
home: os.Path = mill.api.Ctx.defaultHome,
output: os.Path = defaultOutput,
@deprecated("No longer supported.", "Mill 0.11.0-M8")
repl: Flag = Flag(),
noServer: Flag = Flag(),
Expand All @@ -188,6 +197,57 @@ object MillCliConfig {
allowPositionalCommandArgs: Flag = Flag()
): MillCliConfig = new MillCliConfig(
home = home,
output = output,
repl = repl,
noServer = noServer,
bsp = bsp,
showVersion = showVersion,
ringBell = ringBell,
disableTicker = disableTicker,
enableTicker = enableTicker,
debugLog = debugLog,
keepGoing = keepGoing,
extraSystemProperties = extraSystemProperties,
threadCountRaw = threadCountRaw,
imports = imports,
interactive = interactive,
help = help,
watch = watch,
silent = silent,
leftoverArgs = leftoverArgs,
color = color,
disableCallgraphInvalidation,
metaLevel = metaLevel,
allowPositionalCommandArgs = allowPositionalCommandArgs
)
@deprecated("Bin-compat shim", "Mill after 0.12.0-RC1")
def apply(
home: os.Path,
@deprecated("No longer supported.", "Mill 0.11.0-M8")
repl: Flag,
noServer: Flag,
bsp: Flag,
showVersion: Flag,
ringBell: Flag,
disableTicker: Flag,
enableTicker: Option[Boolean],
debugLog: Flag,
keepGoing: Flag,
extraSystemProperties: Map[String, String],
threadCountRaw: Option[Int],
imports: Seq[String],
interactive: Flag,
help: Flag,
watch: Flag,
silent: Flag,
leftoverArgs: Leftover[String],
color: Option[Boolean],
disableCallgraphInvalidation: Flag,
metaLevel: Option[Int],
allowPositionalCommandArgs: Flag
): MillCliConfig = new MillCliConfig(
home = home,
output = defaultOutput,
repl = repl,
noServer = noServer,
bsp = bsp,
Expand Down Expand Up @@ -236,6 +296,7 @@ object MillCliConfig {
metaLevel: Option[Int]
): MillCliConfig = new MillCliConfig(
home = home,
output = defaultOutput,
repl = repl,
noServer = noServer,
bsp = bsp,
Expand Down Expand Up @@ -285,6 +346,7 @@ object MillCliConfig {
predefFile: Option[os.Path]
): MillCliConfig = apply(
home,
output = defaultOutput,
repl,
noServer,
bsp,
Expand All @@ -304,6 +366,9 @@ object MillCliConfig {
leftoverArgs,
color
)

private def defaultOutput: os.Path =
os.Path(OutFiles.defaultOut, WorkspaceRoot.workspaceRoot)
}

import mainargs.ParserForClass
Expand Down
2 changes: 2 additions & 0 deletions runner/src/mill/runner/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import mill.java9rtexport.Export
import mill.api.{MillException, SystemStreams, WorkspaceRoot, internal}
import mill.bsp.{BspContext, BspServerResult}
import mill.main.BuildInfo
import mill.main.client.OutFiles
import mill.util.PrintLogger

import java.lang.reflect.InvocationTargetException
Expand Down Expand Up @@ -224,6 +225,7 @@ object MillMain {

new MillBuildBootstrap(
projectRoot = WorkspaceRoot.workspaceRoot,
output = config.output,
home = config.home,
keepGoing = config.keepGoing.value,
imports = config.imports,
Expand Down

0 comments on commit cd73580

Please sign in to comment.