-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.gradle
237 lines (198 loc) · 8.08 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
buildscript{
dependencies{
classpath "com.github.Anuken.Arc:arc-core:$arcVersion"
}
repositories{
// Necessary Maven repositories for build script classpath.
mavenCentral()
maven{url 'https://www.jitpack.io'}
maven{url 'https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository'}
}
}
import arc.files.*
import arc.graphics.*
import arc.struct.*
import arc.util.*
import arc.util.io.*
import arc.util.serialization.*
import groovy.transform.*
import java.util.concurrent.*
configure(allprojects){
apply plugin: 'java'
// Main source directory.
sourceSets.main.java.srcDirs = ['src/']
dependencies{
// Downgrade Java 9+ syntax into being available in Java 8.
annotationProcessor "com.github.GlennFolker.EntityAnno:downgrader:$entVersion"
}
repositories{
// Necessary Maven repositories to pull the dependencies.
mavenCentral()
maven{url 'https://www.jitpack.io'}
maven{url 'https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository'}
}
// Use Java 17 syntax, but target Java 8 bytecode version.
tasks.withType(JavaCompile).configureEach{
sourceCompatibility = JavaVersion.current().ordinal() - JavaVersion.VERSION_17.ordinal() + 17
options.release.set 8
options.compilerArgs << '-Xlint:-options'
options.incremental = true
options.encoding = 'UTF-8'
}
// Force Arc version to be the same.
configurations.configureEach{
resolutionStrategy.eachDependency{
if(requested.group == 'com.github.Anuken.Arc'){
useVersion arcVersion
}
}
}
}
@CompileStatic
void fetchSprites(final String mindustryVersion, final File baseDir){
final Queue<Runnable> runs = new Queue<>()
Http.get("https://api.github.com/repos/Anuken/Mindustry/contents/core/assets-raw/sprites/units?ref=$mindustryVersion")
.timeout(0)
.error{throw new RuntimeException(it)}
.block{response(baseDir, runs, it)}
logger.lifecycle "Fetching $runs.size unit sprites."
final def exec = Threads.executor('Sprites-Fetcher', OS.cores)
final Queue<Future<?>> fetches = new Queue<>()
while(!runs.isEmpty()){
def run = runs.removeFirst()
fetches.addLast(exec.submit(run))
}
while(!fetches.isEmpty()) Threads.await(fetches.removeFirst())
Threads.await(exec)
}
@CompileStatic
void response(final File dir, final Queue<Runnable> runs, final Http.HttpResponse res){
final def list = Jval.read(res.resultAsString).asArray()
for(final def val : list){
final def name = val.getString('name')
switch(val.getString('type')){
case 'file':
if(name.endsWith('.png')){
final def url = val.getString('download_url')
runs.addLast({
Http.get(url)
.timeout(0)
.error{throw new RuntimeException(it)}
.block{
final def image = new Pixmap(Streams.copyBytes(it.resultAsStream))
new Fi(file("$dir/$name")).writePng(image)
image.dispose()
}
})
}
break
case 'dir':
Http.get(val.getString('url'))
.timeout(0)
.error{throw new RuntimeException(it)}
.block{response(file("$dir/$name"), runs, it)}
break
}
}
}
configure(project(':proc')){
tasks.register('fetchSprites'){
final def fetchOutputProv = layout.buildDirectory.dir('fetched')
doFirst{
def fetchOutput = fetchOutputProv.get().asFile
fetchOutput.deleteDir()
fetchOutput.mkdir()
fetchSprites(mindustryVersion, fetchOutput)
file("$fetchOutput/cache.txt").text = mindustryVersion
}
outputs.dir fetchOutputProv
outputs.upToDateWhen{
def fetchOutput = fetchOutputProv.get().asFile
def cache = file("$fetchOutput/cache.txt")
cache.exists() && cache.text == mindustryVersion
}
}
tasks.register('genSprites', JavaExec){
dependsOn fetchSprites, configurations.runtimeClasspath
final def genOutputProv = layout.buildDirectory.dir('output')
final def fetchSpritesProv = layout.buildDirectory.dir('fetched')
mainClass = 'lights.gen.Generator'
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = genOutputProv.map{it.dir('sprites').dir('units')}
doFirst{
def genOutput = genOutputProv.get().dir('sprites').dir('units').asFile
genOutput.deleteDir()
genOutput.mkdirs()
args fetchSpritesProv.get().asFile
}
doLast{
def genOutput = genOutputProv.get().asFile
file("$genOutput/cache.txt").text = mindustryVersion
}
outputs.dir genOutputProv
outputs.upToDateWhen{
def genOutput = genOutputProv.get().asFile
def cache = file("$genOutput/cache.txt")
cache.exists() && cache.text == mindustryVersion
}
}
dependencies{
// Depend on Mindustry/Arc classpath.
implementation "com.github.Anuken.Mindustry:core:$mindustryVersion"
implementation "com.github.Anuken.Arc:arc-core:$arcVersion"
implementation "com.github.Anuken.Arc:natives-desktop:$arcVersion"
}
}
configure(rootProject){
jar{
inputs.files project(':proc').tasks.genSprites
archiveFileName = "${rootProject.name}-Desktop.jar"
from files(sourceSets.main.output.classesDirs)
from files(sourceSets.main.output.resourcesDir)
from configurations.runtimeClasspath.collect{it.isDirectory() ? it : zipTree(it)}
from(layout.projectDirectory){
include 'mod.json'
include 'icon.png'
}
from files(layout.projectDirectory.dir('assets'))
from files(project(':proc').layout.buildDirectory.dir('output')){
exclude 'cache.txt'
}
}
tasks.register('dex', Jar){
inputs.files tasks.jar
archiveFileName = "${rootProject.name}.jar"
final def desktopJar = tasks.jar.archiveFile
final def dexJar = file("$temporaryDir/Dexed.jar")
from zipTree(desktopJar), zipTree(dexJar)
doFirst{
def sdkRoot = file(
System.getenv('ANDROID_SDK_ROOT') ?: System.getenv('ANDROID_HOME') ?:
{ throw new GradleException('Neither `ANDROID_SDK_ROOT` nor `ANDROID_HOME` is set') }
)
def d8 = file("$sdkRoot/build-tools/$androidBuildVersion/d8")
if(!d8.exists()){
throw new GradleException("Android SDK `build-tools;$androidBuildVersion` isn't installed or is corrupted")
}
def input = desktopJar.get().asFile
def command = "$d8 --release --min-api $androidMinVersion --output $dexJar $input"
(configurations.compileClasspath.asList() + configurations.runtimeClasspath.asList()).forEach{
if(it.exists()) command = "$command --classpath $it"
}
def androidJar = file("$sdkRoot/platforms/android-$androidSdkVersion/android.jar")
if(!androidJar.exists()){
throw new GradleException("Android SDK `platforms;android-$androidSdkVersion` isn't installed or is corrupted")
}
command = "$command --lib $androidJar"
if(OS.isWindows) command = "cmd /c $command"
logger.log(LogLevel.LIFECYCLE, 'Running `d8`.')
command.execute(null, layout.projectDirectory.asFile).waitForProcessOutput(System.out, System.err)
}
}
dependencies{
// Depend on Mindustry/Arc classpath.
compileOnly "com.github.Anuken.Mindustry:core:$mindustryVersion"
compileOnly "com.github.Anuken.Arc:arc-core:$arcVersion"
}
}