Skip to content

Commit aac8daf

Browse files
Adam ComellaFacebook Github Bot
Adam Comella
authored and
Facebook Github Bot
committed
Android: Enable ad-hoc dependencies to be pre-downloaded
Summary: ReactAndroid/build.gradle downloads a number of ad-hoc dependencies from the internet such as boost, JSC headers, and folly. Having the build depend on the internet is problematic. For example, if the site hosting the JSC headers was to go down, then CI builds would start failing. This change introduces the environment variable REACT_NATIVE_DEPENDENCIES which refers to a path. Developers can pre-download all of the ad-hoc dependencies into that path and then the build process will grab the dependencies from that local path rather than trying to download them from the internet. This solution is in the spirit of the existing REACT_NATIVE_BOOST_PATH hook. **Test plan (required)** This change is used by my team's app. Adam Comella Microsoft Corp. Closes #11195 Differential Revision: D4247080 Pulled By: mkonicek fbshipit-source-id: 7c4350339c8d509a829e258d8f1bf320ff8eef64
1 parent abf1438 commit aac8daf

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

ReactAndroid/build.gradle

+18-10
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ import org.apache.tools.ant.filters.ReplaceTokens
1616
def downloadsDir = new File("$buildDir/downloads")
1717
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
1818

19+
// You need to have following folders in this directory:
20+
// - boost_1_57_0
21+
// - double-conversion-1.1.1
22+
// - folly-deprecate-dynamic-initializer
23+
// - glog-0.3.3
24+
// - jsc-headers
25+
def dependenciesPath = System.getenv("REACT_NATIVE_DEPENDENCIES")
26+
1927
// The Boost library is a very large download (>100MB).
2028
// If Boost is already present on your system, define the REACT_NATIVE_BOOST_PATH env variable
2129
// and the build will use that.
22-
def boostPath = System.getenv("REACT_NATIVE_BOOST_PATH")
30+
def boostPath = dependenciesPath ?: System.getenv("REACT_NATIVE_BOOST_PATH")
2331

2432
task createNativeDepsDirectories {
2533
downloadsDir.mkdirs()
@@ -37,7 +45,7 @@ task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
3745
}
3846

3947
task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) {
40-
from boostPath ? boostPath : zipTree(downloadBoost.dest)
48+
from boostPath ?: zipTree(downloadBoost.dest)
4149
from 'src/main/jni/third-party/boost/Android.mk'
4250
include 'boost_1_57_0/boost/**/*.hpp', 'Android.mk'
4351
into "$thirdPartyNdkDir/boost"
@@ -50,8 +58,8 @@ task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Down
5058
dest new File(downloadsDir, 'double-conversion-1.1.1.tar.gz')
5159
}
5260

53-
task prepareDoubleConversion(dependsOn: downloadDoubleConversion, type: Copy) {
54-
from tarTree(downloadDoubleConversion.dest)
61+
task prepareDoubleConversion(dependsOn: dependenciesPath ? [] : [downloadDoubleConversion], type: Copy) {
62+
from dependenciesPath ?: tarTree(downloadDoubleConversion.dest)
5563
from 'src/main/jni/third-party/double-conversion/Android.mk'
5664
include 'double-conversion-1.1.1/src/**/*', 'Android.mk'
5765
filesMatching('*/src/**/*', {fname -> fname.path = "double-conversion/${fname.name}"})
@@ -66,8 +74,8 @@ task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
6674
dest new File(downloadsDir, 'folly-2016.09.26.00.tar.gz');
6775
}
6876

69-
task prepareFolly(dependsOn: downloadFolly, type: Copy) {
70-
from tarTree(downloadFolly.dest)
77+
task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy) {
78+
from dependenciesPath ?: tarTree(downloadFolly.dest)
7179
from 'src/main/jni/third-party/folly/Android.mk'
7280
include 'folly-2016.09.26.00/folly/**/*', 'Android.mk'
7381
eachFile {fname -> fname.path = (fname.path - "folly-2016.09.26.00/")}
@@ -84,8 +92,8 @@ task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
8492

8593
// Prepare glog sources to be compiled, this task will perform steps that normally should've been
8694
// executed by automake. This way we can avoid dependencies on make/automake
87-
task prepareGlog(dependsOn: downloadGlog, type: Copy) {
88-
from tarTree(downloadGlog.dest)
95+
task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy) {
96+
from dependenciesPath ?: tarTree(downloadGlog.dest)
8997
from 'src/main/jni/third-party/glog/'
9098
include 'glog-0.3.3/src/**/*', 'Android.mk', 'config.h'
9199
includeEmptyDirs = false
@@ -124,10 +132,10 @@ task downloadJSCHeaders(type: Download) {
124132
}
125133

126134
// Create Android.mk library module based on so files from mvn + include headers fetched from webkit.org
127-
task prepareJSC(dependsOn: downloadJSCHeaders) << {
135+
task prepareJSC(dependsOn: dependenciesPath ? [] : [downloadJSCHeaders]) << {
128136
copy {
129137
from zipTree(configurations.compile.fileCollection { dep -> dep.name == 'android-jsc' }.singleFile)
130-
from {downloadJSCHeaders.dest}
138+
from dependenciesPath ? "$dependenciesPath/jsc-headers" : {downloadJSCHeaders.dest}
131139
from 'src/main/jni/third-party/jsc/Android.mk'
132140
include 'jni/**/*.so', '*.h', 'Android.mk'
133141
filesMatching('*.h', { fname -> fname.path = "JavaScriptCore/${fname.path}"})

0 commit comments

Comments
 (0)