forked from facebook/fresco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
236 lines (208 loc) · 8.52 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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import de.undercouch.gradle.tasks.download.Download
import org.apache.tools.ant.taskdefs.condition.Os
import com.facebook.fresco.buildsrc.Deps
import com.facebook.fresco.buildsrc.GradleDeps
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath GradleDeps.Android.gradlePlugin
classpath GradleDeps.Kotlin.gradlePlugin
classpath GradleDeps.Publishing.gradleMavenPublishPlugin
classpath GradleDeps.Kotlin.gradlePlugin
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id "de.undercouch.download" version "3.1.2"
}
project.ext {
preDexLibs = !project.hasProperty('disablePreDex')
}
subprojects {
repositories {
google()
mavenCentral()
}
// FIXME: This picks up non-Java files by default, failing to parse them.
// Need to configure this more carefully.
tasks.withType(Javadoc).all {
enabled = false
}
configurations.all {
resolutionStrategy.force Deps.jsr305
}
task allclean {
}
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
}
}
apply plugin: 'de.undercouch.download'
ext.makeNdkTasks = { name, deps ->
task "ndk_build_${name}"(dependsOn: deps, type: Exec) {
inputs.files("src/main/jni/${name}")
outputs.dir("$buildDir/${name}")
commandLine getNdkBuildFullPath(project),
'NDK_PROJECT_PATH=null',
'NDK_APPLICATION_MK=../Application.mk',
'NDK_OUT=' + temporaryDir,
"NDK_LIBS_OUT=$buildDir/${name}",
'-C', file("src/main/jni/${name}").absolutePath,
'--jobs', Runtime.getRuntime().availableProcessors()
}
task "ndk_clean_$name"(type: Exec) {
ignoreExitValue true
commandLine getNdkBuildFullPath(project),
'NDK_PROJECT_PATH=null',
'NDK_APPLICATION_MK=../Application.mk',
'NDK_OUT=' + temporaryDir,
"NDK_LIBS_OUT=$buildDir/${name}",
'-C', file("src/main/jni/${name}").absolutePath,
'clean'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn "ndk_build_$name"
}
clean.dependsOn "ndk_clean_$name"
}
ext.getNdkBuildName = {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return "ndk-build.cmd"
} else {
return "ndk-build"
}
}
ext.getNdkBuildFullPath = { Project project ->
File propFile = project.rootProject.file('local.properties')
if (!propFile.exists()) {
return getNdkBuildName()
}
Properties properties = new Properties()
properties.load(propFile.newDataInputStream())
def ndkCommand = properties.getProperty('ndk.command')
if (ndkCommand != null) {
return ndkCommand
}
def path = null
def ndkPath = properties.getProperty('ndk.path')
if (ndkPath != null) {
path = ndkPath
} else {
def ndkDir = properties.getProperty('ndk.dir')
if (ndkDir != null) {
path = ndkDir
}
}
if (path != null) {
if (!path.endsWith(File.separator)) {
path += File.separator
}
return path + getNdkBuildName()
} else {
// if none of above is provided, we assume ndk-build is already in $PATH
return getNdkBuildName()
}
}
ext.nativeDepsDir = new File("${projectDir}/nativedeps")
ext.downloadsDir = new File("${nativeDepsDir}/downloads")
ext.mergeDir = new File("${nativeDepsDir}/merge")
task removeNativeDeps(type: Delete) {
delete nativeDepsDir
}
allclean.dependsOn removeNativeDeps
task createNativeDepsDirectories {
nativeDepsDir.mkdirs()
downloadsDir.mkdirs()
mergeDir.mkdirs()
}
ext.createNativeLibrariesTasks = {name, libraryUrl, libraryFileName, libraryDestinationDir, sourceDir, includePaths, destinationDir ->
// We create the DownloadTask
tasks.create("download${name}", Download) {
src libraryUrl
onlyIfNewer true
overwrite false
dest "${downloadsDir}/${libraryFileName}"
dependsOn createNativeDepsDirectories
}
// The unpack task
tasks.create("unpack${name}", Copy) {
String filePath = "${downloadsDir}/${libraryFileName}"
ReadableResource resource
if (filePath.endsWith("gz")) {
resource = resources.gzip(filePath)
} else if (filePath.endsWith("bz2")) {
resource = resources.bzip2(filePath)
} else {
throw new GradleException("Could not unpack library " + filePath)
}
from tarTree(resource)
into "${downloadsDir}/${libraryDestinationDir}"
dependsOn "download${name}"
}
// The copy task
Task unpackTask = tasks.getByName("unpack${name}")
tasks.create("copy${name}", Copy) {
from "${unpackTask.destinationDir}/${sourceDir}"
from "src/main/jni/third-party/${destinationDir}"
// Allows for overriding when duplicates are encountered.
duplicatesStrategy DuplicatesStrategy.INCLUDE
include(includePaths)
into "${mergeDir}/${destinationDir}"
dependsOn "unpack${name}"
}
}
// Libjpeg-turbo
createNativeLibrariesTasks(
'Libjpeg', // Name for the tasks
"https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${LIBJPEG_TURBO_VERSION}.tar.gz", // The Url for download
"${LIBJPEG_TURBO_VERSION}.tar.gz", // The downloaded file
'libjpeg', // The folder where the file is downloaded
"libjpeg-turbo-${LIBJPEG_TURBO_VERSION}", // The first dir where we have put our customisation
['**/*.c', '**/*.h','**/*.S', '**/*.asm', '**/*.inc', '*.mk'], // Files to compile
"libjpeg-turbo-${LIBJPEG_TURBO_VERSION}" // Final destination dir
)
// Libpng
createNativeLibrariesTasks(
'Libpng', // Name for the tasks
"https://github.com/glennrp/libpng/archive/v${LIBPNG_VERSION}.tar.gz", // The Url for download
"v${LIBPNG_VERSION}.tar.gz", // The downloaded file
'libpng', // The folder where the file is downloaded
"libpng-${LIBPNG_VERSION}", // The first dir where we have put our customisation
['**/*.c', '**/*.h', '**/*.S', '*.mk'], // Files to compile
"libpng-${LIBPNG_VERSION}" // Final destination dir
)
// Gif
createNativeLibrariesTasks(
'Giflib', // Name for the tasks
"https://sourceforge.net/projects/giflib/files/giflib-${GIFLIB_VERSION}.tar.gz/download", // The Url for download
"giflib-${GIFLIB_VERSION}.tar.gz", // The downloaded file
'giflib', // The folder where the file is downloaded
"giflib-${GIFLIB_VERSION}", // The first dir where we have put our customisation
['*.c', '*.h', '*.mk'], // Files to compile
"giflib" // Final destination dir
)
// Webp
createNativeLibrariesTasks(
'Libwebp', // Name for the tasks
"https://github.com/webmproject/libwebp/archive/v${LIBWEBP_VERSION}.tar.gz", // The Url for download
"v${LIBWEBP_VERSION}.tar.gz", // The downloaded file
'libwebp', // The folder where the file is downloaded
"libwebp-${LIBWEBP_VERSION}", // The first dir where we have put our customisation
['src/**/*.c', 'src/**/*.h', '*.mk'], // Files to compile
"libwebp-${LIBWEBP_VERSION}" // Final destination dir
)
}