Skip to content

Commit

Permalink
7903134: Improve error reporting in jextract gradle build
Browse files Browse the repository at this point in the history
Reviewed-by: mcimadamore
  • Loading branch information
JornVernee authored and mcimadamore committed Mar 28, 2022
1 parent 71d7eae commit 6018d1e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
.gradle
**/build/
.idea
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -9,7 +9,7 @@
`jextract` can be built using `gradle`, as follows (on Windows, `gradlew.bat` should be used instead):

```sh
$ sh ./gradlew -Pjdk18_home=<jdk18_home_dir> -Plibclang_home=<libclang_dir> clean verify
$ sh ./gradlew -Pjdk18_home=<jdk18_home_dir> -Pllvm_home=<libclang_dir> clean verify
```

After building, there should be a new `jextract` folder under `build` (the contents and the name of this folder might vary slightly depending on the platform):
Expand Down Expand Up @@ -38,7 +38,7 @@ Expected a header file
The repository also contains a comprehensive set of tests, written using the [jtreg](https://openjdk.java.net/jtreg/) test framework, which can be run as follows (again, on Windows, `gradlew.bat` should be used instead):

```sh
$ sh ./gradlew -Pjdk18_home=<jdk18_home_dir> -Plibclang_home=<libclang_dir> jtreg
$ sh ./gradlew -Pjdk18_home=<jdk18_home_dir> -Pllvm_home=<libclang_dir> jtreg
```

### Using jextract
Expand Down
25 changes: 21 additions & 4 deletions build.gradle
@@ -1,4 +1,6 @@
import org.apache.tools.ant.taskdefs.condition.Os
import java.nio.file.Files;
import java.nio.file.Path;

plugins {
id "java"
Expand All @@ -10,8 +12,21 @@ plugins {

version = '1.0'

def libclang_home = project.property("libclang_home")
def clang_version = new File("${libclang_home}/lib/clang/").list()[0]
def static checkPath(String p) {
if (!Files.exists(Path.of(p))) {
throw new IllegalArgumentException("Error: the path ${p} does not exist");
}
}

def llvm_home = project.property("llvm_home")
checkPath(llvm_home)
checkPath("${llvm_home}/lib/clang")
def clang_versions = new File("${llvm_home}/lib/clang/").list();
if (clang_versions.length == 0) {
throw new IllegalArgumentException("Could not detect clang version." +
" Make sure a ${llvm_home}/lib/clang/<VERSION> directory exists")
}
def clang_version = clang_versions[0]

def jextract_path
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
Expand All @@ -22,9 +37,11 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
jextract_path = "$buildDir/jextract/bin/jextract"
}

def clang_include_dir = "${libclang_home}/lib/clang/${clang_version}/include"
def clang_include_dir = "${llvm_home}/lib/clang/${clang_version}/include"
checkPath(clang_include_dir)
def os_lib_dir = Os.isFamily(Os.FAMILY_WINDOWS)? "bin" : "lib"
def libclang_dir = "${libclang_home}/${os_lib_dir}"
def libclang_dir = "${llvm_home}/${os_lib_dir}"
checkPath(libclang_dir)

repositories {
mavenCentral()
Expand Down

0 comments on commit 6018d1e

Please sign in to comment.