Skip to content

Commit

Permalink
Better detect Windows Subsystem for Linux environments (com-lihaoyi#2901
Browse files Browse the repository at this point in the history
)

On WSL(1), Mill does not support client-server mode.
As a consequence, we always need to run without a server.

Pull request: com-lihaoyi#2901
  • Loading branch information
lefou authored Dec 1, 2023
1 parent 452bf68 commit b21ef92
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions main/client/src/mill/main/client/MillClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,27 @@ static void initServer(String lockBase, boolean setJnaNoSys) throws IOException,
}

public static void main(String[] args) throws Exception {
boolean runIsolated = false;
if (args.length > 0) {
String firstArg = args[0];
if (Arrays.asList("-i", "--interactive", "--no-server", "--repl", "--bsp", "--help").contains(firstArg)) {
// start in no-server mode
IsolatedMillMainLoader.runMain(args);
return;
runIsolated =
Arrays.asList("-i", "--interactive", "--no-server", "--repl", "--bsp", "--help")
.contains(firstArg);
}
if (!runIsolated) {
// WSL2 has the directory /run/WSL/ and WSL1 not.
String osVersion =System.getProperty("os.version");
if(osVersion != null && (osVersion.contains("icrosoft") || osVersion.contains("WSL"))) {
// Server-Mode not supported under WSL1
runIsolated = true;
}
}

// start in client-server mode
try {
if (runIsolated) {
// start in no-server mode
IsolatedMillMainLoader.runMain(args);
} else try {
// start in client-server mode
int exitCode = main0(args);
if (exitCode == ExitServerCodeWhenVersionMismatch()) {
exitCode = main0(args);
Expand Down Expand Up @@ -116,28 +126,28 @@ public static int main0(String[] args) throws Exception {

try (
Locks locks = Locks.files(lockBase);
final FileToStreamTailer stdoutTailer =new FileToStreamTailer(stdout, System.out, refeshIntervalMillis);
final FileToStreamTailer stdoutTailer = new FileToStreamTailer(stdout, System.out, refeshIntervalMillis);
final FileToStreamTailer stderrTailer = new FileToStreamTailer(stderr, System.err, refeshIntervalMillis);
) {
Locked clientLock = locks.clientLock.tryLock();
if (clientLock != null) {
stdoutTailer.start();
stderrTailer.start();
final int exitCode = run(
lockBase,
() -> {
try {
initServer(lockBase, setJnaNoSys);
} catch (Exception e) {
throw new RuntimeException(e);
}
},
locks,
System.in,
System.out,
System.err,
args,
System.getenv());
lockBase,
() -> {
try {
initServer(lockBase, setJnaNoSys);
} catch (Exception e) {
throw new RuntimeException(e);
}
},
locks,
System.in,
System.out,
System.err,
args,
System.getenv());

// Here, we ensure we process the tails of the output files before interrupting
// the threads
Expand Down

0 comments on commit b21ef92

Please sign in to comment.