Skip to content

Commit

Permalink
changed build system to generate all external jar files used file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghidravore authored and ghidra1 committed Dec 9, 2020
1 parent fb43801 commit 8b05481
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Ghidra/Framework/SoftwareModeling/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
72 changes: 62 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -292,28 +292,49 @@ String getCurrentPlatformName() {
* given project
*
*********************************************************************************/
List<String> getExternalDependencies(Project project) {
List<String> getExternalRuntimeDependencies(Project project) {
List<String> list = new ArrayList<String>()

// 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<String> getExternalDependencies(Configuration configuration) {
List<String> 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<String> getAllExternalDependencies(Project project) {
Set<String> set = new HashSet<String>()

project.getConfigurations().each { config ->
set.addAll(getExternalDependencies(config))
}

return set
}

/******************************************************************************************
Expand All @@ -334,7 +355,7 @@ String generateLibraryDependencyMapping() {
libsFile.withWriter { out ->
subprojects { p ->
p.plugins.withType(JavaPlugin) {
List<String> libs = getExternalDependencies(p);
List<String> libs = getExternalRuntimeDependencies(p);
if (libs != null) {
out.println "Module: $p.name"
libs.each { path ->
Expand All @@ -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<String> allLibs = new HashSet<>();
subprojects { p ->
p.plugins.withType(JavaPlugin) {
Set<String> libs = getAllExternalDependencies(p);
if (libs != null) {
allLibs.addAll(libs);
}
}
}
libsFile.withWriter { out ->
allLibs.each { path ->
out.println "$path"
}
}
return libsFile.absolutePath
}


task allSleighCompile {
}
2 changes: 1 addition & 1 deletion gradle/distributableGhidraModule.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ plugins.withType(JavaPlugin) {

// External Libraries
gradle.taskGraph.whenReady { taskGraph ->
List<String> externalPaths = getExternalDependencies(p)
List<String> externalPaths = getExternalRuntimeDependencies(p)
externalPaths.each { path ->
from (path) {
into {zipPath + "/lib" }
Expand Down
17 changes: 16 additions & 1 deletion gradle/root/prepDev.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,4 +38,5 @@ task generateLibraryDependencyMapping {
doFirst{
generateLibraryDependencyMapping()
}
}
}

2 changes: 1 addition & 1 deletion gradle/support/extensionCommon.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ task zipExtensions (type: Zip) {
/////////////////
gradle.taskGraph.whenReady { taskGraph ->
if (project.plugins.withType(JavaPlugin)) {
List<String> externalPaths = getExternalDependencies(p)
List<String> externalPaths = getExternalRuntimeDependencies(p)
externalPaths.each { path ->
from (path) {
into { getBaseProjectName(p) + "/lib" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/support/ip.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def Map<String, String> getModuleManifestIp(Project project) {
*********************************************************************************/
def checkExternalLibsInMap(Map<String, String> map, Project project) {
if (project.plugins.withType(JavaPlugin)) {
List<String> libs = getExternalDependencies(project)
List<String> libs = getExternalRuntimeDependencies(project)
libs.each { lib ->
String libName = new File(lib).getName() // get just the filename without the path
String relativePath = "lib/"+libName;
Expand Down

0 comments on commit 8b05481

Please sign in to comment.