Added BUCK to generated app with react-native-cli init

Summary:BUCK is faster than Gradle.
For example `gradle app:installDebug` vs `buck install app` is ~7 seconds vs ~2 seconds with warm caches.
This is just the beginning to allow people to become familiar with BUCK.
It is enough for running the app locally and testing on a device.

Gradle is still used for dependency resolution.
Closes https://github.com/facebook/react-native/pull/6733

Differential Revision: D3126328

Pulled By: bestander

fb-gh-sync-id: 56aad276036c029af7e0e23d60c46ba2f77b3d2c
fbshipit-source-id: 56aad276036c029af7e0e23d60c46ba2f77b3d2c
This commit is contained in:
Konstantin Raev 2016-04-01 08:53:28 -07:00 committed by Facebook Github Bot 1
parent 4133de04d7
commit ce1261a3dd
12 changed files with 162 additions and 35 deletions

View File

@ -42,6 +42,12 @@
# Ignore Website
.*/website/.*
# Ignore generators
.*/local-cli/generator.*
# Ignore BUCK generated folders
.*\.buckd/
.*/node_modules/is-my-json-valid/test/.*\.json
.*/node_modules/iconv-lite/encodings/tables/.*\.json
.*/node_modules/y18n/test/.*\.json
@ -59,6 +65,7 @@
.*/node_modules/isemail/.*\.json
.*/node_modules/tr46/.*\.json
[include]
[libs]

View File

@ -76,7 +76,8 @@ test:
- ./gradlew :ReactAndroid:installDebugAndroidTest
- source scripts/circle-ci-android-setup.sh && retry3 ./scripts/run-android-instrumentation-tests.sh com.facebook.react.tests.gradle
- ./scripts/e2e-test.sh --packager
# JS and Android e2e test
- ./scripts/e2e-test.sh --packager --android
# testing docs generation is not broken
- cd website && node ./server/generate.js

View File

@ -0,0 +1,66 @@
import re
# To learn about Buck see [Docs](https://buckbuild.com/).
# To run your application with Buck:
# - install Buck
# - `npm start` - to start the packager
# - `cd android`
# - `cp ~/.android/debug.keystore keystores/debug.keystore`
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
# - `buck install -r android/app` - compile, install and run application
#
lib_deps = []
for jarfile in glob(['libs/*.jar']):
name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile)
lib_deps.append(':' + name)
prebuilt_jar(
name = name,
binary_jar = jarfile,
)
for aarfile in glob(['libs/*.aar']):
name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile)
lib_deps.append(':' + name)
android_prebuilt_aar(
name = name,
aar = aarfile,
)
android_library(
name = 'all-libs',
exported_deps = lib_deps
)
android_library(
name = 'app-code',
srcs = glob([
'src/main/java/**/*.java',
]),
deps = [
':all-libs',
':build_config',
':res',
],
)
android_build_config(
name = 'build_config',
package = '<%= package %>',
)
android_resource(
name = 'res',
res = 'src/main/res',
package = '<%= package %>',
)
android_binary(
name = 'app',
package_type = 'debug',
manifest = 'src/main/AndroidManifest.xml',
keystore = '//android/keystores:debug',
deps = [
':app-code',
],
)

View File

@ -124,3 +124,10 @@ dependencies {
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

View File

@ -1,7 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<%= package %>">
package="<%= package %>"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"

View File

@ -0,0 +1,8 @@
keystore(
name = 'debug',
store = 'debug.keystore',
properties = 'debug.keystore.properties',
visibility = [
'PUBLIC',
],
)

View File

@ -0,0 +1,4 @@
key.store=debug.keystore
key.alias=androiddebugkey
key.store.password=android
key.alias.password=android

View File

@ -64,6 +64,10 @@ module.exports = yeoman.generators.NamedBase.extend({
this.templatePath('_watchmanconfig'),
this.destinationPath('.watchmanconfig')
);
this.fs.copy(
this.templatePath('_buckconfig'),
this.destinationPath('.buckconfig')
);
},
writing: function() {

View File

@ -0,0 +1,6 @@
[android]
target = Google Inc.:Google APIs:23
[maven_repositories]
central = https://repo1.maven.org/maven2

View File

@ -32,3 +32,9 @@ local.properties
#
node_modules/
npm-debug.log
# BUCK
buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore

View File

@ -1,6 +1,7 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {

View File

@ -62,12 +62,17 @@ npm install -g $CLI_PACKAGE
react-native init EndToEndTest --version $PACKAGE
cd EndToEndTest
# Iterates through all arguments and runs e2e tests for all of them one by one
# e.g. ./scripts/e2e-test.sh --packager --ios --android will run all e2e tests but will install the test app once
while test $# -gt 0
do
case $1 in
"--packager"*)
echo "Running a basic packager test"
# Check the packager produces a bundle (doesn't throw an error)
react-native bundle --platform android --dev true --entry-file index.android.js --bundle-output android-bundle.js
# TODO do flow check
# Check that flow passes
$ROOT/node_modules/.bin/flow check
;;
"--ios"*)
echo "Running an iOS app"
@ -86,12 +91,17 @@ case $1 in
ls `basename $MARKER_ANDROID` > /dev/null
../node_modules/react-native/packager/packager.sh --nonPersistent &
SERVER_PID=$!
# TODO Start the app and check it renders "Welcome to React Native"
echo "The Android e2e test is not implemented yet" >&2
exit 1
cp ~/.android/debug.keystore keystores/debug.keystore
./gradlew :app:copyDownloadableDepsToLibs
buck install -r android/app
# TODO t10114777 check it renders "Welcome to React Native"
;;
*)
echo "Please run the script with --ios, --android or --packager" >&2
exit 1
;;
esac
shift
done
exit 0