This repository has been archived by the owner on Aug 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Rakefile
292 lines (223 loc) · 7.65 KB
/
Rakefile
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
require 'time'
require 'rake/clean'
require_relative 'version'
require_relative 'utils'
BASE = "base"
WORK = "work"
CACHE = "cache"
TEMP = "temp"
BUILD = "build"
SNAPSHOT = "snapshot"
CB_BASE = "#{BASE}/CraftBukkit"
CB_WORK = "#{WORK}/CraftBukkit"
DATA = "builddata"
SPECIAL_SOURCE = "#{DATA}/bin/SpecialSource.jar"
SPECIAL_SOURCE_2 = "#{DATA}/bin/SpecialSource-2.jar"
FERNFLOWER = "#{DATA}/bin/fernflower.jar"
CLASS_MAPPINGS = "#{DATA}/mappings/bukkit-#{NMS_VERSION}-cl.csrg"
MEMBER_MAPPINGS = "#{DATA}/mappings/bukkit-#{NMS_VERSION}-members.csrg"
ACCESS_MAPPINGS = "#{DATA}/mappings/bukkit-#{NMS_VERSION}.at"
PACKAGE_MAPPINGS = "#{DATA}/mappings/package.srg"
CLASS_JAR = "#{TEMP}/cl.jar"
MEMBER_JAR = "#{TEMP}/member.jar"
REMAPPED_JAR = "#{TEMP}/mapped.jar"
NMS_CLASSES = "#{TEMP}/classes"
NMS_SRC = "#{WORK}/nms-src"
FORCE = ARGV.include?('--force')
# BuildData
task :init => "data:init"
namespace :data do
desc "Prepare BuildData submodule"
task :init => DATA
Git::Rake.repo DATA do
Git.submodule_update DATA
end
end
# Bukkit/CraftBukkit
directory BUILD
def modular_tasks(id:, name:, artifact:, work: nil)
base = File.join(BASE, name)
work ||= base
work_abs = File.absolute_path(work)
patches = name
patch_list = "#{name}-patches"
patch_list_abs = File.absolute_path(patch_list)
patches_abs = File.absolute_path(patches)
patches_glob = File.join(patches, "*.patch")
build = File.join(BUILD, name)
jar = File.join(build, "target", "#{artifact}-#{NMS_VERSION}-R0.1-SNAPSHOT.jar")
snapshot = File.join(SNAPSHOT, name)
snapshot_nms = File.join(snapshot, "nms-patches")
patched = -> { Dir.chdir(build) { "SportBukkit" == Git.head_commit_message } }
CLEAN.include(File.join(build, "target"))
task :default => jar
desc "Prepare submodules"
task :init => "#{id}:init"
desc "Apply patches"
task :apply => "#{id}:apply"
desc "Compile everything"
task :compile => "#{id}:compile"
desc "Deploy everything"
task :deploy => "#{id}:deploy"
desc "Generate patches"
task :generate => "#{id}:generate"
desc "Update snapshot"
task :snapshot => "#{id}:snapshot"
namespace id do
desc "Prepare #{name} submodule"
task :init => base
Git::Rake.repo base do
Git.submodule_update base
Dir.chdir base do
Git.branch "upstream"
end
end
Git::Rake.repo build => work do
Git.clone from: work, to: build
end
desc "Apply patches to #{name}"
task :apply => [work, build] do
Dir.chdir build do
Git.remote_add remote: "upstream", url: work_abs
Git.assert_clean_work_tree
Git.reset remote: "upstream", branch: "upstream"
Git.apply_patches dir: patches_abs,
list: patch_list_abs
end
end
desc "Compile #{name}"
task :compile => [:compile_clean, jar]
task :compile_clean do
clean jar
end
file jar => build do
unless patched[]
Rake::Task["#{id}:apply"].invoke
end
Dir.chdir build do
info "Compiling #{build}"
maven :clean, :install
end
end
desc "Deploy #{name}"
task :deploy => jar do
Dir.chdir build do
info "Deploying #{build}"
maven :deploy
end
end
desc "Generate patches for #{name}"
task :generate => build do
complete = patched[]
if complete
info "Generating complete patch set for #{name}"
sh "rm #{patches_glob}"
else
info "Generating partial patch set for #{name}"
end
Dir.chdir build do
Git.generate_patches from: "upstream/upstream",
dir: patches_abs,
list: patch_list_abs
end
sh "git", "add", patch_list
sh "git", "add", "--all", patches
if complete
Rake::Task["#{id}:snapshot"].execute
end
end
desc "Update snapshot for #{name}"
task :snapshot => build do
unless patched[]
error "Cannot update snapshot because #{name} is not fully patched"
end
info "Updating snapshot in #{snapshot}"
Git.export from: build, to: snapshot
if File.exists? snapshot_nms
nms_src = File.absolute_path(NMS_SRC)
Dir.chdir snapshot do
sh "./makePatches.sh", nms_src
sh "rm -rf src/main/java/net/minecraft"
sh "rmdir src/main/java/net" do |ok, res| end
end
end
sh "git", "add", "--all", snapshot
end
end
end
modular_tasks id: "bukkit",
name: "Bukkit",
artifact: "sportbukkit-api"
modular_tasks id: "cb",
name: "CraftBukkit",
artifact: "sportbukkit",
work: File.join(WORK, "CraftBukkit")
# Deobfuscate/Decompile
[WORK, CACHE, TEMP].each{|f| CLEAN.include(f) }
directory WORK
directory CACHE
directory TEMP
directory NMS_CLASSES
directory NMS_SRC
desc "Deobfuscate NMS classes"
task :deobf => [:deobf_clean, REMAPPED_JAR]
task :deobf_clean do
clean CLASS_JAR, MEMBER_JAR, REMAPPED_JAR
end
file REMAPPED_JAR => [DATA, CACHE, TEMP] do
download(file: NMS_JAR, url: NMS_URL, md5: NMS_MD5)
info "Creating cl-mapped jar"
sh "java", "-jar", SPECIAL_SOURCE_2, "map",
"-i", NMS_JAR,
"-m", CLASS_MAPPINGS,
"-o", CLASS_JAR
info "Creating member-mapped jar"
sh "java", "-jar", SPECIAL_SOURCE_2, "map",
"-i", CLASS_JAR,
"-m", MEMBER_MAPPINGS,
"-o", MEMBER_JAR
info "Creating final mapped jar"
sh "java", "-jar", SPECIAL_SOURCE,
"--kill-lvt",
"-i", MEMBER_JAR,
"--access-transformer", ACCESS_MAPPINGS,
"-m", PACKAGE_MAPPINGS,
"-o", REMAPPED_JAR
info "Installing in Maven repository"
sh "mvn", "install:install-file",
"-Dfile=#{REMAPPED_JAR}",
"-Dpackaging=jar",
"-DgroupId=org.spigotmc",
"-DartifactId=minecraft-server",
"-Dversion=#{NMS_VERSION}-SNAPSHOT"
end
desc "Decompile NMS classes"
task :decompile => [:decompile_clean, NMS_SRC]
task :decompile_clean do
clean NMS_CLASSES, NMS_SRC
end
file NMS_SRC => REMAPPED_JAR do
info "Extracting NMS classes"
sh "unzip", "-q", REMAPPED_JAR, "net/minecraft/server/*", "-d", NMS_CLASSES
info "Decompiling NMS classes"
sh "java", "-jar", FERNFLOWER,
"-dgs=1", "-hdc=0", "-asc=1", "-udv=0",
NMS_CLASSES, NMS_SRC
end
desc "Apply CraftBukkit patches to NMS source"
task :craftbukkit => [:craftbukkit_clean, CB_WORK]
task :craftbukkit_clean do
clean CB_WORK
end
Git::Rake.repo CB_WORK => [CB_BASE, NMS_SRC] do
Git.clone from: CB_BASE, to: CB_WORK
info "Applying CraftBukkit patches"
Dir.chdir CB_WORK do
sh "git checkout upstream"
sh "git fetch origin upstream"
sh "git reset --hard origin/upstream"
sh "bash applyPatches.sh ../nms-src"
sh "git add src/main/java/net/minecraft/server/*"
sh "git", "commit", "-m", "CraftBukkit #{Time.now.utc.iso8601}"
end
end