-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
build.gradle
122 lines (112 loc) · 3.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
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 {
// Building the nativeruntime does not work with GCC due to libstddc++ linker errors.
// TODO: figure out which linker args are needed to build with GCC.
environment "CC", "clang"
environment "CXX", "clang++"
workingDir "$buildDir/cpp"
commandLine 'cmake', "-B", ".", "-S","$projectDir/cpp/"
}
}
}
task configureICU {
onlyIf { !System.getenv('SKIP_ICU_BUILD') }
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`")
}
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")) {
environment "CFLAGS", "-arch x86_64 -arch arm64"
environment "CXXFLAGS", "-arch x86_64 -arch arm64"
commandLine './runConfigureICU', 'MacOSX', '--enable-static', '--disable-shared'
} else {
println("Skipping the nativeruntime build for OS '${System.getProperty("os.name")}'")
}
}
}
}
task buildICU {
onlyIf { !System.getenv('SKIP_ICU_BUILD') }
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 'make'
}
}
}
task copyNativeRuntime {
dependsOn makeNativeRuntime
doLast {
copy {
from ("$buildDir/cpp") {
include '*libnativeruntime.*'
}
rename { String fileName ->
fileName.replace("libnativeruntime", "librobolectric-nativeruntime")
}
def os = osName()
def arch = arch()
if (os.contains("mac")) {
arch = "universal"
}
into project.file("$buildDir/resources/main/native/${os}/${arch}/")
}
}
}
jar {
def os = osName()
if (!System.getenv('SKIP_NATIVERUNTIME_BUILD') && (os.contains("linux") || os.contains("mac"))) {
dependsOn copyNativeRuntime
} else {
println("Skipping the nativeruntime build for OS '${System.getProperty("os.name")}'")
}
}
dependencies {
api "com.google.guava:guava:27.0.1-jre"
compileOnly AndroidSdk.MAX_SDK.coordinates
}