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

WIP: Native client #4057

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
package mill.main.client;
package mill.main.client

/**
* Constants used for code generation in Mill builds.
*/
object CodeGenConstants {

public class CodeGenConstants {
/**
* Global package prefix for Mill builds. Cannot be `build` because
* it would conflict with the name of the `lazy val build ` object
* it would conflict with the name of the `lazy val build` object
* we import to work around the need for the `.package` suffix, so
* we add an `_` and call it `build_`
*/
public static final String globalPackagePrefix = "build_";
val globalPackagePrefix: String = "build_"

/**
* What the wrapper objects are called. Not `package` because we don't
* want them to be `package objects` due to weird edge case behavior,
* even though we want them to look like package objects to users and IDEs,
* so we add an `_` and call it `package_`
*/
public static final String wrapperObjectName = "package_";
val wrapperObjectName: String = "package_"

/**
* The name of the root build file
*/
public static final String[] rootBuildFileNames = {"build.mill", "build.mill.scala", "build.sc"};
val rootBuildFileNames: Array[String] = Array("build.mill", "build.mill.scala", "build.sc")

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

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

/**
* The user-facing name for the root of the module tree.
*/
public static final String rootModuleAlias = "build";
val rootModuleAlias: String = "build"
}
21 changes: 0 additions & 21 deletions main/client/src/mill/main/client/DebugLog.java

This file was deleted.

21 changes: 21 additions & 0 deletions main/client/src/mill/main/client/DebugLog.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mill.main.client

import java.nio.file.{Files, Path, Paths, StandardOpenOption}
import java.io.IOException

/**
* Used to add `println`s in scenarios where you can't figure out where on earth
* your stdout/stderr/logs are going, and so we just dump them in a file in your
* home folder so you can find them
*/
object DebugLog {
def println(s: String): Unit = synchronized {
val path: Path = Paths.get(System.getProperty("user.home"), "mill-debug-log.txt")
try {
if (!Files.exists(path)) Files.createFile(path)
Files.writeString(path, s + "\n", StandardOpenOption.APPEND)
} catch {
case e: IOException => throw new RuntimeException(e)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package mill.main.client;
package mill.main.client

/**
* Central place containing all the environment variables that Mill uses
*/
public class EnvVars {
object EnvVars {
// USER FACING ENVIRONMENT VARIABLES

/**
* Available in test modules for users to find the test resource folder on disk
* in a convenient fashion. If multiple resource folders are provided on the classpath,
* they are provided as a comma-separated list
*/
public static final String MILL_TEST_RESOURCE_DIR = "MILL_TEST_RESOURCE_DIR";
val MILL_TEST_RESOURCE_DIR: String = "MILL_TEST_RESOURCE_DIR"

/**
* How long the Mill background server should run before timing out from inactivity
*/
public static final String MILL_SERVER_TIMEOUT_MILLIS = "MILL_SERVER_TIMEOUT_MILLIS";
val MILL_SERVER_TIMEOUT_MILLIS: String = "MILL_SERVER_TIMEOUT_MILLIS"

public static final String MILL_JVM_OPTS_PATH = "MILL_JVM_OPTS_PATH";
public static final String MILL_OPTS_PATH = "MILL_OPTS_PATH";
val MILL_JVM_OPTS_PATH: String = "MILL_JVM_OPTS_PATH"
val MILL_OPTS_PATH: String = "MILL_OPTS_PATH"

/**
* Output directory where Mill workers' state and Mill tasks output should be
* written to
*/
public static final String MILL_OUTPUT_DIR = "MILL_OUTPUT_DIR";
val MILL_OUTPUT_DIR: String = "MILL_OUTPUT_DIR"

// INTERNAL ENVIRONMENT VARIABLES
/**
Expand All @@ -35,17 +35,17 @@ public class EnvVars {
* Also, available in test modules for users to find the root folder of the
* mill project on disk. Not intended for common usage, but sometimes necessary.
*/
public static final String MILL_WORKSPACE_ROOT = "MILL_WORKSPACE_ROOT";
val MILL_WORKSPACE_ROOT: String = "MILL_WORKSPACE_ROOT"

/**
* Used to indicate to Mill that it is running as part of the Mill test suite,
* e.g. to turn on additional testing/debug/log-related code
*/
public static final String MILL_TEST_SUITE = "MILL_TEST_SUITE";
val MILL_TEST_SUITE: String = "MILL_TEST_SUITE"

/**
* Used to indicate to the Mill test suite which libraries should be resolved from
* the local disk and not from Maven Central
*/
public static final String MILL_BUILD_LIBRARIES = "MILL_BUILD_LIBRARIES";
val MILL_BUILD_LIBRARIES: String = "MILL_BUILD_LIBRARIES"
}
105 changes: 0 additions & 105 deletions main/client/src/mill/main/client/FileToStreamTailer.java

This file was deleted.

85 changes: 85 additions & 0 deletions main/client/src/mill/main/client/FileToStreamTailer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package mill.main.client

import java.io.{BufferedReader, File, FileReader, FileNotFoundException, IOException, PrintStream}
import scala.util.{Failure, Success, Try}

class FileToStreamTailer(file: File, stream: PrintStream, intervalMsec: Int) extends Thread("Tail")
with AutoCloseable {

private val interval = intervalMsec
@volatile private var keepReading = true
@volatile private var flushy = false
private var ignoreHead = true

setDaemon(true)

override def run(): Unit = {
if (isInterrupted) keepReading = false
var reader: Option[BufferedReader] = None

try {
while (keepReading || flushy) {
flushy = false
try {
// Init reader if not already done
if (reader.isEmpty) {
Try(new BufferedReader(new FileReader(file))) match {
case Success(r) => reader = Some(r)
case Failure(_: FileNotFoundException) => ignoreHead = false
case Failure(_) => // handle other exceptions
}
}

reader.foreach { r =>
try {
var line: String = null
while ({ line = r.readLine(); line != null }) {
if (!ignoreHead) {
stream.println(line)
}
}
// After reading once, stop ignoring the head
ignoreHead = false
} catch {
case _: IOException => // could not read or file vanished
}
}
} finally {
if (keepReading) {
// Wait before the next read
try {
Thread.sleep(interval)
} catch {
case _: InterruptedException => // can't handle anyway
}
}
}
}
} finally {
reader.foreach { r =>
try {
r.close()
} catch {
case _: IOException => // nothing to do if failed to close
}
}
}
}

override def interrupt(): Unit = {
keepReading = false
super.interrupt()
}

/**
* Force a next read, even if we interrupt the thread.
*/
def flush(): Unit = {
flushy = true
}

override def close(): Unit = {
flush()
interrupt()
}
}
Loading