-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[x2cpg] Refactor ExternalCommand (#5017)
Works with Java Process / ProcessBuilder now. No more scala.sys.process. ----------- Co-authored-by: Michael Pollmeier <michael@michaelpollmeier.com>
- Loading branch information
1 parent
2cc61c8
commit 398af04
Showing
20 changed files
with
182 additions
and
143 deletions.
There are no files selected for viewing
29 changes: 10 additions & 19 deletions
29
joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/utils/ExternalCommand.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,24 @@ | ||
package io.joern.c2cpg.utils | ||
|
||
import java.util.concurrent.ConcurrentLinkedQueue | ||
import scala.sys.process.{Process, ProcessLogger} | ||
import scala.util.{Failure, Success, Try} | ||
import scala.jdk.CollectionConverters.* | ||
|
||
object ExternalCommand extends io.joern.x2cpg.utils.ExternalCommand { | ||
object ExternalCommand { | ||
|
||
override def handleRunResult(result: Try[Int], stdOut: Seq[String], stdErr: Seq[String]): Try[Seq[String]] = { | ||
result match { | ||
case Success(0) => | ||
import io.joern.x2cpg.utils.ExternalCommand.ExternalCommandResult | ||
|
||
private val IsWin = scala.util.Properties.isWin | ||
|
||
def run(command: Seq[String], cwd: String, extraEnv: Map[String, String] = Map.empty): Try[Seq[String]] = { | ||
io.joern.x2cpg.utils.ExternalCommand.run(command, cwd, mergeStdErrInStdOut = true, extraEnv) match { | ||
case ExternalCommandResult(0, stdOut, _) => | ||
Success(stdOut) | ||
case Success(1) if IsWin && IncludeAutoDiscovery.gccAvailable() => | ||
case ExternalCommandResult(1, stdOut, _) if IsWin && IncludeAutoDiscovery.gccAvailable() => | ||
// the command to query the system header file locations within a Windows | ||
// environment always returns Success(1) for whatever reason... | ||
Success(stdOut) | ||
case _ => | ||
case ExternalCommandResult(_, stdOut, _) => | ||
Failure(new RuntimeException(stdOut.mkString(System.lineSeparator()))) | ||
} | ||
} | ||
|
||
override def run(command: String, cwd: String, extraEnv: Map[String, String] = Map.empty): Try[Seq[String]] = { | ||
val stdOutOutput = new ConcurrentLinkedQueue[String] | ||
val processLogger = ProcessLogger(stdOutOutput.add, stdOutOutput.add) | ||
val process = shellPrefix match { | ||
case Nil => Process(command, new java.io.File(cwd), extraEnv.toList*) | ||
case _ => Process(shellPrefix :+ command, new java.io.File(cwd), extraEnv.toList*) | ||
} | ||
handleRunResult(Try(process.!(processLogger)), stdOutOutput.asScala.toSeq, Nil) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.