@@ -77,6 +77,10 @@ else {
77
77
78
78
OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform . currentOperatingSystem;
79
79
80
+ // Technically we probably should not be doing this, but we need to know which platform we're on.
81
+ apply from : new File (ghidraInstallDir). getCanonicalPath() + " /GPL/nativePlatforms.gradle"
82
+ def ghidraPlatformName = getCurrentPlatformName()
83
+
80
84
// change this to set the version of Z3 we're using
81
85
String z3Version = " 4.12.1"
82
86
@@ -151,7 +155,6 @@ task printGhidraDir {
151
155
println ' Using Ghidra install directory ' + ghidraInstallDir
152
156
println ' Using Java ' + targetCompatibility + ' for Ghidra ' + ghidraVersion
153
157
println ' Using AUTOCATS test directory ' + autocatsDir
154
- println ' Targeting ' + os. getDisplayName() + ' (' + System . properties[' os.name' ]. toLowerCase() + ' -' + System . getProperty(' os.arch' ) + ' )'
155
158
}
156
159
157
160
task copyToLib (type : Copy ) {
@@ -284,11 +287,16 @@ tasks.clean.dependsOn(tasks.cmakeClean)
284
287
// slow because LTO. So we dynamically decide whether to set tasks.cmakeBuild as
285
288
// a dependency depending on whether z3 appears to be built.
286
289
task buildZ3 {
287
- if (! (file(' build/cmake/z3/linux-amd64/libz3.so' ). exists() ||
288
- file(' build/cmake/z3/windows-amd64/libz3.dll' ). exists() ||
289
- file(' build/cmake/z3/osx-amd64/libz3.dylib' ). exists())) {
290
+ if (fileTree(" build/cmake/z3" ). matching {
291
+ include " *-*/libz3.so"
292
+ include " *-*/libz3.dll"
293
+ include " *-*/libz3.dylib"
294
+ include " *-*/libz3java.so"
295
+ include " *-*/libz3java.dll"
296
+ include " *-*/libz3java.dylib"
297
+ }. isEmpty()) {
290
298
dependsOn(tasks. cmakeBuild)
291
- }
299
+ }
292
300
}
293
301
294
302
tasks. build. dependsOn(tasks. buildZ3)
@@ -305,37 +313,31 @@ project.getTasks().matching(
305
313
}
306
314
);
307
315
308
- if (os. isLinux()) {
309
- task copyZ3toOsLinux(type : Copy ) {
310
- from (" build/cmake/z3/linux-amd64/libz3.so" )
311
- from (" build/cmake/z3/linux-amd64/libz3java.so" )
312
- into " os/linux_x86_64"
313
- }
314
-
315
- copyZ3toOsLinux. dependsOn(tasks. buildZ3)
316
- copyToLib. dependsOn(copyZ3toOsLinux)
317
- }
316
+ task copyZ3(type : Copy ) {
317
+ from (" build/cmake/z3" ) {
318
+ include " *-*/libz3.so"
319
+ include " *-*/libz3.dll"
320
+ include " *-*/libz3.dylib"
321
+ include " *-*/libz3java.so"
322
+ include " *-*/libz3java.dll"
323
+ include " *-*/libz3java.dylib"
318
324
319
- if (os. isWindows()) {
320
- task copyZ3toOsWin(type : Copy ) {
321
- from (" build/cmake/z3/windows-amd64/libz3.dll" )
322
- from (" build/cmake/z3/windows-amd64/libz3java.dll" )
323
- into " os/win_x86_64"
324
325
}
325
-
326
- copyZ3toOsWin. dependsOn(tasks. buildZ3)
327
- copyToLib. dependsOn(copyZ3toOsWin)
328
- }
326
+ into " os/${ ghidraPlatformName} "
329
327
330
- if (os . isMacOsX()) {
331
- task copyZ3toOsMac( type : Copy ) {
332
- from ( " build/cmake/z3/osx-amd64/libz3.dylib " )
333
- from ( " build/cmake/z3/osx-amd64/libz3java.dylib " )
334
- into " os/mac_x86_64 "
328
+ // https://stackoverflow.com/a/45635959
329
+ // Flatten the hierarchy by setting the path
330
+ // of all files to their respective basename
331
+ eachFile {
332
+ path = name
335
333
}
336
-
337
- copyZ3toOsMac. dependsOn(tasks. buildZ3)
338
- copyToLib. dependsOn(copyZ3toOsMac)
334
+
335
+ // Flattening the hierarchy leaves empty directories,
336
+ // do not copy those
337
+ includeEmptyDirs = false
338
+
339
+ copyZ3. dependsOn(tasks. buildZ3)
340
+ copyToLib. dependsOn(copyZ3)
339
341
}
340
342
341
343
// END: cmake z3 build section
@@ -453,12 +455,20 @@ testlogger {
453
455
454
456
test {
455
457
458
+ def osDir = file(" ${ ghidraInstallDir} /Ghidra/Extensions/kaiju/os/" )
459
+
460
+ // Automatically find the os dir names.
461
+ def osDirNames =
462
+ osDir. listFiles()
463
+ .findAll { it. isDirectory() }
464
+ .collect { file(osDir. name + " /" + it. name )}
465
+ .join(' :' )
466
+
456
467
jvmArgs = [' -Djava.awt.headless=true' ,
457
468
// add-exports needed prior to Ghidra 10.3 to address sun.awt not exported in JDK 17+
458
469
' --add-exports=java.desktop/sun.awt=ALL-UNNAMED' ,
459
470
// add the kaiju os directories to load z3 library to run tests
460
- ' -Djava.library.path=' + ghidraInstallDir + ' /Ghidra/Extensions/kaiju/lib/:' + ghidraInstallDir + ' /Ghidra/Extensions/kaiju/os/linux_x86_64/:' + ghidraInstallDir + ' /Ghidra/Extensions/kaiju/os/mac_x86_64/:' + ghidraInstallDir + ' /Ghidra/Extensions/kaiju/os/win_x86_64/' ]
461
-
471
+ ' -Djava.library.path=' + ghidraInstallDir + ' /Ghidra/Extensions/kaiju/lib/:' + osDirNames]
462
472
useJUnitPlatform()
463
473
464
474
maxHeapSize = ' 2G'
0 commit comments