/
build.gradle
109 lines (100 loc) · 2.9 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
import org.robolectric.gradle.DeployedRoboJavaModulePlugin
import org.robolectric.gradle.RoboJavaModulePlugin
apply plugin: RoboJavaModulePlugin
apply plugin: DeployedRoboJavaModulePlugin
static def osName() {
def osName = System.getProperty("os.name").toLowerCase(Locale.US);
if (osName.contains("linux")) {
return "linux"
} else if (osName.contains("mac")) {
return "mac"
} else if (osName.contains("win")) {
return "windows"
}
return "unknown"
}
static def arch() {
def arch = System.getProperty("os.arch").toLowerCase(Locale.US);
if (arch.equals("x86_64") || arch.equals("amd64")) {
return "x86_64"
}
return arch
}
task cmakeNativeRuntime {
doLast {
mkdir "$buildDir/cpp"
exec {
workingDir "$buildDir/cpp"
commandLine 'cmake', "-B", ".", "-S","$projectDir/cpp/", "-G", "Ninja"
}
}
}
task configureICU {
onlyIf { !System.getenv('ICU_ROOT_DIR') }
doLast {
def os = osName()
if (!file("$projectDir/external/icu/icu4c/source").exists()) {
throw new GradleException("ICU submodule not detected. Please run `git submodule update --init`")
}
if (file("$projectDir/external/icu/icu4c/source/Makefile").exists()) {
println("ICU Makefile detected, skipping ICU configure")
} else {
exec {
workingDir "$projectDir/external/icu/icu4c/source"
if (os.contains("linux")) {
environment "CFLAGS", "-fPIC"
environment "CXXFLAGS", "-fPIC"
commandLine './runConfigureICU', 'Linux', '--enable-static', '--disable-shared'
} else if (os.contains("mac")) {
commandLine './runConfigureICU', 'MacOSX', '--enable-static', '--disable-shared'
} else {
println("ICU configure not supported for OS '${System.getProperty("os.name")}'")
}
}
}
}
}
task buildICU {
onlyIf { !System.getenv('ICU_ROOT_DIR') }
dependsOn configureICU
doLast {
exec {
def os = osName()
if (os.contains("linux") || os.contains("mac")) {
workingDir "$projectDir/external/icu/icu4c/source"
commandLine 'make', '-j4'
}
}
}
}
task makeNativeRuntime {
dependsOn buildICU
dependsOn cmakeNativeRuntime
doLast {
exec {
workingDir "$buildDir/cpp"
commandLine 'ninja'
}
}
}
processResources {
def os = osName()
if (System.getenv('SKIP_NATIVERUNTIME_BUILD')) {
println("Skipping the nativeruntime build");
} else if (!os.contains("linux") && !os.contains("mac")) {
println("Building the nativeruntime not supported for OS '${System.getProperty("os.name")}'")
} else {
dependsOn makeNativeRuntime
from ("$buildDir/cpp") {
include '*libnativeruntime.*'
rename { String fileName ->
fileName.replace("libnativeruntime", "librobolectric-nativeruntime")
}
into "native/${os}/${arch()}/"
}
}
}
dependencies {
api "com.google.guava:guava:27.0.1-jre"
compileOnly AndroidSdk.MAX_SDK.coordinates
}