forked from babun/babun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.groovy
executable file
·167 lines (147 loc) · 4.92 KB
/
build.groovy
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
#!/usr/bin/env groovy
import static java.lang.System.*
import static java.lang.System.getenv
VERSION = new File("${getRoot()}/babun.version").text.trim()
TEN_MINUTES = 10
TWENTY_MINUTES = 20
execute()
def execute() {
log "EXEC"
checkArguments()
String mode = this.args[0]
if (mode == "clean") {
doClean()
} else if (mode == "cygwin") {
doCygwin()
} else if (mode == "package") {
doPackage()
} else if (mode == "release") {
doRelease()
}
log "FINISHED"
}
def checkArguments() {
if (this.args.length != 1 || !this.args[0].matches("clean|cygwin|package|release")) {
err.println "Usage: build.groovy <clean|cygwin|package|release>"
exit(-1)
}
}
def initEnvironment() {
File target = getTarget()
if (!target.exists()) {
target.mkdir()
}
}
def doClean() {
log "EXEC clean"
File target = getTarget()
if (target.exists()) {
if (!target.deleteDir()) {
throw new RuntimeException("Cannot delete targe folder")
}
}
}
def doPackage() {
log "EXEC package"
executeBabunPackages()
executeBabunCygwin()
executeBabunCore()
executeBabunDist()
}
def doCygwin() {
executeBabunPackages()
boolean downloadOnly=true
executeBabunCygwin(downloadOnly)
}
def doRelease() {
log "EXEC release"
doPackage()
executeRelease()
}
def executeBabunPackages() {
String module = "babun-packages"
log "EXEC ${module}"
if (shouldSkipModule(module)) return
File workingDir = new File(getRoot(), module);
String conf = new File(getRoot(), "${module}/conf/").absolutePath
String out = new File(getTarget(), "${module}").absolutePath
def command = ["groovy.bat", "packages.groovy", conf, out]
executeCmd(command, workingDir, TEN_MINUTES)
}
def executeBabunCygwin(boolean downloadOnly = false) {
String module = "babun-cygwin"
log "EXEC ${module}"
File workingDir = new File(getRoot(), module);
String input = workingDir.absolutePath
String repo = new File(getTarget(), "babun-packages").absolutePath
String out = new File(getTarget(), "${module}").absolutePath
String pkgs = new File(getRoot(), "babun-packages/conf/cygwin.x86.packages")
String downOnly = downloadOnly as String
println "Download only flag set to: ${downOnly}"
def command = ["groovy.bat", "cygwin.groovy", repo, input, out, pkgs, downOnly]
executeCmd(command, workingDir, TEN_MINUTES)
}
def executeBabunCore() {
String module = "babun-core"
log "EXEC ${module}"
if (shouldSkipModule(module)) return
File workingDir = new File(getRoot(), module);
String root = getRoot().absolutePath
String cygwin = new File(getTarget(), "babun-cygwin/cygwin").absolutePath
String out = new File(getTarget(), "${module}").absolutePath
String branch = getenv("babun_branch") ? getenv("babun_branch") : "release"
println "Taking babun branch [${branch}]"
def command = ["groovy.bat", "core.groovy", root, cygwin, out, branch]
executeCmd(command, workingDir, TEN_MINUTES)
}
def executeBabunDist() {
String module = "babun-dist"
log "EXEC ${module}"
if (shouldSkipModule(module)) return
File workingDir = new File(getRoot(), module);
String input = workingDir.absolutePath
String cygwin = new File(getTarget(), "babun-core/cygwin").absolutePath
String out = new File(getTarget(), "${module}").absolutePath
def command = ["groovy.bat", "dist.groovy", cygwin, input, out, VERSION]
executeCmd(command, workingDir, TEN_MINUTES)
}
def executeRelease() {
log "EXEC release"
assert getenv("bintray_user") != null
assert getenv("bintray_secret") != null
File artifact = new File(getTarget(), "babun-dist/babun-${VERSION}-dist.zip")
def args = ["groovy", "babun-dist/release/release.groovy", "babun", "babun-dist", VERSION,
artifact.absolutePath, getenv("bintray_user"), getenv("bintray_secret")]
executeCmd(args, getRoot(), TWENTY_MINUTES)
}
def shouldSkipModule(String module) {
File out = new File(getTarget(), module)
log "Checking if skip module ${module} -> folder ${out.absolutePath}"
if (out.exists()) {
log "SKIP ${module}"
return true
}
log "DO NOT SKIP ${module}"
return false
}
File getTarget() {
return new File(getRoot(), "target")
}
File getRoot() {
return new File(getClass().protectionDomain.codeSource.location.path).parentFile
}
def executeCmd(List<String> command, File workingDir, int timeout) {
ProcessBuilder processBuilder = new ProcessBuilder(command)
processBuilder.directory(workingDir)
Process process = processBuilder.start()
addShutdownHook { process.destroy() }
process.consumeProcessOutput(out, err)
process.waitForOrKill(timeout * 60000)
assert process.exitValue() == 0
}
def getReleaseScript() {
new File(getRoot(), "release.groovy")
}
def log(String msg) {
println "[${new Date()}] ${msg}"
}