From 8b054814a83cd1b62450485271fc1aecd0f653e3 Mon Sep 17 00:00:00 2001 From: ghidravore Date: Tue, 8 Dec 2020 13:03:36 -0500 Subject: [PATCH] changed build system to generate all external jar files used file. --- .../Framework/SoftwareModeling/build.gradle | 3 + build.gradle | 72 ++++++++++++++++--- gradle/distributableGhidraModule.gradle | 2 +- gradle/root/prepDev.gradle | 17 ++++- gradle/support/extensionCommon.gradle | 2 +- gradle/support/ip.gradle | 2 +- 6 files changed, 84 insertions(+), 14 deletions(-) diff --git a/Ghidra/Framework/SoftwareModeling/build.gradle b/Ghidra/Framework/SoftwareModeling/build.gradle index 07e1bef2b5..e6fcb43727 100644 --- a/Ghidra/Framework/SoftwareModeling/build.gradle +++ b/Ghidra/Framework/SoftwareModeling/build.gradle @@ -30,6 +30,9 @@ dependencies { // Must specify the specific antlr implementation to use or it will default to trying to find // version 2.7.7 (which we don't have) antlr "org.antlr:antlr:3.5.2" + // need to add in the antlr dependencies for when we build from flat jar dirs + antlr "org.antlr:antlr-runtime:3.5.2" + antlr "org.antlr:ST4:4.0.8" } def genSrcDir = 'generated-src/antlr/main' diff --git a/build.gradle b/build.gradle index a26d0fbd1f..b5539e3409 100644 --- a/build.gradle +++ b/build.gradle @@ -292,28 +292,49 @@ String getCurrentPlatformName() { * given project * *********************************************************************************/ -List getExternalDependencies(Project project) { +List getExternalRuntimeDependencies(Project project) { List list = new ArrayList() - // for each dependency in the compile configuration - Configuration runtimeConfig = project.configurations.runtime - runtimeConfig.allDependencies.each { dep -> + list.addAll(getExternalDependencies(project.configurations.compile)); + list.addAll(getExternalDependencies(project.configurations.runtime)); + + return list +} + +List getExternalDependencies(Configuration configuration) { + List list = new ArrayList<>(); + configuration.dependencies.each { dep -> // if the dependency is an external jar - if (dep.class.toString().contains("DefaultExternalModuleDependency")) { - + if (dep instanceof ExternalDependency) { + // loop back through all the dependency files, looking for one that contains the dependency name. - String depPath = runtimeConfig.find { + String depPath = configuration.find { it.name.contains(dep.name) } // if we found the path, then add it to the list - if (depPath && !depPath.contains("libsForBuild")) { + if (depPath) { list.add(depPath) } } } - return list + return list; +} + +/********************************************************************************* + * Returns a list of all the external library paths declared as dependencies for the + * given project + * + *********************************************************************************/ +Set getAllExternalDependencies(Project project) { + Set set = new HashSet() + + project.getConfigurations().each { config -> + set.addAll(getExternalDependencies(config)) + } + + return set } /****************************************************************************************** @@ -334,7 +355,7 @@ String generateLibraryDependencyMapping() { libsFile.withWriter { out -> subprojects { p -> p.plugins.withType(JavaPlugin) { - List libs = getExternalDependencies(p); + List libs = getExternalRuntimeDependencies(p); if (libs != null) { out.println "Module: $p.name" libs.each { path -> @@ -346,6 +367,37 @@ String generateLibraryDependencyMapping() { } return libsFile.absolutePath } +/****************************************************************************************** + * + * Creates a file that lists all external jars used to build and run Ghidra + * + ******************************************************************************************/ +String generateAllExternalLibsFile() { + File libsFile = file("$buildDir/AllExternalLibs.txt") + + // Check to make sure the build folder exists - if it doesn't, the 'libsFile.withWriter' + // call (below) will fail miserably. + def buildFolder = file ("$buildDir") + if (!buildFolder.exists()) { + buildFolder.mkdirs() + } + Set allLibs = new HashSet<>(); + subprojects { p -> + p.plugins.withType(JavaPlugin) { + Set libs = getAllExternalDependencies(p); + if (libs != null) { + allLibs.addAll(libs); + } + } + } + libsFile.withWriter { out -> + allLibs.each { path -> + out.println "$path" + } + } + return libsFile.absolutePath +} + task allSleighCompile { } diff --git a/gradle/distributableGhidraModule.gradle b/gradle/distributableGhidraModule.gradle index 104a842240..3506d50080 100644 --- a/gradle/distributableGhidraModule.gradle +++ b/gradle/distributableGhidraModule.gradle @@ -173,7 +173,7 @@ plugins.withType(JavaPlugin) { // External Libraries gradle.taskGraph.whenReady { taskGraph -> - List externalPaths = getExternalDependencies(p) + List externalPaths = getExternalRuntimeDependencies(p) externalPaths.each { path -> from (path) { into {zipPath + "/lib" } diff --git a/gradle/root/prepDev.gradle b/gradle/root/prepDev.gradle index dc0d6f1bf9..fe46b5bca4 100644 --- a/gradle/root/prepDev.gradle +++ b/gradle/root/prepDev.gradle @@ -12,8 +12,22 @@ task prepDev { // the GhidraLauncher depends on this file to build the classpath in dev mode dependsOn { generateLibraryDependencyMapping } + + // generate list of all library files used to build and run ghidra. (not strictly necessary here, but nice to have) + dependsOn { generateAllExternalLibsFile } + } +/****************************************************************************************** + * TASK generateAllExternalLibsFile + * + * Summary: Creates a file that lists all libraries used to build and run Ghidra + ******************************************************************************************/ +task generateAllExternalLibsFile { + doFirst{ + generateAllExternalLibsFile() + } +} /****************************************************************************************** * TASK generateLibraryDependencyMapping @@ -24,4 +38,5 @@ task generateLibraryDependencyMapping { doFirst{ generateLibraryDependencyMapping() } -} \ No newline at end of file +} + diff --git a/gradle/support/extensionCommon.gradle b/gradle/support/extensionCommon.gradle index bc1d3cdd5a..953fa19ba0 100644 --- a/gradle/support/extensionCommon.gradle +++ b/gradle/support/extensionCommon.gradle @@ -61,7 +61,7 @@ task zipExtensions (type: Zip) { ///////////////// gradle.taskGraph.whenReady { taskGraph -> if (project.plugins.withType(JavaPlugin)) { - List externalPaths = getExternalDependencies(p) + List externalPaths = getExternalRuntimeDependencies(p) externalPaths.each { path -> from (path) { into { getBaseProjectName(p) + "/lib" } diff --git a/gradle/support/ip.gradle b/gradle/support/ip.gradle index 5e6c4a8ab3..2125091554 100644 --- a/gradle/support/ip.gradle +++ b/gradle/support/ip.gradle @@ -82,7 +82,7 @@ def Map getModuleManifestIp(Project project) { *********************************************************************************/ def checkExternalLibsInMap(Map map, Project project) { if (project.plugins.withType(JavaPlugin)) { - List libs = getExternalDependencies(project) + List libs = getExternalRuntimeDependencies(project) libs.each { lib -> String libName = new File(lib).getName() // get just the filename without the path String relativePath = "lib/"+libName;