/***************************************************************************************** * * Create a configuration so the a dependency can be declared on the the software modeling * project which is where the sleigh compiler java code lives. This will be used to * form the classpath of the sleighCompile task that follows. * *****************************************************************************************/ configurations { sleighConfig } dependencies { sleighConfig project(':SoftwareModeling') } /***************************************************************************************** * * Task to write sleigh compiler args to build/data/sleighArgs.txt for use with sleigh * external sleigh compiler. * *****************************************************************************************/ task saveSleighArgs { def sleighArgsFile = file("build/data/sleighArgs.txt") outputs.files sleighArgsFile outputs.upToDateWhen { false } doLast { sleighArgsFile.withWriter { out-> project.sleighCompile.args.each { a-> // don't save -a option if (!"-a".equals(a)) { out.println a } } } } } prepDev.dependsOn(saveSleighArgs) /***************************************************************************************** * * Task to write sleigh build.xml file for use is development mode only. * *****************************************************************************************/ task writeSleighDevBuild { def templateFilePath = project(':BuildFiles').projectDir.toString() + "/sleighDevBuild.template" doLast { // Generate build.xml with injected classpath for running sleigh compiler copy { into "data" from (templateFilePath) { rename { "build.xml" } expand ( [ 'gradleSleighDevClasspath': project(':SoftwareModeling').sleighDevClasspath ] ) } } } } prepDev.dependsOn(writeSleighDevBuild) /***************************************************************************************** * * Write sleigh build.xml file for each language module into assembleCommon * *****************************************************************************************/ rootProject.assembleCommon { into (getZipPath(this.project) + "/data") { from (rootProject.projectDir.toString() + "/GhidraBuild/BuildFiles/sleighDistBuild.template") { rename { "build.xml" } } } } /***************************************************************************************** * * Task to compile language files using the sleigh compiler. * *****************************************************************************************/ task sleighCompile (type: JavaExec) { group = rootProject.GHIDRA_GROUP description " Compiles all the sleigh languages. [processorUtils.gradle]\n" // define standard parameters for JavaExec classpath configurations.sleighConfig main = 'ghidra.pcodeCPort.slgh_compile.SleighCompile' // Delay adding the directory argument until the first part of the execution phase, so // that any extra args added by a project override will be added to the arg list before // these arguments. doFirst { args '-a' args './data/languages' } jvmArgs '-Xmx2048M' } // The task that copies the common files to the distribution folder must depend on // the sleigh tasks before executing. rootProject.assembleCommon.dependsOn(sleighCompile) rootProject.assembleCommon.dependsOn(saveSleighArgs) // For all tasks of type:Test (i.e., integrationTest, cunitTest, etc.), add a task dependency to // sleighCompile. The sleighCompile task inputs and outputs are defined such that the *.slaspec // files will only be compiled once, in other words, the up-to-date checks work ok in the // sleighCompile task. To learn more, visit: // https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:up_to_date_checks // This task dependency is needed because many tests rely on the language // modules as seen in the use of ghidra.test.ToyProgramBuilder. // The tasks of type:Test do not know about sleighCompile during their configuration phase, so the // dependency must be done in this gradle file. rootProject.subprojects.findAll { subproject -> boolean isSupporProject = subproject.findProperty("isSupportProject") ?: false; if (!isSupporProject) { subproject.tasks.withType(Test).all { it.dependsOn(sleighCompile) } } } /***************************************************************************************** * * Task to clean out the compile language files (*.sla) * *****************************************************************************************/ task cleanSleigh { group rootProject.GHIDRA_GROUP description "Removes all the compile sleigh language files (*.sla). [gradleScripts/processUtils.gradle]\n" doLast { def deleteTree = fileTree(dir: "data/languages", include: "*.sla") deleteTree.each { File file -> delete file } } } /**************************************************************************************** * * Set up inputs and outputs for the sleighCompile task so that languages only get build * when the inputs change * * sleigh compile outputs to same directory as input. All files except .sla are input * ******************************************************************************************/ def taskInputs = fileTree(dir: 'data/languages', exclude: '**/*.sla') def taskOutputs = fileTree(dir: 'data/languages', include: '**/*.sla') // define the sleigh compile inputs and outputs so that gradle can check if they need building sleighCompile.inputs.files (taskInputs) sleighCompile.outputs.files (taskOutputs) // define the sleigh compile inputs to saveSleighArgs to limit task creation to language modules saveSleighArgs.inputs.files (taskInputs) def isSupportModule(Project p) { return p.findProperty("isSupportProject") ?: false }