Skip to content

Commit

Permalink
Add new Gradle build
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekkio committed Oct 27, 2020
1 parent a8a0882 commit a88eeb4
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 190 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ or
./gradlew -PGHIDRA_INSTALL_DIR=/path/to/ghidra
```

You can then find a built extension .zip in the `dist` directory.
You can then find a built extension .zip in the `build/distributions` directory.

## How to install

Expand Down
33 changes: 0 additions & 33 deletions build.gradle

This file was deleted.

131 changes: 131 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright 2019-2020 Joonas Javanainen <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.time.LocalDate
import java.time.format.DateTimeFormatter.BASIC_ISO_DATE
import java.util.Properties
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.4.10"
java
}

repositories {
jcenter()
}

val ghidraDir = System.getenv("GHIDRA_INSTALL_DIR")
?: (project.findProperty("ghidra.dir") as? String)
?: throw IllegalStateException("Can't find Ghidra installation")

val ghidraProps = Properties().apply { file("$ghidraDir/Ghidra/application.properties").inputStream().use { load(it) } }
val ghidraVersion = ghidraProps.getProperty("application.version")!!
val ghidraRelease = ghidraProps.getProperty("application.release.name")!!

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
withSourcesJar()
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
}
}

val ghidra: Configuration by configurations.creating

dependencies {
ghidra(fileTree("$ghidraDir/Ghidra/Framework") { include("**/*.jar") })
ghidra(fileTree("$ghidraDir/Ghidra/Features") { include("**/*.jar") })

compileOnly(ghidra)

testImplementation(ghidra)
testImplementation(kotlin("stdlib-jdk8"))
testImplementation(platform("org.junit:junit-bom:5.7.0"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

val generateExtensionProps by tasks.registering() {
val output = file("$buildDir/generated/extension.properties")
outputs.file(output)
doLast {
output.outputStream().use {
val props = Properties()
props += mapOf(
("name" to "GhidraBoy"),
("description" to "Support for Sharp SM83 / Game Boy"),
("author" to "Gekkio"),
("createdOn" to LocalDate.now().toString()),
("version" to ghidraVersion)
)
props.store(it, null)
}
}
}

val compileSleigh by tasks.registering(JavaExec::class) {
val slaspecFile = file("data/languages/sm83.slaspec")
val slaFile = file("data/languages/sm83.sla")

inputs.files(fileTree("data/languages").include("*.slaspec", "*.sinc"))
.withPropertyName("sourceFiles")
.withPathSensitivity(PathSensitivity.RELATIVE)
outputs.files(slaFile)
.withPropertyName("outputFile")

classpath = configurations["ghidra"]
main = "ghidra.pcodeCPort.slgh_compile.SleighCompile"
args = listOf("-u", "-l", "-n", "-t", "-e", "-c", "-f", slaspecFile.absolutePath)
}

val zip by tasks.registering(Zip::class) {
archiveFileName.set("ghidra_${ghidraVersion}_${ghidraRelease}_${LocalDate.now().format(BASIC_ISO_DATE)}_${project.name}.zip")

into("${project.name}/")
from(tasks.named("jar")) {
into("lib/")
}
from(tasks.named("sourcesJar")) {
into("lib/")
rename { "${project.name}-src.zip" }
}
from(configurations.runtimeClasspath.get()) {
into("lib/")
}

from(generateExtensionProps)
from("data") {
into("data/")
include("**/*.cspec", "**/*.ldefs", "**/*.pspec", "**/*.sinc", "**/*.slaspec", "**/sleighArgs.txt")
}
from("README.markdown", "LICENSE", "Module.manifest")
}

tasks.named("assemble") {
dependsOn("zip")
}

tasks.named<Test>("test") {
dependsOn("compileSleigh")
useJUnitPlatform()

systemProperty("ghidra.dir", ghidraDir)
systemProperty("SystemUtilities.isTesting", true)
}

defaultTasks("clean", "assemble")
50 changes: 0 additions & 50 deletions data/build.xml

This file was deleted.

5 changes: 0 additions & 5 deletions extension.properties

This file was deleted.

2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kotlin.stdlib.default.dependency=false
org.gradle.vfs.watch=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit a88eeb4

Please sign in to comment.