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

Better detect Windows Subsystem for Linux environments #2901

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Changes from all commits
Commits
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
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