Skip to content

Commit

Permalink
Fix staging invocations of pysrc2cpg (#1080)
Browse files Browse the repository at this point in the history
* Fix staging of `pysrc2cpg`

* Add script test for `pythonsrc`
  • Loading branch information
ursachec committed Mar 4, 2022
1 parent 8dce302 commit e8adb64
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
Expand Up @@ -13,10 +13,10 @@ case class PythonSrcCpgGenerator(config: FrontendConfig, rootPath: Path) extends
outputPath: String = "cpg.bin.zip",
namespaces: List[String] = List()
): Option[String] = {
val pysrc2cpgsh = rootPath.resolve("pysrc2cpg.sh").toString
val arguments = Seq(inputPath, "--output", outputPath) ++ config.cmdLineParams
val pysrc2cpgsh = rootPath.resolve("pysrc2cpg").toString
val arguments = Seq(inputPath, "-o", outputPath) ++ config.cmdLineParams
runShellCommand(pysrc2cpgsh, arguments).map(_ => outputPath)
}

override def isAvailable: Boolean = rootPath.resolve("pysrc2cpg.sh").toFile.exists()
override def isAvailable: Boolean = rootPath.resolve("pysrc2cpg").toFile.exists()
}
2 changes: 2 additions & 0 deletions joern-cli/build.sbt
Expand Up @@ -33,6 +33,7 @@ def frontendMappings(frontendName: String, stagedProject: File): Seq[(File, Stri
lazy val x2cpg = project.in(file("frontends/x2cpg"))
lazy val kotlin2cpg = project.in(file("frontends/kotlin2cpg"))
lazy val javasrc2cpg = project.in(file("frontends/javasrc2cpg"))
lazy val pysrc2cpg = project.in(file("frontends/pysrc2cpg"))
lazy val jimple2cpg = project.in(file("frontends/jimple2cpg"))
lazy val fuzzyc2cpg = project.in(file("frontends/fuzzyc2cpg"))
lazy val js2cpg = project
Expand All @@ -50,6 +51,7 @@ Universal / mappings ++= frontendMappings("fuzzyc2cpg", (fuzzyc2cpg / stage).val
Universal / mappings ++= frontendMappings("ghidra2cpg", (Projects.ghidra2cpg / stage).value)
Universal / mappings ++= frontendMappings("js2cpg", (js2cpg / stage).value)
Universal / mappings ++= frontendMappings("jimple2cpg", (jimple2cpg / stage).value)
Universal / mappings ++= frontendMappings("pysrc2cpg", (pysrc2cpg / stage).value)

lazy val cpgVersionFile = taskKey[File]("persist cpg version in file (e.g. for schema-extender)")
cpgVersionFile := {
Expand Down
2 changes: 1 addition & 1 deletion joern-cli/src/universal/pysrc2cpg
Expand Up @@ -6,7 +6,7 @@ else
SCRIPT_ABS_PATH=$(readlink -f "$0")
fi
SCRIPT_ABS_DIR=$(dirname "$SCRIPT_ABS_PATH")
SCRIPT="$SCRIPT_ABS_DIR"/frontends/pysrc2cpg/bin/pysrc2cpg
SCRIPT="$SCRIPT_ABS_DIR"/frontends/pysrc2cpg/bin/io_joern_pysrc-2-cpg_main

if [ ! -f "$SCRIPT" ]; then
echo "Unable to find $SCRIPT, have you created the distribution?"
Expand Down
5 changes: 5 additions & 0 deletions tests/code/pythonsrc/simple.py
@@ -0,0 +1,5 @@
def my_fun():
println("Hello, world!")

def main():
my_fun()
5 changes: 4 additions & 1 deletion tests/frontends-tests.sh
@@ -1,25 +1,28 @@
#!/usr/bin/env bash

set -euo pipefail

SCRIPT_ABS_PATH=$(readlink -f "$0")
SCRIPT_ABS_DIR=$(dirname "$SCRIPT_ABS_PATH")

JOERN="$SCRIPT_ABS_DIR"/../joern

frontends=(c javascript javasrc java ghidra)
frontends=(c javascript javasrc java ghidra pythonsrc)
declare -A minMethodCount=(
[c]=2
[javascript]=3
[javasrc]=7
[java]=7
[ghidra]=100
[pythonsrc]=2
)
declare -A expectedMethod=(
[c]=print_number
[javascript]=lookForProperty
[javasrc]=callsExternalMethod
[java]=callsExternalMethod
[ghidra]=reallocarray
[pythonsrc]=my_fun
)

for frontend in "${frontends[@]}"; do
Expand Down

0 comments on commit e8adb64

Please sign in to comment.