-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle
132 lines (108 loc) · 4.23 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
import org.apache.tools.ant.taskdefs.condition.Os
group 'net.labymod'
version '1.0'
ext.generatedHeadersDir = new File(buildDir, "generatedHeaders")
if(!ext.generatedHeadersDir.exists() && !ext.generatedHeadersDir.mkdirs()) {
throw new GradleException("Failed to create directory ${ext.generatedHeadersDir.absolutePath}")
}
ext.nativeBinariesDir = new File(buildDir, "nativeBinaries")
if(!ext.nativeBinariesDir.exists() && !ext.nativeBinariesDir.mkdirs()) {
throw new GradleException("Failed to create directory ${ext.nativeBinariesDir.absolutePath}")
}
def isExternalBuild = false
def ciBuild = project.hasProperty("CI") && Boolean.parseBoolean(project.property("CI").toString())
if(!project.hasProperty("nativeBinaryExternalDir")) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// WARNING, this assumes CMake uses visual studio
// For GCC or Clang the output should be $nativeBinariesDir/libopus-jni-native.dll
ext.nativeBinaries = Arrays.asList(new File(nativeBinariesDir, "Debug/opus-jni-native.dll"))
} else if (Os.isFamily(Os.FAMILY_MAC)) {
ext.nativeBinaries = Arrays.asList(new File(nativeBinariesDir, "libopus-jni-native.dylib"))
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
ext.nativeBinaries = Arrays.asList(new File(nativeBinariesDir, "libopus-jni-native.so"))
} else {
if (!project.hasProperty("nativeBinaryLibrary")) {
throw new GradleException("Unable to determine native output library, " +
"pass -PnativeBinaryLibrary=/path/to/native/binary to gradle")
} else {
ext.nativeBinaries = [new File(project.property("nativeBinaryLibrary").toString())]
}
}
} else {
def nativeBinaryExternalDir = file(project.property("nativeBinaryExternalDir").toString())
if(!nativeBinaryExternalDir.exists()) {
throw new GradleException("nativeBinaryExternalDir ${nativeBinaryExternalDir.absolutePath} does not exist")
}
ext.nativeBinaries = new ArrayList<File>()
for(def file in nativeBinaryExternalDir.listFiles()) {
println "Found native binary ${file.absolutePath}"
ext.nativeBinaries.add(file)
}
isExternalBuild = true
}
if(project.hasProperty("32bit")) {
ext.is32bit = true
} else {
ext.is32bit = false
}
project(":opus-jni-java").afterEvaluate { javaProject ->
project("opus-jni-native").afterEvaluate { nativeProject ->
nativeProject.tasks["build"].dependsOn(javaProject.tasks["compileJava"])
if(!isExternalBuild) {
javaProject.tasks["processResources"].dependsOn(nativeProject.tasks["build"])
}
}
}
def getExtension(File file) {
String fileName = file.getName()
if(fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) {
return fileName.substring(fileName.lastIndexOf(".") + 1)
} else {
return ""
}
}
def getPathWithoutExtension(File file) {
String fileName = file.getAbsolutePath()
if(fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) {
return fileName.substring(0, fileName.lastIndexOf("."))
} else {
return ""
}
}
def processBinary(File binary, boolean doMove) {
String extension = getExtension(binary)
String path = getPathWithoutExtension(binary)
File newPath = null
if(ext.is32bit) {
newPath = new File(path + "-32." + extension)
} else {
newPath = new File(path + "-64." + extension)
}
if(doMove) {
println "Moving ${binary.absolutePath} to ${newPath.absolutePath}"
binary.renameTo(newPath)
}
return newPath
}
if(ciBuild) {
def ciDir = file("ci")
if(!ciDir.exists() && !ciDir.mkdirs()) {
throw new GradleException("Failed to create directory ${ciDir.absolutePath}")
}
new File(ciDir, "binaries").withWriter {
for(File binary in ext.nativeBinaries) {
it.write(processBinary(binary, false).absolutePath)
}
}
def binaries = ext.nativeBinaries
task moveNativeBinaries {
doLast {
for (File binary in binaries) {
processBinary(binary, true)
}
}
}
project("opus-jni-native").afterEvaluate { nativeProject ->
nativeProject.tasks["build"].finalizedBy(moveNativeBinaries)
}
}