Skip to content

Commit 6018d1e

Browse files
JornVerneemcimadamore
authored andcommitted
7903134: Improve error reporting in jextract gradle build
Reviewed-by: mcimadamore
1 parent 71d7eae commit 6018d1e

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.gradle
22
**/build/
3+
.idea

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
`jextract` can be built using `gradle`, as follows (on Windows, `gradlew.bat` should be used instead):
1010

1111
```sh
12-
$ sh ./gradlew -Pjdk18_home=<jdk18_home_dir> -Plibclang_home=<libclang_dir> clean verify
12+
$ sh ./gradlew -Pjdk18_home=<jdk18_home_dir> -Pllvm_home=<libclang_dir> clean verify
1313
```
1414

1515
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):
@@ -38,7 +38,7 @@ Expected a header file
3838
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):
3939

4040
```sh
41-
$ sh ./gradlew -Pjdk18_home=<jdk18_home_dir> -Plibclang_home=<libclang_dir> jtreg
41+
$ sh ./gradlew -Pjdk18_home=<jdk18_home_dir> -Pllvm_home=<libclang_dir> jtreg
4242
```
4343

4444
### Using jextract

build.gradle

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import org.apache.tools.ant.taskdefs.condition.Os
2+
import java.nio.file.Files;
3+
import java.nio.file.Path;
24

35
plugins {
46
id "java"
@@ -10,8 +12,21 @@ plugins {
1012

1113
version = '1.0'
1214

13-
def libclang_home = project.property("libclang_home")
14-
def clang_version = new File("${libclang_home}/lib/clang/").list()[0]
15+
def static checkPath(String p) {
16+
if (!Files.exists(Path.of(p))) {
17+
throw new IllegalArgumentException("Error: the path ${p} does not exist");
18+
}
19+
}
20+
21+
def llvm_home = project.property("llvm_home")
22+
checkPath(llvm_home)
23+
checkPath("${llvm_home}/lib/clang")
24+
def clang_versions = new File("${llvm_home}/lib/clang/").list();
25+
if (clang_versions.length == 0) {
26+
throw new IllegalArgumentException("Could not detect clang version." +
27+
" Make sure a ${llvm_home}/lib/clang/<VERSION> directory exists")
28+
}
29+
def clang_version = clang_versions[0]
1530

1631
def jextract_path
1732
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
@@ -22,9 +37,11 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
2237
jextract_path = "$buildDir/jextract/bin/jextract"
2338
}
2439

25-
def clang_include_dir = "${libclang_home}/lib/clang/${clang_version}/include"
40+
def clang_include_dir = "${llvm_home}/lib/clang/${clang_version}/include"
41+
checkPath(clang_include_dir)
2642
def os_lib_dir = Os.isFamily(Os.FAMILY_WINDOWS)? "bin" : "lib"
27-
def libclang_dir = "${libclang_home}/${os_lib_dir}"
43+
def libclang_dir = "${llvm_home}/${os_lib_dir}"
44+
checkPath(libclang_dir)
2845

2946
repositories {
3047
mavenCentral()

0 commit comments

Comments
 (0)