Skip to content

Commit

Permalink
Merge pull request #165 from Privado-Inc/fix/rubyFailingTestCases
Browse files Browse the repository at this point in the history
add ast-gen in ruby
  • Loading branch information
khemrajrathore authored Dec 31, 2024
2 parents 320970c + d0957b4 commit 804570e
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions joern-cli/frontends/rubysrc2cpg/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,51 @@ libraryDependencies ++= Seq(
"org.jruby" % "jruby-complete" % Versions.jRuby
)

enablePlugins(JavaAppPackaging, LauncherJarPlugin)

libraryDependencies ++= Seq(
"io.shiftleft" %% "codepropertygraph" % Versions.cpg,
"org.scalatest" %% "scalatest" % Versions.scalatest % Test
)

enablePlugins(JavaAppPackaging, LauncherJarPlugin, Antlr4Plugin)

Antlr4 / antlr4Version := Versions.antlr
Antlr4 / antlr4GenVisitor := true
Antlr4 / javaSource := (Compile / sourceManaged).value

lazy val astGenVersion = settingKey[String]("`ruby_ast_gen` version")
astGenVersion := appProperties.value.getString("rubysrc2cpg.ruby_ast_gen_version")

lazy val astGenDlUrl = settingKey[String]("astgen download url")
astGenDlUrl := s"https://github.com/joernio/ruby_ast_gen/releases/download/v${astGenVersion.value}/"

def hasCompatibleAstGenVersion(astGenBaseDir: File, astGenVersion: String): Boolean = {
val versionFile = astGenBaseDir / "lib" / "ruby_ast_gen" / "version.rb"
if (!versionFile.exists) return false
val versionPattern = "VERSION = \"([0-9]+\\.[0-9]+\\.[0-9]+)\"".r
versionPattern.findFirstIn(IO.read(versionFile)) match {
case Some(versionString) =>
// Regex group matching doesn't appear to work in SBT
val version = versionString.stripPrefix("VERSION = \"").stripSuffix("\"")
version == astGenVersion
case _ => false
}
}

lazy val astGenResourceTask = taskKey[Seq[File]](s"Download `ruby_ast_gen` and package this under `resources`")
astGenResourceTask := {
val targetDir = baseDirectory.value / "src" / "main" / "resources"
val gemName = s"ruby_ast_gen_v${astGenVersion.value}.zip"
val compressGemPath = targetDir / gemName
val unpackedGemFullPath = targetDir / gemName.stripSuffix(s"_v${astGenVersion.value}.zip")
if (!hasCompatibleAstGenVersion(unpackedGemFullPath, astGenVersion.value)) {
if (unpackedGemFullPath.exists()) IO.delete(unpackedGemFullPath)
val url = s"${astGenDlUrl.value}$gemName"
sbt.io.Using.urlInputStream(new URI(url).toURL) { inputStream =>
sbt.IO.transfer(inputStream, compressGemPath)
}
IO.unzip(compressGemPath, unpackedGemFullPath)
IO.delete(compressGemPath)
}
(unpackedGemFullPath ** "*").get.filter(_.isFile)
}

Compile / resourceGenerators += astGenResourceTask

lazy val joernTypeStubsDlUrl = settingKey[String]("joern_type_stubs download url")
joernTypeStubsDlUrl := s"https://github.com/joernio/joern-type-stubs/releases/download/v${joernTypeStubsVersion.value}/"

Expand Down

0 comments on commit 804570e

Please sign in to comment.