Skip to content

Commit

Permalink
[jssrc2cpg] Give astgen more heap memory (#3947)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-leuthaeuser authored Dec 12, 2023
1 parent 99aeab4 commit f1dca75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ object AstGenRunner {

private val LineLengthThreshold: Int = 10000

private val NODE_OPTIONS: Map[String, String] = Map("NODE_OPTIONS" -> "--max-old-space-size=8192")

private val TypeDefinitionFileExtensions = List(".t.ts", ".d.ts")

private val MinifiedPathRegex: Regex = ".*([.-]min\\..*js|bundle\\.js)".r
Expand Down Expand Up @@ -271,7 +273,8 @@ class AstGenRunner(config: Config) {
}
}

val result = ExternalCommand.run(s"$astGenCommand$executableArgs -t ts -o $out", out.toString())
val result =
ExternalCommand.run(s"$astGenCommand$executableArgs -t ts -o $out", out.toString(), extraEnv = NODE_OPTIONS)

val jsons = SourceFiles.determine(out.toString(), Set(".json"))
jsons.foreach { jsonPath =>
Expand All @@ -298,12 +301,12 @@ class AstGenRunner(config: Config) {
private def vueFiles(in: File, out: File): Try[Seq[String]] = {
val files = SourceFiles.determine(in.pathAsString, Set(".vue"))
if (files.nonEmpty)
ExternalCommand.run(s"$astGenCommand$executableArgs -t vue -o $out", in.toString())
ExternalCommand.run(s"$astGenCommand$executableArgs -t vue -o $out", in.toString(), extraEnv = NODE_OPTIONS)
else Success(Seq.empty)
}

private def jsFiles(in: File, out: File): Try[Seq[String]] =
ExternalCommand.run(s"$astGenCommand$executableArgs -t ts -o $out", in.toString())
ExternalCommand.run(s"$astGenCommand$executableArgs -t ts -o $out", in.toString(), extraEnv = NODE_OPTIONS)

private def runAstGenNative(in: File, out: File): Try[Seq[String]] = for {
ejsResult <- ejsFiles(in, out)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import scala.jdk.CollectionConverters._

object ExternalCommand {

private val IS_WIN: Boolean =
scala.util.Properties.isWin
private val IS_WIN: Boolean = scala.util.Properties.isWin

private val shellPrefix: Seq[String] =
if (IS_WIN) "cmd" :: "/c" :: Nil else "sh" :: "-c" :: Nil
private val shellPrefix: Seq[String] = if (IS_WIN) "cmd" :: "/c" :: Nil else "sh" :: "-c" :: Nil

def run(command: String, cwd: String, separateStdErr: Boolean = false): Try[Seq[String]] = {
def run(
command: String,
cwd: String,
separateStdErr: Boolean = false,
extraEnv: Map[String, String] = Map.empty
): Try[Seq[String]] = {
val stdOutOutput = new ConcurrentLinkedQueue[String]
val stdErrOutput = if (separateStdErr) new ConcurrentLinkedQueue[String] else stdOutOutput
val processLogger = ProcessLogger(stdOutOutput.add, stdErrOutput.add)

Process(shellPrefix :+ command, new java.io.File(cwd)).!(processLogger) match {
Process(shellPrefix :+ command, new java.io.File(cwd), extraEnv.toList: _*).!(processLogger) match {
case 0 =>
Success(stdOutOutput.asScala.toSeq)
case _ =>
Expand Down

0 comments on commit f1dca75

Please sign in to comment.