-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
154 lines (131 loc) · 4.27 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME
import java.util.Properties
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType
import java.time.format.DateTimeFormatter.BASIC_ISO_DATE
plugins {
java
kotlin("jvm") version "1.4.30"
id("org.jlleitschuh.gradle.ktlint") version "9.4.1"
}
repositories {
jcenter()
}
val ghidraDir = System.getenv("GHIDRA_INSTALL_DIR")
?: (project.findProperty("ghidra.dir") as? String)
?: throw IllegalStateException("Can't find Ghidra installation directory from environment variable GHIDRA_INSTALL_DIR")
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"
freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalUnsignedTypes"
}
}
val ghidra: Configuration by configurations.creating
dependencies {
ghidra(fileTree("$ghidraDir/Ghidra/Framework") { include("**/*.jar") })
ghidra(fileTree("$ghidraDir/Ghidra/Features") { include("**/*.jar") })
compileOnly(ghidra)
implementation("com.google.guava:guava:30.1.1-jre")
testImplementation(ghidra)
testImplementation(kotlin("stdlib-jdk8"))
testImplementation(platform("org.junit:junit-bom:5.7.0"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
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 project.name),
("createdOn" to LocalDateTime.now().toString()),
("author" to "Ilya Kharlamov"),
("version" to ghidraVersion),
("description" to "Support for NES / Famicom ROM disassembly in iNES format")
)
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")
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
languageVersion = "1.4"
}