-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
456 lines (375 loc) · 15.7 KB
/
build.gradle
File metadata and controls
456 lines (375 loc) · 15.7 KB
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
/*
* Bearsampp Prerequisites - Gradle Build Script
*
* This build script handles the build process for Bearsampp Prerequisites installer.
* Includes Visual C++ Redistributables and CaskaydiaCove Nerd Font.
*/
// ============================================================================
// PLUGINS
// ============================================================================
plugins {
id 'base'
}
// ============================================================================
// PROPERTIES AND CONFIGURATION
// ============================================================================
// Load build.properties
def buildPropsFile = file('build.properties')
if (!buildPropsFile.exists()) {
throw new GradleException("build.properties not found at: ${buildPropsFile.absolutePath}")
}
def buildProps = new Properties()
buildPropsFile.withInputStream { buildProps.load(it) }
// Prerequisites configuration from build.properties
ext.prereqRelease = buildProps.getProperty('prerequisites.release', '2025.7.31')
ext.prereqId = buildProps.getProperty('prerequisites.id', 'prerequisites')
ext.prereqName = buildProps.getProperty('prerequisites.name', 'Bearsampp Prerequisites Package')
ext.prereqSetupName = buildProps.getProperty('prerequisites.setupname', "Bearsampp-prerequisites-${prereqRelease}")
.replace('${prerequisites.release}', prereqRelease)
// Root/dev path configuration
def rootDir = file("${projectDir}/..").canonicalFile
def devPath = file("${rootDir}/dev")
// Define project paths
ext.projectBasedir = projectDir.absolutePath
ext.rootDirPath = rootDir.absolutePath
// Build base path resolution priority:
// 1) build.properties (build.path)
// 2) Environment variable BEARSAMPP_BUILD_PATH
// 3) Default to {root}/bearsampp-build
def buildPathFromProps = (buildProps.getProperty('build.path', '') ?: '').trim()
def buildPathFromEnv = System.getenv('BEARSAMPP_BUILD_PATH') ?: ''
def defaultBuildPath = "${rootDir}/bearsampp-build"
ext.buildBasePath = buildPathFromProps ? buildPathFromProps : (buildPathFromEnv ? buildPathFromEnv : defaultBuildPath)
// Verify dev directory exists
if (!devPath.exists()) {
throw new GradleException("Project 'dev' not found in ${devPath}")
}
println "Bearsampp dev found in ${devPath}"
// Build paths
ext.buildTmpPath = file("${buildBasePath}/tmp")
ext.prereqTmpPath = file("${buildTmpPath}/prerequisites")
ext.prereqDestPath = file("${buildBasePath}/prerequisites")
// Source paths
ext.prereqSrcPath = file("${projectDir}/src")
ext.prereqSetupPath = file("${projectDir}/setup")
ext.vcRedistPath = file("${prereqSrcPath}/vcredist_2015_2022")
// VC Redistributable URLs
ext.vcRedistX86Url = 'https://aka.ms/vs/17/release/vc_redist.x86.exe'
ext.vcRedistX64Url = 'https://aka.ms/vs/17/release/vc_redist.x64.exe'
ext.vcRedistX86File = file("${vcRedistPath}/vc_redist.x86.exe")
ext.vcRedistX64File = file("${vcRedistPath}/vc_redist.x64.exe")
// Inno Setup path (from dev/bin/lib)
// Note: Tool paths are available via rootProject.ext.innosetupCompiler when used as a subproject
ext.innosetupPath = file("${devPath}/bin/lib/innosetup")
ext.isccExe = file("${innosetupPath}/ISCC.exe")
// ============================================================================
// HELPER FUNCTIONS
// ============================================================================
/**
* Generate hash files for a file
*/
def generateHashFiles(File file) {
if (!file.exists()) {
throw new GradleException("File not found for hashing: ${file}")
}
println "Generating hash files..."
// Generate MD5
def md5File = new File("${file.absolutePath}.md5")
def md5Hash = calculateHash(file, 'MD5')
md5File.text = "${md5Hash} ${file.name}\n"
println " Created: ${md5File.name}"
// Generate SHA1
def sha1File = new File("${file.absolutePath}.sha1")
def sha1Hash = calculateHash(file, 'SHA-1')
sha1File.text = "${sha1Hash} ${file.name}\n"
println " Created: ${sha1File.name}"
// Generate SHA256
def sha256File = new File("${file.absolutePath}.sha256")
def sha256Hash = calculateHash(file, 'SHA-256')
sha256File.text = "${sha256Hash} ${file.name}\n"
println " Created: ${sha256File.name}"
// Generate SHA512
def sha512File = new File("${file.absolutePath}.sha512")
def sha512Hash = calculateHash(file, 'SHA-512')
sha512File.text = "${sha512Hash} ${file.name}\n"
println " Created: ${sha512File.name}"
}
/**
* Calculate hash for a file
*/
def calculateHash(File file, String algorithm) {
def digest = java.security.MessageDigest.getInstance(algorithm)
file.withInputStream { stream ->
def buffer = new byte[8192]
def bytesRead
while ((bytesRead = stream.read(buffer)) != -1) {
digest.update(buffer, 0, bytesRead)
}
}
return digest.digest().collect { String.format('%02x', it) }.join('')
}
// ============================================================================
// TASKS
// ============================================================================
// Task: Download VC Redistributables
tasks.register('downloadVcRedist') {
group = 'build'
description = 'Download Visual C++ Redistributables from Microsoft'
doLast {
println ""
println "=".multiply(70)
println "Downloading Visual C++ Redistributables"
println "=".multiply(70)
println ""
// Create vcredist directory if it doesn't exist
if (!vcRedistPath.exists()) {
vcRedistPath.mkdirs()
println "Created directory: ${vcRedistPath}"
}
// Download x86 redistributable
println "Downloading x86 redistributable..."
println " URL: ${vcRedistX86Url}"
println " Destination: ${vcRedistX86File}"
try {
def x86Url = new URL(vcRedistX86Url)
x86Url.openConnection().with { conn ->
conn.instanceFollowRedirects = true
conn.setRequestProperty('User-Agent', 'Mozilla/5.0')
conn.connect()
if (conn.responseCode == 200 || conn.responseCode == 302 || conn.responseCode == 301) {
vcRedistX86File.bytes = conn.inputStream.bytes
println " [SUCCESS] Downloaded: ${vcRedistX86File.name} (${(vcRedistX86File.size() / 1024 / 1024).toInteger()} MB)"
} else {
throw new GradleException("Failed to download x86 redistributable. HTTP ${conn.responseCode}")
}
}
} catch (Exception e) {
throw new GradleException("Error downloading x86 redistributable: ${e.message}")
}
// Download x64 redistributable
println "Downloading x64 redistributable..."
println " URL: ${vcRedistX64Url}"
println " Destination: ${vcRedistX64File}"
try {
def x64Url = new URL(vcRedistX64Url)
x64Url.openConnection().with { conn ->
conn.instanceFollowRedirects = true
conn.setRequestProperty('User-Agent', 'Mozilla/5.0')
conn.connect()
if (conn.responseCode == 200 || conn.responseCode == 302 || conn.responseCode == 301) {
vcRedistX64File.bytes = conn.inputStream.bytes
println " [SUCCESS] Downloaded: ${vcRedistX64File.name} (${(vcRedistX64File.size() / 1024 / 1024).toInteger()} MB)"
} else {
throw new GradleException("Failed to download x64 redistributable. HTTP ${conn.responseCode}")
}
}
} catch (Exception e) {
throw new GradleException("Error downloading x64 redistributable: ${e.message}")
}
println ""
println "=".multiply(70)
println "[SUCCESS] Visual C++ Redistributables downloaded successfully"
println "=".multiply(70)
}
}
// Task: Display build information
tasks.register('info') {
group = 'help'
description = 'Display build information and available tasks'
doLast {
println """
================================================================
Bearsampp Prerequisites - Build Information
================================================================
Prerequisites Configuration:
Release: ${prereqRelease}
ID: ${prereqId}
Name: ${prereqName}
Setup Name: ${prereqSetupName}
Paths:
Project: ${projectDir}
Dev: ${devPath}
Build Base: ${buildBasePath}
Build Tmp: ${buildTmpPath}
Prereq Tmp: ${prereqTmpPath}
Prereq Dest: ${prereqDestPath}
Source: ${prereqSrcPath}
Setup: ${prereqSetupPath}
Inno Setup: ${isccExe}
Available Tasks:
gradle info - Show this information
gradle release - Build prerequisites installer
gradle clean - Clean build artifacts
gradle verify - Verify build environment
Examples:
gradle release
gradle verify
================================================================
""".stripIndent()
}
}
// Task: Build prerequisites installer
tasks.register('release') {
group = 'build'
description = 'Build prerequisites installer with Inno Setup'
dependsOn 'downloadVcRedist'
doLast {
println ""
println "=".multiply(70)
println "Building Bearsampp Prerequisites ${prereqRelease}"
println "=".multiply(70)
println ""
// Verify Inno Setup exists
if (!isccExe.exists()) {
throw new GradleException("Inno Setup not found at: ${isccExe}")
}
println "Using Inno Setup: ${isccExe}"
println ""
// Clean and create temp directory
println "Preparing build directory..."
if (prereqTmpPath.exists()) {
delete prereqTmpPath
}
prereqTmpPath.mkdirs()
// Copy source files
println "Copying source files..."
def tmpSrcPath = file("${prereqTmpPath}/src")
tmpSrcPath.mkdirs()
copy {
from prereqSrcPath
into tmpSrcPath
}
// Copy setup files
println "Copying setup files..."
copy {
from prereqSetupPath
into prereqTmpPath
exclude 'setup.iss'
}
// Process setup.iss with token replacement
println "Processing setup.iss..."
def setupIssTemplate = file("${prereqSetupPath}/setup.iss")
def setupIssOutput = file("${prereqTmpPath}/setup.iss")
def setupContent = setupIssTemplate.text
setupContent = setupContent.replace('@PREREQ_RELEASE@', prereqRelease)
setupContent = setupContent.replace('@PREREQ_ID@', prereqId)
setupContent = setupContent.replace('@PREREQ_NAME@', prereqName)
setupIssOutput.text = setupContent
// Create destination directory
prereqDestPath.mkdirs()
// Build installer with Inno Setup
println ""
println "Building installer with Inno Setup..."
println ""
def command = [
isccExe.absolutePath,
"/O${prereqDestPath.absolutePath}",
"/F${prereqSetupName}",
setupIssOutput.absolutePath
]
def process = new ProcessBuilder(command as String[])
.directory(prereqTmpPath)
.redirectErrorStream(true)
.start()
process.inputStream.eachLine { line ->
if (line.trim()) println " ${line}"
}
def exitCode = process.waitFor()
if (exitCode != 0) {
throw new GradleException("Inno Setup compilation failed with exit code: ${exitCode}")
}
// Generate hash files
def installerFile = file("${prereqDestPath}/${prereqSetupName}.exe")
if (!installerFile.exists()) {
throw new GradleException("Installer not found: ${installerFile}")
}
println ""
generateHashFiles(installerFile)
println ""
println "=".multiply(70)
println "[SUCCESS] Prerequisites installer built successfully"
println "Output: ${installerFile}"
println "=".multiply(70)
}
}
// Task: Clean build artifacts
tasks.named('clean') {
group = 'build'
description = 'Clean build artifacts and temporary files'
doLast {
// Clean Gradle build directory
def buildDir = file("${projectDir}/build")
if (buildDir.exists()) {
delete buildDir
}
// Clean temp build directory
if (prereqTmpPath.exists()) {
delete prereqTmpPath
}
println "[SUCCESS] Build artifacts cleaned"
}
}
// Task: Verify build environment
tasks.register('verify') {
group = 'verification'
description = 'Verify build environment and dependencies'
doLast {
println "Verifying build environment for prerequisites..."
def checks = [:]
// Check Java version
def javaVersion = JavaVersion.current()
checks['Java 8+'] = javaVersion >= JavaVersion.VERSION_1_8
// Check required files
checks['build.properties'] = file('build.properties').exists()
checks['src directory'] = prereqSrcPath.exists()
checks['setup directory'] = prereqSetupPath.exists()
checks['setup.iss'] = file("${prereqSetupPath}/setup.iss").exists()
// Check dev directory
checks['dev directory'] = file(devPath).exists()
// Check Inno Setup
checks['Inno Setup'] = isccExe.exists()
// Check for font file
def fontFile = file("${prereqSrcPath}/fonts/CaskaydiaCoveNerdFont-Regular.ttf")
checks['CaskaydiaCove Nerd Font'] = fontFile.exists()
// Note: VC++ Redistributables are now downloaded dynamically from Microsoft
checks['VC++ Redist (Dynamic Download)'] = true
println "\nEnvironment Check Results:"
println "-".multiply(60)
checks.each { name, passed ->
def status = passed ? "[PASS]" : "[FAIL]"
println " ${status.padRight(10)} ${name}"
}
println "-".multiply(60)
def allPassed = checks.values().every { it }
if (allPassed) {
println "\n[SUCCESS] All checks passed! Build environment is ready."
println "\nYou can now run:"
println " gradle release - Build prerequisites installer"
} else {
println "\n[WARNING] Some checks failed. Please review the requirements."
if (!checks['Inno Setup']) {
println "\nInno Setup not found at: ${isccExe}"
}
if (!checks['CaskaydiaCove Nerd Font']) {
println "\nCaskaydiaCove Nerd Font not found."
println "Download from: https://github.com/ryanoasis/nerd-fonts/releases/latest"
println "Place CaskaydiaCoveNerdFont-Regular.ttf in: ${prereqSrcPath}/fonts/"
}
throw new GradleException("Build environment verification failed")
}
}
}
// ============================================================================
// BUILD LIFECYCLE HOOKS
// ============================================================================
gradle.taskGraph.whenReady { graph ->
println """
================================================================
Bearsampp Prerequisites - Gradle Build
================================================================
""".stripIndent()
}
// ============================================================================
// DEFAULT TASK
// ============================================================================
defaultTasks 'info'