@@ -77,6 +77,10 @@ else {
7777
7878OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform . currentOperatingSystem;
7979
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+
8084// change this to set the version of Z3 we're using
8185String z3Version = " 4.12.1"
8286
@@ -151,7 +155,6 @@ task printGhidraDir {
151155 println ' Using Ghidra install directory ' + ghidraInstallDir
152156 println ' Using Java ' + targetCompatibility + ' for Ghidra ' + ghidraVersion
153157 println ' Using AUTOCATS test directory ' + autocatsDir
154- println ' Targeting ' + os. getDisplayName() + ' (' + System . properties[' os.name' ]. toLowerCase() + ' -' + System . getProperty(' os.arch' ) + ' )'
155158}
156159
157160task copyToLib (type : Copy ) {
@@ -284,11 +287,16 @@ tasks.clean.dependsOn(tasks.cmakeClean)
284287// slow because LTO. So we dynamically decide whether to set tasks.cmakeBuild as
285288// a dependency depending on whether z3 appears to be built.
286289task 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()) {
290298 dependsOn(tasks. cmakeBuild)
291- }
299+ }
292300}
293301
294302tasks. build. dependsOn(tasks. buildZ3)
@@ -305,37 +313,31 @@ project.getTasks().matching(
305313 }
306314);
307315
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"
318324
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"
324325 }
325-
326- copyZ3toOsWin. dependsOn(tasks. buildZ3)
327- copyToLib. dependsOn(copyZ3toOsWin)
328- }
326+ into " os/${ ghidraPlatformName} "
329327
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
335333 }
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)
339341}
340342
341343// END: cmake z3 build section
@@ -453,12 +455,20 @@ testlogger {
453455
454456test {
455457
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+
456467 jvmArgs = [' -Djava.awt.headless=true' ,
457468 // add-exports needed prior to Ghidra 10.3 to address sun.awt not exported in JDK 17+
458469 ' --add-exports=java.desktop/sun.awt=ALL-UNNAMED' ,
459470 // 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]
462472 useJUnitPlatform()
463473
464474 maxHeapSize = ' 2G'
0 commit comments