diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ccc98257d6b..ab4d5887697 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,9 +26,6 @@ jobs: fi echo "##[set-output name=version;]$VERSION" id: determine_version - - name: Build cpgo - run: | - cd go-jni && ./build.sh && sudo cp ../libcpgo.so /usr/lib/ - name: Build ${{ steps.determine_version.outputs.version }} run: | if [ "$SONAR_TOKEN" != "" ] diff --git a/README.md b/README.md index 2ecec6bda00..41aa08b76e0 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Some languages, such as Golang are marked as experimental and depend on other na #### Golang -In the case of Golang, the necessary native code can be found in the `go-jni` folder. In order to build it you can use the `build.sh` script, which uses `java_home` to automatically find JNI headers and stores the finished library in the cpg root folder. This currently only works for Linux and macOS. +In the case of Golang, the necessary native code can be found in the `src/main/golang` folder. Gradle should automatically find JNI headers and stores the finished library in the `src/main/golang` folder. This currently only works for Linux and macOS. In order to use it in an external project, the resulting library needs to be placed somewhere in `java.library.path`. ## Development Setup diff --git a/build.gradle.kts b/build.gradle.kts index 58b86f52ce9..380f24f7f56 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -191,3 +191,21 @@ spotless { googleJavaFormat() } } + +tasks.register("compileGolang") { + doLast { + project.exec { + commandLine("./build.sh") + .setStandardOutput(System.out) + .workingDir("src/main/golang") + } + } +} + +tasks.named("compileJava") { + dependsOn(":compileGolang") +} + +tasks.withType { + systemProperty("java.library.path", project.projectDir.resolve("src/main/golang")) +} diff --git a/go-jni/.vscode/tasks.json b/src/main/golang/.vscode/tasks.json similarity index 100% rename from go-jni/.vscode/tasks.json rename to src/main/golang/.vscode/tasks.json diff --git a/go-jni/basic_types.go b/src/main/golang/basic_types.go similarity index 100% rename from go-jni/basic_types.go rename to src/main/golang/basic_types.go diff --git a/go-jni/build.sh b/src/main/golang/build.sh similarity index 80% rename from go-jni/build.sh rename to src/main/golang/build.sh index 195ae77a6ab..d399b7f4891 100755 --- a/go-jni/build.sh +++ b/src/main/golang/build.sh @@ -15,4 +15,4 @@ fi export CGO_CFLAGS="-I${JAVA_HOME}/include -I/${JAVA_HOME}/include/${ARCH}" -go build -buildmode=c-shared -o ../libcpgo.${EXTENSION} lib/cpg/main.go +go build -buildmode=c-shared -o libcpgo.${EXTENSION} lib/cpg/main.go diff --git a/go-jni/declarations.go b/src/main/golang/declarations.go similarity index 100% rename from go-jni/declarations.go rename to src/main/golang/declarations.go diff --git a/go-jni/expressions.go b/src/main/golang/expressions.go similarity index 100% rename from go-jni/expressions.go rename to src/main/golang/expressions.go diff --git a/go-jni/frontend/frontend.go b/src/main/golang/frontend/frontend.go similarity index 100% rename from go-jni/frontend/frontend.go rename to src/main/golang/frontend/frontend.go diff --git a/go-jni/frontend/handler.go b/src/main/golang/frontend/handler.go similarity index 100% rename from go-jni/frontend/handler.go rename to src/main/golang/frontend/handler.go diff --git a/go-jni/go.mod b/src/main/golang/go.mod similarity index 100% rename from go-jni/go.mod rename to src/main/golang/go.mod diff --git a/go-jni/go.sum b/src/main/golang/go.sum similarity index 100% rename from go-jni/go.sum rename to src/main/golang/go.sum diff --git a/go-jni/language.go b/src/main/golang/language.go similarity index 100% rename from go-jni/language.go rename to src/main/golang/language.go diff --git a/go-jni/lib/cpg/main.go b/src/main/golang/lib/cpg/main.go similarity index 100% rename from go-jni/lib/cpg/main.go rename to src/main/golang/lib/cpg/main.go diff --git a/go-jni/node.go b/src/main/golang/node.go similarity index 100% rename from go-jni/node.go rename to src/main/golang/node.go diff --git a/go-jni/scope.go b/src/main/golang/scope.go similarity index 100% rename from go-jni/scope.go rename to src/main/golang/scope.go diff --git a/go-jni/statements.go b/src/main/golang/statements.go similarity index 100% rename from go-jni/statements.go rename to src/main/golang/statements.go diff --git a/go-jni/types.go b/src/main/golang/types.go similarity index 100% rename from go-jni/types.go rename to src/main/golang/types.go diff --git a/src/test/java/de/fraunhofer/aisec/cpg/frontends/golang/GoLanguageFrontendTest.kt b/src/test/java/de/fraunhofer/aisec/cpg/frontends/golang/GoLanguageFrontendTest.kt index 0116fa7012d..e3a13102322 100644 --- a/src/test/java/de/fraunhofer/aisec/cpg/frontends/golang/GoLanguageFrontendTest.kt +++ b/src/test/java/de/fraunhofer/aisec/cpg/frontends/golang/GoLanguageFrontendTest.kt @@ -387,6 +387,8 @@ class GoLanguageFrontendTest : BaseTest() { assertEquals("true", initializer.name) val `if` = body.statements[1] as? IfStatement + + assertNotNull(`if`) } @Test