-
Notifications
You must be signed in to change notification settings - Fork 2
/
3612-Optimize-Gradle-build-with-focus-on-incremental.patch
403 lines (369 loc) · 14.5 KB
/
3612-Optimize-Gradle-build-with-focus-on-incremental.patch
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Pavlo Shevchenko <pshevchenko@gradle.com>
Date: Mon, 8 Nov 2021 15:31:42 +0100
Subject: [PATCH] 3612: Optimize Gradle build with focus on incremental build
support and output caching
---
.../Framework-TraceModeling/build.gradle | 12 +++++
.../Extensions/bundle_examples/build.gradle | 5 --
Ghidra/Features/FunctionID/build.gradle | 10 ++++
.../Common/support/buildExtension.gradle | 49 ++++++++++++++++--
gradle.properties | 1 +
gradle/distributableGhidraExtension.gradle | 5 --
gradle/distributableGhidraModule.gradle | 4 +-
gradle/externalGhidraExtension.gradle | 5 --
gradle/helpProject.gradle | 50 +++++++++++++++++--
gradle/root/distribution.gradle | 20 ++++----
gradle/support/extensionCommon.gradle | 4 +-
gradle/support/ip.gradle | 12 ++++-
settings.gradle | 1 +
13 files changed, 140 insertions(+), 38 deletions(-)
diff --git a/Ghidra/Debug/Framework-TraceModeling/build.gradle b/Ghidra/Debug/Framework-TraceModeling/build.gradle
index 7aec2d3efb..2195cf32ce 100644
--- a/Ghidra/Debug/Framework-TraceModeling/build.gradle
+++ b/Ghidra/Debug/Framework-TraceModeling/build.gradle
@@ -21,6 +21,18 @@ apply from: "${rootProject.projectDir}/gradle/distributableGhidraModule.gradle"
apply plugin: 'eclipse'
eclipse.project.name = 'Debug Framework-TraceModeling'
+// The generation timestamp included in these help files
+// makes them different on every build which causes all consuming tasks to be re-executed every time
+// By excluding these files from crucial inputs using runtime classpath normalization,
+// we are able to re-use build artifacts of this project on incremental builds
+normalization {
+ runtimeClasspath {
+ ignore '**/help/*_HelpSet.hs'
+ ignore '**/help/*_map.xml'
+ ignore '**/help/*_TOC.xml'
+ }
+}
+
dependencies {
api project(':Generic')
api project(':SoftwareModeling')
diff --git a/Ghidra/Extensions/bundle_examples/build.gradle b/Ghidra/Extensions/bundle_examples/build.gradle
index 1bf09d2822..9a25866bab 100644
--- a/Ghidra/Extensions/bundle_examples/build.gradle
+++ b/Ghidra/Extensions/bundle_examples/build.gradle
@@ -140,10 +140,5 @@ rootProject.createInstallationZip {
ZIP_DIR_PREFIX + "/Extensions/Ghidra"
}
}
- doLast {
- this.project.zipExtensions.outputs.each {
- delete it
- }
- }
}
diff --git a/Ghidra/Features/FunctionID/build.gradle b/Ghidra/Features/FunctionID/build.gradle
index 22588d6f06..9e8616f63d 100644
--- a/Ghidra/Features/FunctionID/build.gradle
+++ b/Ghidra/Features/FunctionID/build.gradle
@@ -39,6 +39,16 @@ def fidDbFiles = fileTree(depsDir.exists() ? depsDir : binRepoDir) {
}
task unpackFidDatabases {
+ inputs.files(fidDbFiles.getFiles())
+ .withPropertyName("fidDbFiles")
+ .withPathSensitivity(PathSensitivity.RELATIVE)
+ // Adding task output to make use of Gradle's up-to-date check
+ // However, outputs in form of file trees are not supported by Gradle's build cache
+ // We would need to write these files to a separate folder if we'd like to enable caching
+ outputs.files fileTree("$buildDir/data").matching {
+ include "*.fidbf"
+ }
+
doLast {
fidDbFiles.each { file ->
diff --git a/Ghidra/RuntimeScripts/Common/support/buildExtension.gradle b/Ghidra/RuntimeScripts/Common/support/buildExtension.gradle
index 72b2368916..e9ec3644e9 100644
--- a/Ghidra/RuntimeScripts/Common/support/buildExtension.gradle
+++ b/Ghidra/RuntimeScripts/Common/support/buildExtension.gradle
@@ -310,6 +310,43 @@ tasks.register('cleanHelp') {
}
}
+// CommandLineArgumentProvider that supplies indexHelp task with relative help file paths
+// This allows build cache artifacts to be relocate-able across workspaces and machines.
+class HelpFilesPathProvider implements CommandLineArgumentProvider {
+ @InputDirectory
+ @PathSensitive(PathSensitivity.RELATIVE)
+ File helpFilePath
+
+ @Override
+ Iterable<String> asArguments() {
+ [helpFilePath.absolutePath]
+ }
+}
+
+// CommandLineArgumentProvider that supplies indexHelp task with the absolute path to the help output directory
+// This allows build cache artifacts to be relocate-able across workspaces and machines.
+class HelpOutputPathProvider implements CommandLineArgumentProvider {
+ @OutputDirectory
+ File helpOutputPath
+
+ @Override
+ Iterable<String> asArguments() {
+ ["-db ${helpOutputPath.absolutePath}".toString()]
+ }
+}
+
+// CommandLineArgumentProvider that supplies indexHelp task with help config file
+// This allows build cache artifacts to be relocate-able across workspaces and machines.
+class HelpConfigFileProvider implements CommandLineArgumentProvider {
+ @InputFile
+ File helpConfigFile
+
+ @Override
+ Iterable<String> asArguments() {
+ ["-c", "${helpConfigFile}".toString()]
+ }
+}
+
// Task for calling the java help indexer, which creates a searchable index of the help contents
tasks.register('indexHelp', JavaExec) {
group "Ghidra Private"
@@ -317,8 +354,12 @@ tasks.register('indexHelp', JavaExec) {
File helpRootDir = file('src/main/help/help')
File outputFile = file("build/help/main/help/${project.name}_JavaHelpSearch")
- inputs.dir helpRootDir skipWhenEmpty()
+ inputs.dir(helpRootDir)
+ .withPropertyName('helpRootDir')
+ .withPathSensitivity(PathSensitivity.RELATIVE)
+ skipWhenEmpty()
outputs.dir outputFile
+ outputs.cacheIf { true }
classpath = sourceSets.main.runtimeClasspath
@@ -342,15 +383,15 @@ tasks.register('indexHelp', JavaExec) {
configFile.write "IndexRemove ${helpRootDir.absolutePath}" + File.separator + "\n"
// pass the config file we created as an argument to the indexer
- args '-c',"$configFile"
+ argumentProviders.add(new HelpConfigFileProvider(helpConfigFile: configFile))
// tell the indexer where send its output
- args '-db', outputFile.absolutePath
+ argumentProviders.add(new HelpOutputPathProvider(helpOutputPath: outputFile))
// for each help file that was found, add it as an argument to the indexer
helpFiles.each { File file ->
- args "${file.absolutePath}"
+ argumentProviders.add(new HelpFilesPathProvider(helpFilePath: file))
}
}
}
diff --git a/gradle.properties b/gradle.properties
index 879249cd9f..25184bcd78 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,3 +1,4 @@
# Increase maximum Gradle heap size (default is 1G)
# And fix build in locales with non-default capitalizations (e.g. tr_TR)
org.gradle.jvmargs=-Xmx2G -Duser.language=en -Duser.country=US
+org.gradle.caching=true
diff --git a/gradle/distributableGhidraExtension.gradle b/gradle/distributableGhidraExtension.gradle
index fb029f2782..0ff9b15f29 100644
--- a/gradle/distributableGhidraExtension.gradle
+++ b/gradle/distributableGhidraExtension.gradle
@@ -32,10 +32,5 @@ rootProject.createInstallationZip {
into {
ZIP_DIR_PREFIX + "/Extensions/Ghidra"
}
- }
- doLast {
- this.project.zipExtensions.outputs.each {
- delete it
- }
}
}
diff --git a/gradle/distributableGhidraModule.gradle b/gradle/distributableGhidraModule.gradle
index b83bf52123..cf72058a1d 100644
--- a/gradle/distributableGhidraModule.gradle
+++ b/gradle/distributableGhidraModule.gradle
@@ -43,8 +43,8 @@ rootProject.assembleDistribution {
from (BIN_REPO + '/' + getGhidraRelativePath(p) + "/data") {
into { zipPath + "/data" }
}
-
- from (p.projectDir.toString() + "/build/LICENSE.txt") {
+
+ from (ip) {
into { zipPath }
}
diff --git a/gradle/externalGhidraExtension.gradle b/gradle/externalGhidraExtension.gradle
index abda7a1d7e..870589bcde 100644
--- a/gradle/externalGhidraExtension.gradle
+++ b/gradle/externalGhidraExtension.gradle
@@ -18,10 +18,5 @@ apply from: "$rootProject.projectDir/gradle/support/extensionCommon.gradle"
rootProject.createExternalExtensions {
from (this.project.zipExtensions)
- doLast {
- this.project.zipExtensions.outputs.each {
- delete it
- }
- }
}
diff --git a/gradle/helpProject.gradle b/gradle/helpProject.gradle
index 4e27de875e..4bc29beed3 100644
--- a/gradle/helpProject.gradle
+++ b/gradle/helpProject.gradle
@@ -226,8 +226,45 @@ tasks.register('cleanHelp') {
}
}
-// Task for calling the java help indexer, which creates a searchable index of the help contents
-tasks.register('indexHelp', JavaExec) {
+// CommandLineArgumentProvider that supplies indexHelp task with relative help file paths
+// This allows build cache artifacts to be relocate-able across workspaces and machines.
+class HelpFilesPathProvider implements CommandLineArgumentProvider {
+ @InputDirectory
+ @PathSensitive(PathSensitivity.RELATIVE)
+ File helpFilePath
+
+ @Override
+ Iterable<String> asArguments() {
+ [helpFilePath.absolutePath]
+ }
+}
+
+// CommandLineArgumentProvider that supplies indexHelp task with the absolute path to the help output directory
+// This allows build cache artifacts to be relocate-able across workspaces and machines.
+class HelpOutputPathProvider implements CommandLineArgumentProvider {
+ @OutputDirectory
+ File helpOutputPath
+
+ @Override
+ Iterable<String> asArguments() {
+ ["-db","${helpOutputPath.absolutePath}".toString()]
+ }
+}
+
+// CommandLineArgumentProvider that supplies indexHelp task with help config file
+// This allows build cache artifacts to be relocate-able across workspaces and machines.
+class HelpConfigFileProvider implements CommandLineArgumentProvider {
+ @InputFile
+ File helpConfigFile
+
+ @Override
+ Iterable<String> asArguments() {
+ ["-c", "${helpConfigFile}".toString()]
+ }
+}
+
+// Task for calling the java help indexer, which creates a searchable index of the help contents.
+task indexHelp(type: JavaExec) {
group "private"
description "indexes the helps files for this module. [gradle/helpProject.gradle]"
@@ -235,8 +272,11 @@ tasks.register('indexHelp', JavaExec) {
File helpRootDir = file('src/main/help/help')
File outputFile = file("build/help/main/help/${project.name}_JavaHelpSearch")
+ dependsOn configurations.runtimeClasspath
+
inputs.dir helpRootDir
outputs.dir outputFile
+ outputs.cacheIf { true }
classpath = configurations.helpIndex
@@ -267,14 +307,14 @@ tasks.register('indexHelp', JavaExec) {
configFile.write "IndexRemove ${helpRootDir.absolutePath}" + File.separator + "\n"
// pass the config file we created as an argument to the indexer
- args '-c',"$configFile"
+ argumentProviders.add(new HelpConfigFileProvider(helpConfigFile: configFile))
// tell the indexer where send its output
- args '-db', outputFile.absolutePath
+ argumentProviders.add(new HelpOutputPathProvider(helpOutputPath: outputFile))
// for each help file that was found, add it as an argument to the indexer
helpFiles.each { File file ->
- args "${file.absolutePath}"
+ argumentProviders.add(new HelpFilesPathProvider(helpFilePath: file))
}
}
}
diff --git a/gradle/root/distribution.gradle b/gradle/root/distribution.gradle
index ab7876cc94..ad58e92537 100644
--- a/gradle/root/distribution.gradle
+++ b/gradle/root/distribution.gradle
@@ -474,6 +474,16 @@ def updateSlaFilesTimestamp(String distributionDirectoryPath, int timeOffsetMinu
println "updateSlaFilesTimestamp: Updated timestamps to $numFilesAdded .sla files."
}
+String ghidraExtensionsDirPath = DISTRIBUTION_DIR.getPath() + "/" + ZIP_DIR_PREFIX + "/Ghidra/Extensions"
+task createGhidraExtensionsDir {
+ outputs.dir ghidraExtensionsDirPath
+ doLast {
+ // We always want the extensions directory to exist in the zip, even if there's nothing
+ // installed there.
+ new File(ghidraExtensionsDirPath).mkdirs()
+ }
+}
+
/*********************************************************************************
*
* Assemble all targets.
@@ -487,6 +497,7 @@ task assembleAll() {
dependsOn assembleDistribution
dependsOn assembleSource
dependsOn "assembleDistribution_$currentPlatform"
+ dependsOn createGhidraExtensionsDir
if (project.hasProperty("allPlatforms")) {
project.PLATFORMS.each { platform ->
@@ -495,11 +506,6 @@ task assembleAll() {
}
doFirst {
- // We always want the extensions directory to exist in the zip, even if there's nothing
- // installed there.
- new File( DISTRIBUTION_DIR.getPath() + "/" + ZIP_DIR_PREFIX + "/Ghidra/Extensions").mkdirs()
-
-
// The dependent tasks copy the sla and slaspec files into "extractTo/<release name>/ghidra/"
// and then later to "extractTo/<release name>/dist/", which this zip task compresses. The copy
// tasks do not preserve the file modification times. If slaspec timestamp > sla timestamp,
@@ -536,10 +542,6 @@ task createInstallationZip(type: Zip) { t ->
from (DISTRIBUTION_DIR.getPath() + "/" + ZIP_DIR_PREFIX) {
into ZIP_DIR_PREFIX
}
-
- doLast {
- delete file(DISTRIBUTION_DIR.getPath() + "/" + ZIP_DIR_PREFIX)
- }
}
diff --git a/gradle/support/extensionCommon.gradle b/gradle/support/extensionCommon.gradle
index f75a612a27..aa0c7e7c3d 100644
--- a/gradle/support/extensionCommon.gradle
+++ b/gradle/support/extensionCommon.gradle
@@ -111,8 +111,8 @@ task zipExtensions (type: Zip) {
from (p.projectDir.toString() + "/build/data") {
into { getBaseProjectName(p) + "/data" }
}
-
- from (p.projectDir.toString() + "/build/LICENSE.txt") {
+
+ from (ip) {
into { getBaseProjectName(p) }
}
diff --git a/gradle/support/ip.gradle b/gradle/support/ip.gradle
index 83f119f35a..ba03a7cacb 100644
--- a/gradle/support/ip.gradle
+++ b/gradle/support/ip.gradle
@@ -31,7 +31,17 @@
/*********************************************************************************
* Defines the main ip task for each subproject
*********************************************************************************/
-task ip {
+task ip {
+
+ inputs.file(file("certification.manifest"))
+ .withPropertyName("ipCertificationFile")
+ .withPathSensitivity(PathSensitivity.RELATIVE)
+ inputs.file(file("Module.manifest"))
+ .withPropertyName("ipModuleManifest")
+ .withPathSensitivity(PathSensitivity.RELATIVE)
+ outputs.cacheIf { true}
+ outputs.file file("$buildDir/LICENSE.txt")
+
doLast {
// scans all the files in the module, reads ip from header, verifies ip, and creates mapping
diff --git a/settings.gradle b/settings.gradle
index 599e2c7c34..26430e324b 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+rootProject.name = "ghidra"
apply from: "gradle/support/settingsUtil.gradle"
/*******************************************************************************************
--
2.45.1