forked from ReadyTalk/avian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
323 lines (267 loc) · 7.59 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
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.2.4'
}
}
apply plugin: 'native-component'
apply plugin: 'ivy-publish'
apply plugin: 'java'
apply plugin: 'artifactory-publish'
enum SupportedOS implements OperatingSystem {
LINUX, WINDOWS, MACOSX;
public static final SupportedOS CURRENT;
static {
String p = System.properties['os.name']
switch(p.replaceAll(' ', '').toLowerCase()) {
case ~/.*linux.*/: CURRENT = LINUX; break;
case ~/.*darwin.*/: CURRENT = MACOSX; break;
case ~/.*osx.*/: CURRENT = MACOSX; break;
case ~/.*win.*/: CURRENT = WINDOWS; break;
default:
String m = "SupportedOS: unrecognized platform: ${p}"
println(m)
throw new IllegalArgumentException(m)
}
}
public String getName() {
return toString().toLowerCase()
}
public String getDisplayName() {
return getName()
}
public boolean isCurrent() { return this == CURRENT }
public boolean isFreeBSD() { return false }
public boolean isLinux() { return this == LINUX }
public boolean isMacOsX() { return this == MACOSX }
public boolean isSolaris() { return false }
public boolean isWindows() { return this == WINDOWS }
}
public String adjustArch(String arch) {
switch(arch) {
case ~/.*64.*/: return 'x86_64'
default: return 'i386'
}
}
ext {
currentPlatform = SupportedOS.CURRENT.getName()
currentArch = adjustArch(System.properties['os.arch'])
currentPlatformArch = "${currentPlatform}-${currentArch}"
platform = project.hasProperty('platform') ? platform : currentPlatform
arch = project.hasProperty('arch') ? arch : currentArch
platformArch = "${platform}-${arch}"
java_home = System.properties.'java.home'
if(java_home.endsWith("/jre")) {
java_home = java_home.substring(0, java_home.length() - "/jre".length())
}
java_home = java_home
libDir = "${buildDir}/lib"
lzmaDir = "${libDir}/lzma"
buildOptions = ['', '-lzma']
}
repositories {
ivy {
name "ivyLocal"
url "${System.env.HOME}/.ivy2/local"
layout 'maven'
}
ivy {
name "jcenter"
if(version.contains("SNAPSHOT")) {
url "http://oss.jfrog.org/artifactory/oss-snapshot-local"
} else {
url "http://oss.jfrog.org/artifactory/oss-release-local"
}
layout 'maven'
}
}
configurations {
create('windows-i386')
create('windows-x86_64')
}
dependencies {
'windows-i386' "com.readytalk:win32:1.0.0-SNAPSHOT"
'windows-x86_64' "com.readytalk:win64:1.0.0-SNAPSHOT"
}
model {
platforms {
create(platformArch) {
operatingSystem SupportedOS.valueOf(platform.toUpperCase())
architecture "${arch}"
}
}
tasks {
buildOptions.each { buildOption ->
platforms.each { platform ->
if(platform.operatingSystem.name == "windows") {
def artifactName = platform.architecture.name == "i386" ? 'win32' : 'win64'
task "extract${platform.name}${buildOption}"(type: Copy) {
from {
tarTree(configurations."${platform.name}".find { it.name =~ artifactName })
}
into "${libDir}/tools"
}
}
task "build${platform.name}${buildOption}"(type: Exec) {
executable "make"
args "platform=${platform.operatingSystem.name}",
"arch=${platform.architecture.name}"
if(buildOption == "-lzma") {
dependsOn 'extractLzma'
args "lzma=${lzmaDir}"
}
if(platform.operatingSystem.name == "windows") {
dependsOn "extract${platform.name}${buildOption}"
args "win32=${libDir}/tools/win32",
"win64=${libDir}/tools/win64"
}
environment JAVA_HOME: java_home
}
assemble {
dependsOn "build${platform.name}${buildOption}"
}
}
}
}
}
tasks.withType(JavaCompile) {
sourceCompatibility = "1.6"
targetCompatibility = "1.6"
options.with {
encoding = "UTF-8"
bootClasspath = sourceSets.main.output.classesDir
}
}
sourceSets {
main {
java {
srcDir 'classpath'
}
}
}
javadoc {
title = "Avian v${version} Class Library API"
}
task javadocJar(type: Jar) {
dependsOn javadoc
classifier = 'javadoc'
from {
javadoc.destinationDir
}
}
jar {
baseName "classpath-avian"
}
task downloadLzma(type: Exec) {
commandLine "curl"
args "--create-dirs", "-o", "${lzmaDir}/lzma920.tar.bz2", "-f", "http://oss.readytalk.com/avian-web/lzma920.tar.bz2"
}
task extractLzma(type: Copy) {
dependsOn downloadLzma
from {
tarTree(resources.bzip2("${lzmaDir}/lzma920.tar.bz2"))
}
into lzmaDir
}
task install {
dependsOn assemble, publish
}
publishing {
repositories {
add(project.repositories."ivyLocal")
}
publications {
ivy(IvyPublication) {
from components.java
artifact(javadocJar)
artifact("vm.pro") {
name "vm"
type "proguard"
extension "pro"
}
module "classpath-avian"
}
create("tools-avian-${currentPlatformArch}", IvyPublication) {
module "tools-avian-${currentPlatformArch}"
def publishBinSuffix = currentPlatform == "windows" ? "exe" : "bin"
def binSuffix = currentPlatform == "windows" ? ".exe" : ""
artifact("${buildDir}/${currentPlatform}-${currentArch}/binaryToObject/binaryToObject${binSuffix}") {
name "binaryToObject"
type publishBinSuffix
extension publishBinSuffix
}
}
buildOptions.each { buildOption ->
platforms.each { platform ->
def binSuffix=""
def publishBinSuffix="bin"
create("${platform.name}${buildOption}", IvyPublication) {
def nativeBuildDir = "${buildDir}/${platform.operatingSystem.name}-${platform.architecture.name}${buildOption}"
if(platform.operatingSystem.name == "windows") {
publishBinSuffix = "exe"
binSuffix = ".${publishBinSuffix}"
}
module "runtime-avian${buildOption}-${platform.name}"
artifact("${nativeBuildDir}/avian${binSuffix}") {
name "avian"
type publishBinSuffix
extension publishBinSuffix
}
artifact("${nativeBuildDir}/libavian.a") {
name "libavian"
type "a"
extension "a"
}
if (buildOption == "-lzma") {
artifact("${nativeBuildDir}/libavian-lzma.a") {
name "libavian-lzma"
type "a"
extension "a"
}
artifact("${nativeBuildDir}/lzma/lzma${binSuffix}") {
name "lzma"
type publishBinSuffix
extension publishBinSuffix
}
}
}
}
}
}
}
artifactoryPublish {
onlyIf {
// TRAVIS_BRANCH reports master if it is a master build or a PR going to master
// TRAVIS_PULL_REQUEST reports false if not a pull request and the PR number if it is
System.env.'TRAVIS_BRANCH' == "master" && System.env.'TRAVIS_PULL_REQUEST' == "false"
}
dependsOn assemble
}
artifactory {
contextUrl = "http://oss.jfrog.org"
resolve {
repository {
repoKey = 'libs-releases'
}
}
publish {
repository {
repoKey = 'oss-snapshot-local'
username = System.env.BINTRAY_USER
password = System.env.BINTRAY_API_KEY
ivy {
ivyLayout = "[organisation]/[module]/[revision]/ivy-[revision].xml"
}
}
defaults {
platforms.each {
publications it.name
}
}
}
}
task wrapper(type: Wrapper) {
distributionUrl = 'http://services.gradle.org/distributions/gradle-2.0-bin.zip'
}