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

WSL does not work #193

Closed
infiniteregrets opened this issue Nov 11, 2023 · 1 comment · Fixed by #194
Closed

WSL does not work #193

infiniteregrets opened this issue Nov 11, 2023 · 1 comment · Fixed by #194
Assignees
Labels
bug Something isn't working

Comments

@infiniteregrets
Copy link
Contributor

Bug Description

WSL just fails with no local installation of mirrord binary was found

Steps to Reproduce

Setup wsl2 on intellij idea ultimate and debug with mirrord

Backtrace

No response

Relevant Logs

No response

Your operating system and version

windows 11, wsl2, ubuntu 20.04 lts

Local process

python3

Local process version

No response

Additional Info

No response

@infiniteregrets infiniteregrets added the bug Something isn't working label Nov 11, 2023
@infiniteregrets
Copy link
Contributor Author

diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
index 4e93476..1136528 100644
--- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
+++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
@@ -208,9 +208,13 @@ class MirrordApi(private val service: MirrordProjectService) {
:
diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
index 4e93476..1136528 100644
--- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
+++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
@@ -208,9 +208,13 @@ class MirrordApi(private val service: MirrordProjectService) {
:
diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
index 4e93476..1136528 100644
--- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
+++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
@@ -208,9 +208,13 @@ class MirrordApi(private val service: MirrordProjectService) {
PS C:\Users\aashi\mirrord-intellij> git diff
diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
index 4e93476..1136528 100644
--- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
+++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
@@ -208,9 +208,13 @@ class MirrordApi(private val service: MirrordProjectService) {
      */
     fun verifyConfig(
         cli: String,
-        configFilePath: String
+        configFilePath: String,
+        wslDistribution: WSLDistribution?
     ): String {
-        return MirrordVerifyConfigTask(cli, configFilePath).run(service.project)
+        val verifyConfigTask = MirrordVerifyConfigTask(cli, configFilePath).apply {
+            this.wslDistribution = wslDistribution
+        }
+        return verifyConfigTask.run(service.project)
     }

     /**
@@ -303,6 +307,7 @@ private abstract class MirrordCliTask<T>(private val cli: String, private val co
             wslDistribution?.let {
                 val wslOptions = WSLCommandLineOptions().apply {
                     isLaunchWithWslExe = true
+                    isExecuteCommandInShell = false
                 }
                 it.patchCommandLine(this, project, wslOptions)
             }
diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordBinaryManager.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordBinaryManager.kt
index fa9423e..4515b7d 100644
--- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordBinaryManager.kt
+++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordBinaryManager.kt
@@ -104,7 +104,7 @@ class MirrordBinaryManager {
             val local = if (checkInPath) {
                 manager.getLocalBinary(version, wslDistribution)
             } else {
-                manager.findBinaryInStorage(version)
+                manager.findBinaryInStorage(version, wslDistribution)
             }

             if (local != null) {
@@ -241,19 +241,24 @@ class MirrordBinaryManager {
         Files.move(tmpDestination, destination, StandardCopyOption.REPLACE_EXISTING)
     }

-    private class MirrordBinary(val command: String) {
+    private class MirrordBinary(val command: String, wslDistribution: WSLDistribution?) {
         val version: String

         init {
-            val child = Runtime.getRuntime().exec(arrayOf(command, "--version"))
+            version = if (wslDistribution != null) {
+                val command = wslDistribution.getWslPath(command)
+                val output = wslDistribution.executeOnWsl(1000, command, "--version")
+                output.stdout.split(' ')[1].trim()
+            } else {
+                val child = Runtime.getRuntime().exec(arrayOf(command, "--version"))
+                val result = child.waitFor()
+                if (result != 0) {
+                    MirrordLogger.logger.debug("`mirrord --version` failed with code $result")
+                    throw RuntimeException("failed to get mirrord version")
+                }

-            val result = child.waitFor()
-            if (result != 0) {
-                MirrordLogger.logger.debug("`mirrord --version` failed with code $result")
-                throw RuntimeException("failed to get mirrord version")
+                child.inputReader().readLine().split(' ')[1].trim()
             }
-
-            version = child.inputReader().readLine().split(' ')[1].trim()
         }
     }

@@ -277,7 +282,7 @@ class MirrordBinaryManager {
                 output.stdoutLines.first().trim()
             }

-            val binary = MirrordBinary(output)
+            val binary = MirrordBinary(output, wslDistribution)
             if (requiredVersion == null || requiredVersion == binary.version) {
                 return binary
             }
@@ -291,10 +296,10 @@ class MirrordBinaryManager {
     /**
      * @return executable found in plugin storage
      */
-    private fun findBinaryInStorage(requiredVersion: String?): MirrordBinary? {
+    private fun findBinaryInStorage(requiredVersion: String?, wslDistribution: WSLDistribution?): MirrordBinary? {
         try {
             MirrordPathManager.getBinary(CLI_BINARY, true)?.let {
-                val binary = MirrordBinary(it)
+                val binary = MirrordBinary(it, wslDistribution)
                 if (requiredVersion == null || requiredVersion == binary.version) {
                     return binary
                 }
@@ -310,7 +315,7 @@ class MirrordBinaryManager {
      * @return the local installation of mirrord, either in `PATH` or in plugin storage
      */
     private fun getLocalBinary(requiredVersion: String?, wslDistribution: WSLDistribution?): MirrordBinary? {
-        return findBinaryInPath(requiredVersion, wslDistribution) ?: findBinaryInStorage(requiredVersion)
+        return findBinaryInPath(requiredVersion, wslDistribution) ?: findBinaryInStorage(requiredVersion, wslDistribution)      
     }

     /**
diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordExecManager.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordExecManager.kt
index c487fb5..1de5cb0 100644
--- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordExecManager.kt
+++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordExecManager.kt
@@ -116,7 +116,7 @@ class MirrordExecManager(private val service: MirrordProjectService) {
         val configPath = service.configApi.getConfigPath(mirrordConfigFromEnv)
         var verifiedConfig: MirrordVerifiedConfig? = null
         if (configPath != null) {
-            val verifiedConfigOutput = service.mirrordApi.verifyConfig(cli, configPath)
+            val verifiedConfigOutput = service.mirrordApi.verifyConfig(cli, wslDistribution?.getWslPath(configPath) ?: configPath, wslDistribution)
             val verified = MirrordVerifiedConfig(verifiedConfigOutput, service.notifier).also { verifiedConfig = it }
             if (verified.isError()) {
                 throw InvalidConfigException(configPath, "validation failed for config")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant