-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
325 lines (286 loc) · 12.5 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
324
325
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
id 'maven'
}
repositories {
mavenLocal()
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.8.9'
}
version = '0.14.0-beta-2'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
test {
useJUnitPlatform()
systemProperty "file.encoding", "utf-8"
}
sourceSets {
main {
resources {
if (OperatingSystem.current().isLinux() ||
OperatingSystem.current().isMacOsX() ||
OperatingSystem.current().isUnix()) {
srcDirs "src/main/resources", "build/natives/lib/Release", "build/natives/downloads"
} else if (OperatingSystem.current().isWindows()) {
srcDirs "src/main/resources", "build/natives/bin/Release", "build/natives/downloads"
}
}
}
}
compileJava {
if (OperatingSystem.current().isLinux()) {
def armJavacPath = ""
def armJavaPath = ""
def armJdkPath = ""
if (project.hasProperty('armJdkPath')) {
armJdkPath = project.getProperties()['armJdkPath'] as String
armJavacPath = file(armJdkPath + '/bin/javac').absolutePath
armJavaPath = file(armJdkPath + '/bin/java').absolutePath
}
def modifiedJavacFile = new File('armjavac.sh')
def modifiedJavaFile = new File('armjava.sh')
def qemuCommand = ""
if (project.hasProperty("aarch64Build")) {
qemuCommand = 'qemu-aarch64 -L /usr/aarch64-linux-gnu/ '
} else if (project.hasProperty("aarch32Build")) {
qemuCommand = 'qemu-arm -L /usr/arm-linux-gnueabihf/ '
}
if (project.hasProperty("aarch64Build") || project.hasProperty("aarch32Build")) {
if (armJdkPath.isEmpty()) {
throw new InvalidUserDataException("ARM JDK path not provided.\n" +
"Specify the ARM JDK path like this: -ParmJdkPath=<jdk-path>")
}
modifiedJavacFile.withWriter {
writer -> writer.writeLine qemuCommand + armJavacPath + ' "$@"'
}
modifiedJavacFile.setExecutable(true)
modifiedJavaFile.withWriter {
writer -> writer.writeLine qemuCommand + armJavaPath + ' "$@"'
}
modifiedJavaFile.setExecutable(true)
project.logger.info(qemuCommand + armJavaPath + ' "$@"')
if (modifiedJavacFile.exists() && modifiedJavaFile.exists()) {
options.forkOptions.executable = file(modifiedJavacFile.path).absolutePath
test.executable = file(modifiedJavaFile.path).absolutePath
}
}
}
System.setProperty("user.dir", project.projectDir.toString())
options.compilerArgs += ["-h", file("src/main/include")]
options.encoding = "UTF-8"
}
task compileJNI {
dependsOn compileJava
outputs.upToDateWhen { false }
doLast {
def nativeDir = new File(project.projectDir.toString() + '/build/natives')
if (!nativeDir.exists()) {
nativeDir.mkdirs()
}
String architecture = ""
// determine CPU architecture name and windows generator name
String generator = ""
String osArch = System.getProperty("os.arch")
if (osArch in ["arm", "aarch32"] || project.hasProperty("aarch32Build")) {
architecture = "aarch32"
generator = "ARM"
} else if (osArch in ["arm64", "aarch64"] || project.hasProperty("aarch64Build")) {
architecture = "aarch64"
generator = "ARM64"
} else if (osArch.endsWith("86")) {
architecture = "x86"
generator = "Win32"
} else if (osArch in ["amd64", "x86_64"]) {
architecture = "amd64"
generator = "x64"
}
String buildConcurrency = "-j " + Runtime.getRuntime().availableProcessors().toString()
// this property will not be used for android builds, as android builds use ninja instead of make
if (project.hasProperty("j")) {
buildConcurrency = "-j " + project['j'].toString()
}
if (OperatingSystem.current().isLinux()) {
if (project.hasProperty("androidBuild") && project.hasProperty("androidSDKPath")) {
invokeAndroidBuild(nativeDir) // ANDROID BUILD
} else if (project.hasProperty("androidBuild") || project.hasProperty("androidSDKPath")) {
throw new GradleException("Both properties, androidBuild and androidSDKPath need to be defined.")
} else { // LINUX BUILD
invokeLinuxBuild(nativeDir, architecture, buildConcurrency)
}
} else if (OperatingSystem.current().isMacOsX()) { // MAC OS BUILD
invokeMacOSBuild(nativeDir, architecture, buildConcurrency)
} else if (OperatingSystem.current().isWindows()) { // WINDOWS BUILD
invokeWindowsBuild(nativeDir, architecture, generator, buildConcurrency)
} else {
throw new GradleException(String.format("Operating System not supported: %s", OperatingSystem.current().getName()))
}
}
}
def invokeAndroidBuild(File nativeDir) {
def androidArchitectures = ["arm64-v8a", "x86_64", "armeabi-v7a", "x86"] as String[]
def androidSDKPath = project.getProperties()['androidSDKPath'].toString()
logger.info(String.format("Executing Android build. Architectures: %s", Arrays.toString(androidArchitectures)))
for (arch in androidArchitectures) {
exec {
commandLine 'cmake', '-B' + nativeDir.getPath(), '-S.', '-GNinja', '-DANDROID_ABI=' + arch, '-DANDROID_NDK=' + androidSDKPath + '/ndk/22.0.7026061', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_MAKE_PROGRAM=' + androidSDKPath + '/cmake/3.10.2.4988404/bin/ninja', '-DCMAKE_TOOLCHAIN_FILE=' + androidSDKPath + '/ndk/22.0.7026061/build/cmake/android.toolchain.cmake', '-DANDROID_NATIVE_API_LEVEL=23', '-DANDROID_TOOLCHAIN=clang'
}
exec {
commandLine 'cmake', '--build', nativeDir.getPath(), '--config', 'Release'
}
exec {
commandLine 'rm', nativeDir.getPath() + '/CMakeCache.txt'
}
renamePlatformArtifactsDirectoryAccordingToArchitecture(nativeDir, arch)
}
}
def invokeMacOSBuild(File nativeDir, String architecture, String buildConcurrency) {
logger.info(String.format("Executing macOS build. Architecture: %s", architecture))
exec {
commandLine 'cmake', '-B' + nativeDir.getPath(), '-S.'
}
exec {
commandLine 'cmake', '--build', nativeDir.getPath(), '--config', 'Release', buildConcurrency
}
renamePlatformArtifactsDirectoryAccordingToArchitecture(nativeDir, architecture)
}
def invokeLinuxBuild(File nativeDir, String architecture, String buildConcurrency) {
logger.info(String.format("Executing Linux build. Architecture: %s", architecture))
def isCMakeToolchainFileRequired = architecture in ["aarch64", "aarch32", "x86"] || project.hasProperty("aarch64Build") || project.hasProperty("aarch32Build")
def cmakeToolchain = ""
if (isCMakeToolchainFileRequired) {
cmakeToolchain = "-DCMAKE_TOOLCHAIN_FILE=./linux-" + architecture + "-toolchain.cmake"
}
exec {
commandLine 'cmake', '-B' + nativeDir.getPath(), '-S.', cmakeToolchain
}
exec {
commandLine 'cmake', '--build', nativeDir.getPath(), '--config', 'Release', buildConcurrency
}
renamePlatformArtifactsDirectoryAccordingToArchitecture(nativeDir, architecture)
}
def invokeWindowsBuild(File nativeDir, String architecture, String generator, String buildConcurrency) {
logger.info(String.format("Executing Windows build. Architecture: %s", architecture))
exec {
commandLine 'cmake', '-B' + nativeDir.getPath(), '-S.', '-A', generator
}
exec {
commandLine 'cmake', '--build', nativeDir.getPath(), '--config', 'Release', buildConcurrency
}
renamePlatformArtifactsDirectoryAccordingToArchitecture(nativeDir, architecture)
}
def renamePlatformArtifactsDirectoryAccordingToArchitecture(File nativeDir, String architecture) {
def platformArtifactsDirectoryPath = ""
def artifactsDirectoryPath = "lib/Release/"
// determine path for directory created after cmake build, eg: build/natives/lib/Release/Linux
if (OperatingSystem.current().isLinux()) {
if (project.hasProperty("androidBuild") && project.hasProperty("androidSDKPath")) {
platformArtifactsDirectoryPath = artifactsDirectoryPath + "Android"
} else {
platformArtifactsDirectoryPath = artifactsDirectoryPath + "Linux"
}
} else if (OperatingSystem.current().isWindows()) {
platformArtifactsDirectoryPath = "bin/Release/Windows"
} else {
// do not rename artifacts directory for OSes other than windows & linux
return
}
def platformArtifactsDirectory = new File(nativeDir, platformArtifactsDirectoryPath)
System.out.println(platformArtifactsDirectory.getPath())
// determine renamed path, including the architecture for the build, eg: build/natives/lib/Release/Linux-amd64
def architectureArtifactsDirectoryPath = ""
if (OperatingSystem.current().isLinux() && project.hasProperty("androidBuild") && project.hasProperty("androidSDKPath")) {
// naming pattern for android is different, eg: build/natives/lib/Release/arm64-v8a
// so, handle that separately
architectureArtifactsDirectoryPath = artifactsDirectoryPath + architecture
} else {
architectureArtifactsDirectoryPath = platformArtifactsDirectoryPath + "-" + architecture
}
def architectureArtifactsDirectory = new File(nativeDir, architectureArtifactsDirectoryPath)
// if build has been rerun, delete the existing artifacts
if (architectureArtifactsDirectory.exists()) {
architectureArtifactsDirectory.deleteDir()
}
// rename the directory created after cmake build to include architecture in the directory name
if (platformArtifactsDirectory.exists()) {
platformArtifactsDirectory.renameTo(architectureArtifactsDirectory)
}
}
clean.doFirst {
delete fileTree('src/main/include') {
include 'io_opentimeline_*.h'
}
}
processResources {
dependsOn compileJNI
}
tasks.withType(Test) {
if (OperatingSystem.current().isLinux()) {
systemProperty "java.library.path", "build/natives/lib/Release/Linux"
} else if (OperatingSystem.current().isMacOsX()) {
systemProperty "java.library.path", "build/natives/lib/Release/Darwin"
} else if (OperatingSystem.current().isWindows()) {
systemProperty "java.library.path", "build\\natives\\bin\\Release\\Windows"
}
testLogging.showStandardStreams = false
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
javadoc.failOnError = false
javadoc {
options.overview = "overview.html" // relative to source root
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
task createPom {
pom {
project {
groupId 'io.opentimeline'
artifactId 'opentimelineio'
version version.toString()
description 'OpenTimelineIO is an interchange format and API for editorial cut information. OTIO is not a container format for media, rather it contains information about the order and length of cuts and references to external media.'
url 'opentimeline.io'
name 'OpenTimelineIO'
licenses {
license {
name "Modified Apache 2.0 License"
url "https://github.com/PixarAnimationStudios/OpenTimelineIO/blob/master/LICENSE.txt"
distribution "repo"
}
}
developers {
developer {
id "OpenTimelineIO"
name "Contributors to the OpenTimelineIO project"
email "otio-discussion@lists.aswf.io"
}
}
scm {
url "https://github.com/PixarAnimationStudios/OpenTimelineIO"
}
}
}.writeTo("build/pom/opentimelineio-" + version.toString() + ".pom")
}