forked from MinecraftForge/MCPConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
508 lines (456 loc) · 18.8 KB
/
build.gradle
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath 'org.ow2.asm:asm:6.0'
classpath 'org.ow2.asm:asm-tree:6.0'
}
}
plugins {
id 'de.undercouch.download' version '3.3.0'
id 'maven'
}
archivesBaseName = 'mcp_config'
group = 'de.oceanlabs.mcp'
version = '18w22c'
def hasPatches = false
import de.undercouch.gradle.tasks.download.Download
task downloadJson(type: Download) {
src 'https://s3.amazonaws.com/Minecraft.Download/versions/' + project.version + '/' + project.version + '.json'
dest file('build/downloads/' + project.version + '.json')
overwrite false
}
task downloadClient(type: Download) {
src 'https://s3.amazonaws.com/Minecraft.Download/versions/' + project.version + '/' + project.version + '.jar'
dest file('build/downloads/' + project.version + '.jar')
overwrite false
}
task downloadServer(type: Download) {
src 'https://s3.amazonaws.com/Minecraft.Download/versions/' + project.version + '/minecraft_server.' + project.version + '.jar'
dest file('build/downloads/minecraft_server.' + project.version + '.jar')
overwrite false
}
import net.minecraftforge.lex.MergeJar
task mergeJars(type: MergeJar) {
dependsOn 'downloadClient', 'downloadServer'
client downloadClient.dest
server downloadServer.dest
mappings file('joined.tsrg')
output file('build/' + project.version + '.joined.jar')
}
task downloadLibraries(dependsOn: 'downloadJson') {
inputs.file downloadJson.dest
doLast {
def json = new groovy.json.JsonSlurper().parseText(downloadJson.dest.text)
json.libraries.each {lib ->
def target = file('build/downloads/' + lib.downloads.artifact.path)
if (!target.exists()) {
download {
src lib.downloads.artifact.url
dest target
}
}
}
}
}
import net.minecraftforge.lex.ExtractInheritance
task extractInheritance(type: ExtractInheritance) {
dependsOn 'mergeJars', 'downloadLibraries'
input mergeJars.output
output file('build/' + project.version + '_inheritance.json')
doFirst {
def json = new groovy.json.JsonSlurper().parseText(downloadJson.dest.text)
json.libraries.each{ addLibrary(file('build/downloads/' + it.downloads.artifact.path)) }
}
}
task makeSRG {
inputs.file('joined.tsrg')
outputs.file('build/' + project.version + '_joined.srg')
doLast {
def input = inputs.files.singleFile
def output = outputs.files.singleFile
def CLs = [:]
def FDs = [:]
def MDs = [:]
def lines = []
input.eachLine { line ->
if (line.indexOf('#') != -1)
line = line.substring(0, line.indexOf('#'))
if (line.trim().isEmpty())
return
if (!line.startsWith('\t'))
CLs[line.split(' ')[0]] = line.split(' ')[1]
lines.add(line)
}
def remap = {
if (it.indexOf('L') == -1)
return it
def m = it =~ /L([^;]+);/
def sb = new StringBuffer();
while (m.find())
m.appendReplacement(sb, java.util.regex.Matcher.quoteReplacement('L' + (CLs.containsKey(m.group(1)) ? CLs.get(m.group(1)) : m.group(1)) + ';'))
m.appendTail(sb);
return sb.toString();
}
def current = null
lines.each { line ->
if (!line.startsWith('\t')) {
current = line.split(' ')
return
}
if (current == null)
throw new Exception("TSRG format screwed up... Null class context!")
def pts = line.trim().split(' ')
if (pts.length == 2)
FDs[current[0] + '/' + pts[0]] = current[1] + '/' + pts[1]
else if (pts.length == 3)
MDs[current[0] + '/' + pts[0] + ' ' + pts[1]] = current[1] + '/' + pts[2] + ' ' + remap.call(pts[1])
else
throw new Exception('Unknown: ' + line.trim())
}
String.metaClass.rsplit = { chr -> [delegate.substring(0, delegate.lastIndexOf(chr)), delegate.substring(delegate.lastIndexOf(chr))] }
output.withWriter('UTF-8') { writer ->
def format_class = {
if (it.indexOf('/') != -1)
return it
def ret = ''
for (def pt : it.split('\\$'))
ret += '$' + pt.padLeft(1000, ' ')
return ret.substring(1)
}
def format_field = { format_class.call(it.rsplit('/')[0]) + '/' + it.rsplit('/')[1].padLeft(1000, ' ') }
def format_method = { format_field.call(it.split(' ')[0]) + ' ' + it.split(' ')[1] }
CLs.sort{format_class.call(it.key)}.each{k,v -> writer.write('CL: ' + k + ' ' + v + '\n')}
FDs.sort{format_field.call(it.key)}.each{k,v -> writer.write('FD: ' + k + ' ' + v + '\n')}
MDs.sort{format_method.call(it.key)}.each{k,v -> writer.write('MD: ' + k + ' ' + v + '\n')}
}
}
}
task makeCSRG {
inputs.file('joined.tsrg')
outputs.file('build/' + project.version + '_joined.csrg')
doLast {
def current = null
outputs.files.singleFile.withWriter('UTF-8') { writer ->
inputs.files.singleFile.each { line ->
if (line.indexOf('#') != -1)
line = line.substring(0, line.indexOf('#'))
if (line.trim().isEmpty())
return
if (!line.startsWith('\t')) {
current = line.split(' ')[0]
writer.write(line + '\n')
} else {
if (current == null)
throw new Exception("TSRG format screwed up... Null class context!")
writer.write(current + ' ' + line.trim() + '\n')
}
}
}
}
}
def loadSRG(file) {
def ret = ['PK:': [:], 'CL:': [:], 'FD:': [:], 'MD:': [:]]
file.eachLine { line ->
if (line.indexOf('#') != -1)
line = line.substring(0, line.indexOf('#'))
if (line.trim().isEmpty())
return
def pts = line.split(' ')
if (pts[0] == 'PK:' || pts[0] == 'CL:' || pts[0] == 'FD:')
ret[pts[0]][pts[1]] = pts[2]
else if (pts[0] == 'MD:')
ret[pts[0]][pts[1] + ' ' + pts[2]] = pts[3] + ' ' + pts[4]
}
return ret
}
def extraAccess = [
'PUBLIC net/minecraft/client/renderer/texture/NativeImage func_195697_a (IIIZ)V'
]
task fixAccessLevels(dependsOn: ['extractInheritance', 'makeSRG']) {
inputs.file extractInheritance.output
outputs.file('build/' + project.version + '_access.txt')
doLast {
def srg = loadSRG(makeSRG.outputs.files.singleFile)
def json = new groovy.json.JsonSlurper().parseText(inputs.files.singleFile.text)
outputs.files.singleFile.withWriter('UTF-8') { writer ->
json.each{ k,v ->
json[k]['methods']?.each{ sig,data ->
if (data['override']) {
def access = json[data['override']] ? json[data['override']]['methods'] ? json[data['override']]['methods'][sig] ? json[data['override']]['methods'][sig]['access'] : null : null : null
if (access != null) {
if ((data['access'] & 0b1010) == 0) { // STATIC PRIVATE
def old = data['access'] & 0b0010 ? 0 : data['access'] & 0b0100 ? 2 : data['access'] & 0b0001 ? 3 : 1
def top = access & 0b0010 ? 0 : access & 0b0100 ? 2 : access & 0b0001 ? 3 : 1
def names = ['PRIVATE', 'DEFAULT', 'PROTECTED', 'PUBLIC']
if (old < top) {
def mapped = srg['MD:'][k + '/' + sig]
if (mapped == null) {
print('Missing srg mapping for access: ' + k + '/' + sig + '\n')
}
else {
def mtd = mapped.split(' ')
def ind = mtd[0].lastIndexOf('/')
mtd = mtd[0].substring(0, ind) + ' ' + mtd[0].substring(ind+1) + ' ' + mtd[1]
//println(mtd + " " + names[old] + " " + names[top])
writer.write(names[top] + ' ' + mtd + '\n')
}
}
}
}
}
}
}
extraAccess.each{line -> writer.write(line + '\n')}
}
}
}
task dumpOverrides(dependsOn: ['extractInheritance', 'makeSRG']) {
inputs.file extractInheritance.output
outputs.file 'build/' + project.version + '_overrides.txt'
doLast {
def srg = loadSRG(makeSRG.outputs.files.singleFile)
def json = new groovy.json.JsonSlurper().parseText(inputs.files.singleFile.text)
def methods = [] as HashSet
json.each{ k,v ->
json[k]['methods']?.each{ sig,data ->
if (data['override']) {
def mtd = srg['MD:'][k + '/' + sig]
methods.add(mtd)
}
}
}
outputs.files.singleFile.withWriter('UTF-8') { writer ->
methods = methods.sort{it}
methods.each{ writer.write(it + '\n') }
}
}
}
task dumpStatic(dependsOn: ['extractInheritance', 'makeSRG']) {
inputs.file extractInheritance.output
outputs.file 'build/' + project.version + '_static_methods.txt'
doLast {
def srg = loadSRG(makeSRG.outputs.files.singleFile)
def json = new groovy.json.JsonSlurper().parseText(inputs.files.singleFile.text)
def methods = [] as HashSet
json.each{ cls,data ->
data['methods']?.findAll{k,v -> (v['access'] & 0b1000) != 0}.each{ sig,__ ->
def mtd = srg['MD:'][cls + '/' + sig]
if (mtd && !mtd.contains('()') && mtd.contains('func_')) {
mtd = mtd.split(' ')[0]
methods.add(mtd.substring(mtd.lastIndexOf('/') + 1))
}
}
}
outputs.files.singleFile.withWriter('UTF-8') { writer ->
methods = methods.sort{it}
methods.each{ writer.write(it + '\n') }
}
}
}
task makeExceptions(dependsOn: ['extractInheritance', 'makeSRG']) {
inputs.file 'exceptions.txt'
outputs.file('build/' + project.version + '_exceptions.txt')
doLast {
def srg = loadSRG(makeSRG.outputs.files.singleFile)
def json = new groovy.json.JsonSlurper().parseText(extractInheritance.output.text)
def known = [:]
srg['MD:'].each{k,v -> known[v] = k}
def methods = [:]
def current_class = null
def line_num = 0
inputs.files.singleFile.eachLine { line ->
line_num++
if (line.indexOf('#') != -1)
line = line.substring(0, line.indexOf('#'))
if (line.trim().isEmpty())
return
def pts = line.trim().split(' ')
if (line.startsWith('\t')) {
if (current_class == null)
throw new Exception('Invalid Exceptions.txt format on line #' + line_num + ': ' + line)
def key = current_class + '/' + pts[0] + ' ' + pts[1]
if (!methods[key])
methods[key] = [] as HashSet
for (int x = 2; x < pts.length; x++)
methods[key].add(pts[x])
} else if (pts.length == 1) {
current_class = pts[0]
} else if (pts.length >= 3) {
current_class = null
def key = pts[0] + '/' + pts[1] + ' ' + pts[2]
if (!methods[key])
methods[key] = [] as HashSet
for (int x = 3; x < pts.length; x++)
methods[key].add(pts[x])
} else
throw new Exception('Invalid Exceptions.txt format on line #' + line_num + ': ' + line)
}
json.each{ k,v ->
json[k]['methods']?.each{ sig,data ->
if (data['override']) {
def mtd = srg['MD:'][k + '/' + sig]
def ord = data['override'] + '/' + sig
if (srg['MD:'][ord])
ord = srg['MD:'][ord]
if (methods[ord]) {
if (!methods[mtd])
methods[mtd] = [] as HashSet
methods[ord].each{ methods[mtd].add(it) }
if (data['bouncer']) {
def bnc = srg['MD:'][k +'/' + data['bouncer']['name'] + ' ' + data['bouncer']['desc']]
if (!methods[bnc])
methods[bnc] = [] as HashSet
methods[ord].each{ methods[bnc].add(it) }
}
}
}
}
}
outputs.files.singleFile.withWriter('UTF-8') { writer ->
methods.keySet().sort{it}.findAll{known.containsKey(it)}.each{ writer.write(it + ' ' + methods[it].join(' ') + '\n') }
}
}
}
import org.objectweb.asm.Type
task makeExceptorConfigOld(dependsOn: ['makeExceptions', 'fixAccessLevels']) {
inputs.file 'constructors.txt'
inputs.file makeExceptions.outputs.files.singleFile
inputs.file fixAccessLevels.outputs.files.singleFile
outputs.file 'build/' + project.version + '_joined.exc'
doLast {
def params = [:]
def exceptions = [:]
def access = [:]
file('constructors.txt').eachLine{ line ->
if (line.indexOf('#') != -1)
line = line.substring(0, line.indexOf('#'))
if (line.trim().isEmpty())
return
def pts = line.split(' ')
def args = []
def index = 1
Type.getMethodType(pts[2]).argumentTypes.each{
args.add('p_i' + pts[0] + '_' + index + '_')
index += it.size
}
params[pts[1] + '.<init>' + pts[2]] = args
}
makeExceptions.outputs.files.singleFile.eachLine{line ->
def pts = line.split(' ')
def ind = pts[0].lastIndexOf('/')
pts[0] = (pts[0].substring(0, ind) + '.' + pts[0].substring(ind+1)) + '' + pts[1]
exceptions[pts[0]] = pts[2..(pts.length-1)]
}
fixAccessLevels.outputs.files.singleFile.eachLine{line ->
def pts = line.split('=')
if (pts.length == 2)
access[pts[0]] = pts[1]
}
def keys = [] as HashSet
keys.addAll(params.keySet())
keys.addAll(exceptions.keySet())
keys.addAll(access.keySet())
outputs.files.singleFile.withWriter('UTF-8') { writer ->
keys.sort().each{ key ->
if (access[key])
writer.write(key + '=' + access[key] + '\n')
else {
def p = params[key] ? params[key] : []
def e = exceptions[key] ? exceptions[key] : []
if (p.size() > 0 || e.size() > 0)
writer.write(key + '=' + e.join(',') + '|' + p.join(',') + '\n')
}
}
}
}
}
task makeExceptorConfig(dependsOn: ['makeExceptions', 'fixAccessLevels']) {
outputs.file 'build/' + project.version + '_exceptor.cfg'
doLast {
outputs.files.singleFile.withWriter('UTF-8') { writer ->
writer.write('Version = 3.7\n')
writer.write('Access = ' + fixAccessLevels.outputs.files.singleFile.name.replace(project.version +'_', '') + '\n')
writer.write('Exceptions = ' + makeExceptions.outputs.files.singleFile.name.replace(project.version +'_', '') + '\n')
writer.write('Constructors = constructors.txt\n')
writer.write('LVT = LVT\n')
}
}
}
task makeZip(type: Zip) {
baseName = project.archivesBaseName
classifier = 'srg'
version = project.version
destinationDir = file('build/distributions')
from 'astyle.cfg' //Do we need this? Need to double check if astyle is run before patches.
if (hasPatches) {
from('patches'){ into 'patches' }
}
from makeSRG
from makeExceptorConfig
from makeExceptorConfigOld //TODO: Remove? Make a Injector config file specifying the version?
from dumpOverrides
from dumpStatic
from fixAccessLevels
from makeExceptions
from file('constructors.txt')
//TODO: exceptor.json? I don't think we actually use this data.
rename { it.replace project.version+'_', '' }
}
tasks.makeZip.dependsOn makeSRG, makeExceptorConfigOld, dumpOverrides, dumpStatic, fixAccessLevels, makeExceptions
task makeCZip(type: Zip, dependsOn: ['makeZip', 'makeCSRG']) {
baseName = project.archivesBaseName
classifier = 'csrg'
version = project.version
destinationDir = file('build/distributions')
from(zipTree(makeZip.outputs.files.singleFile)){
exclude '**.srg'
}
from makeCSRG
rename { it.replace project.version+'_', '' }
}
task makeTZip(type: Zip, dependsOn: 'makeZip') {
baseName = project.archivesBaseName
classifier = 'tsrg'
version = project.version
destinationDir = file('build/distributions')
from(zipTree(makeZip.outputs.files.singleFile)){
exclude '**.srg'
}
from 'joined.tsrg'
rename { it.replace project.version+'_', '' }
}
artifacts {
archives makeZip
archives makeCZip
archives makeTZip
}
uploadArchives {
repositories.mavenDeployer {
dependsOn 'build'
if (project.hasProperty('forgeMavenPass'))
{
repository(url: "http://files.minecraftforge.net/maven/manage/upload") {
authentication(userName: project.getProperty('forgeMavenUsername'), password: project.getProperty('forgeMavenPass'))
}
}
else
{
repository(url: 'file://localhost/' + project.file('repo').getAbsolutePath())
}
pom {
groupId = project.group
version = project.version
artifactId = project.archivesBaseName
project {
name project.archivesBaseName
packaging 'jar'
description 'MCPConfig'
url 'https://github.com/MinecraftForge/MCPConfig'
}
}
}
}