forked from openjdk/jextract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
200 lines (163 loc) · 5.61 KB
/
Copy pathbuild.gradle
File metadata and controls
200 lines (163 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import org.apache.tools.ant.taskdefs.condition.Os
import java.nio.file.Files;
import java.nio.file.Path;
plugins {
id "java"
}
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_version = "19"
def jmods_dir = "$buildDir/jmods"
def jextract_jmod_file = "$jmods_dir/org.openjdk.jextract.jmod"
def jextract_jmod_libs_dir = "$buildDir/jextract_jmod_libs"
def jextract_jmod_conf_dir = "$buildDir/jextract_jmod_conf";
def jextract_app_dir = "$buildDir/jextract"
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 os_script_extension = Os.isFamily(Os.FAMILY_WINDOWS)? ".bat" : ""
def libclang_dir = "${llvm_home}/${os_lib_dir}"
checkPath(libclang_dir)
repositories {
mavenCentral()
}
compileJava {
options.release = 19
options.compilerArgs << "--enable-preview"
options.fork = true
options.forkOptions.executable = "${jdk19_home}/bin/javac"
}
jar {
archiveBaseName = 'org.openjdk.jextract'
archiveVersion = project.version
}
task copyLibClang(type: Copy) {
dependsOn jar
def dir_prefix_len = "$buildDir".length()
def libs_dir = jextract_jmod_libs_dir.substring(dir_prefix_len)
def conf_dir = jextract_jmod_conf_dir.substring(dir_prefix_len)
into("$buildDir")
from("${libclang_dir}") {
include("*clang.*")
include("libLLVM.*")
into(libs_dir)
}
from("$clang_include_dir") {
include("*.h")
into(conf_dir + "/jextract")
}
}
task createJextractJmod(type: Exec) {
dependsOn copyLibClang
// if these inputs or outputs change, gradle will rerun the task
inputs.file(jar.archiveFile.get())
outputs.file(jextract_jmod_file)
doFirst {
delete(jextract_jmod_file)
}
executable = "${jdk19_home}/bin/jmod"
args = [
"create",
"--module-version=$jextract_version",
"--class-path=" + jar.archiveFile.get(),
"--libs=$jextract_jmod_libs_dir",
"--conf=$jextract_jmod_conf_dir",
"${jextract_jmod_file}"
]
}
task createJextractImage(type: Exec) {
dependsOn createJextractJmod
// if these inputs or outputs change, gradle will rerun the task
inputs.file(jar.archiveFile.get())
outputs.dir(jextract_app_dir)
def quote_jlink_opts = Os.isFamily(Os.FAMILY_WINDOWS)?
'\\"--enable-native-access=org.openjdk.jextract\\" \\"--enable-preview\""' :
'"--enable-native-access=org.openjdk.jextract" "--enable-preview"'
doFirst {
delete(jextract_app_dir)
}
executable = "${jdk19_home}/bin/jlink"
args = [
"--module-path=$jmods_dir",
"--add-modules=org.openjdk.jextract,jdk.compiler,jdk.zipfs",
"--output=${jextract_app_dir}",
"--launcher=jextract=org.openjdk.jextract/org.openjdk.jextract.JextractTool",
"--add-options",
"${quote_jlink_opts}"
]
}
// build the jextract image when the build or assemble task is run
assemble.dependsOn(createJextractImage)
// very simple integration test for generated jextract
task verify(type: Exec) {
dependsOn createJextractImage
executable = "${jextract_app_dir}/bin/jextract${os_script_extension}"
args = [ "test.h", "--output", "$buildDir/integration_test" ]
}
// jlink a JDK image with org.openjdk.jextract for testing
task createRuntimeImageForTest(type: Exec) {
dependsOn verify
def out_dir = "$buildDir/jextract-jdk-test-image"
// if these inputs or outputs change, gradle will rerun the task
inputs.file(jar.archiveFile.get())
outputs.dir(out_dir)
doFirst {
delete(out_dir)
}
executable = "${jdk19_home}/bin/jlink"
args = [
"--module-path=$jmods_dir" + File.pathSeparator + "$jdk19_home/jmods",
"--add-modules=ALL-MODULE-PATH",
"--output=$out_dir",
]
}
task cmakeConfigure(type: Exec) {
executable = "cmake"
args = [
"-B", "$buildDir/testlib-build",
"-S", "$projectDir/test/test-support",
"-DTEST_SOURCE_ROOT:FILEPATH=$projectDir/test",
"-DCMAKE_BUILD_TYPE:STRING=Release",
"-DCMAKE_INSTALL_PREFIX:FILEPATH=$buildDir/testlib-install"
]
}
task cmakeBuild(type: Exec) {
dependsOn cmakeConfigure
executable = "cmake"
args = [
"--build", "$buildDir/testlib-build",
"--config", "Release",
"--target", "install"
]
}
// run jtreg tests. Note: needs jtreg_home variable set to point to the jtreg
task jtreg(type: JavaExec) {
dependsOn createRuntimeImageForTest,cmakeBuild
doFirst {
if (findProperty("jtreg_home") == null) {
throw new GradleException("jtreg_home is not defined")
}
}
workingDir = "$buildDir"
classpath = files(findProperty("jtreg_home") + "/lib/jtreg.jar")
args = [
"-jdk", "$buildDir/jextract-jdk-test-image",
"-nativepath:$buildDir/testlib-install/${os_lib_dir}",
"-javaoption:--enable-preview",
"-javaoption:--enable-native-access=org.openjdk.jextract,ALL-UNNAMED",
"-avm", "-conc:auto", "-verbose:summary",
"../test"
]
}