From 57ef0b2ba37aa6898fdd5f6d9fb0fec1d3756f75 Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Wed, 21 Nov 2018 13:14:43 +0100 Subject: [PATCH] Avoid unnecessary downloads of Android NDK after running `make clean` --- Makefile | 28 +++++++++++++++++++++------- scripts/lib/setup/installers.sh | 2 +- scripts/prepare-for-platform.sh | 28 +++++++++++++++++----------- scripts/run-pre-build-check.sh | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 19 deletions(-) create mode 100755 scripts/run-pre-build-check.sh diff --git a/Makefile b/Makefile index 950add737c..a87e30947a 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ HELP_FUN = \ # Main targets clean: ##@prepare Remove all output folders - git clean -qdxf -f android/ modules/react-native-status/ node_modules/ target/ desktop/ StatusImPackage/ + git clean -dxf -f -e android/local.properties setup: ##@prepare Install all the requirements for status-react ./scripts/setup @@ -46,10 +46,6 @@ prepare-desktop: ##@prepare Install desktop platform dependencies and prepare wo scripts/prepare-for-platform.sh desktop npm install -_prepare-mobile: ##@prepare Install mobile platform dependencies and prepare workspace - scripts/prepare-for-platform.sh mobile - npm install - $(STATUS_GO_IOS_ARCH): curl -s -L \ "$(GITHUB_URL)/$(STATUS_GO_VER)/status-go-ios.zip" \ @@ -61,13 +57,17 @@ $(STATUS_GO_DRO_ARCH): "$(GITHUB_URL)/$(STATUS_GO_VER)/status-go-android.aar" \ -o "$(STATUS_GO_DRO_ARCH)" -prepare-ios: $(STATUS_GO_IOS_ARCH) _prepare-mobile ##@prepare Install and prepare iOS-specific dependencies +prepare-ios: $(STATUS_GO_IOS_ARCH) ##@prepare Install and prepare iOS-specific dependencies + scripts/prepare-for-platform.sh ios + npm install unzip -q -o "$(STATUS_GO_IOS_ARCH)" -d "$(RCTSTATUS_DIR)" ifeq ($(OS),Darwin) cd ios && pod install endif -prepare-android: $(STATUS_GO_DRO_ARCH) _prepare-mobile ##@prepare Install and prepare Android-specific dependencies +prepare-android: $(STATUS_GO_DRO_ARCH) ##@prepare Install and prepare Android-specific dependencies + scripts/prepare-for-platform.sh android + npm install cd android && ./gradlew react-native-android:installArchives prepare-mobile: prepare-android prepare-ios ##@prepare Install and prepare mobile platform specific dependencies @@ -90,14 +90,18 @@ release-windows-desktop: prod-build-desktop ##@build build release for desktop r TARGET_SYSTEM_NAME=Windows scripts/build-desktop.sh prod-build: + scripts/run-pre-build-check.sh android + scripts/run-pre-build-check.sh ios lein prod-build prod-build-android: rm ./modules/react-native-status/android/libs/status-im/status-go/local/status-go-local.aar 2> /dev/null || true + scripts/run-pre-build-check.sh android lein prod-build-android prod-build-ios: rm -r ./modules/react-native-status/ios/RCTStatus/Statusgo.framework/ 2> /dev/null || true + scripts/run-pre-build-check.sh ios lein prod-build-ios full-prod-build: ##@build build prod for both Android and iOS @@ -108,6 +112,7 @@ full-prod-build: ##@build build prod for both Android and iOS prod-build-desktop: git clean -qdxf -f ./index.desktop.js desktop/ + scripts/run-pre-build-check.sh desktop lein prod-build-desktop #-------------- @@ -115,34 +120,43 @@ prod-build-desktop: # ------------- watch-ios-real: ##@watch Start development for iOS real device + scripts/run-pre-build-check.sh ios clj -R:dev build.clj watch --platform ios --ios-device real watch-ios-simulator: ##@watch Start development for iOS simulator + scripts/run-pre-build-check.sh ios clj -R:dev build.clj watch --platform ios --ios-device simulator watch-android-real: ##@watch Start development for Android real device + scripts/run-pre-build-check.sh android clj -R:dev build.clj watch --platform android --android-device real watch-android-avd: ##@watch Start development for Android AVD + scripts/run-pre-build-check.sh android clj -R:dev build.clj watch --platform android --android-device avd watch-android-genymotion: ##@watch Start development for Android Genymotion + scripts/run-pre-build-check.sh android clj -R:dev build.clj watch --platform android --android-device genymotion watch-desktop: ##@watch Start development for Desktop + scripts/run-pre-build-check.sh desktop clj -R:dev build.clj watch --platform desktop #-------------- # Run # ------------- run-android: ##@run Run Android build + scripts/run-pre-build-check.sh android react-native run-android --appIdSuffix debug run-desktop: ##@run Run Desktop build + scripts/run-pre-build-check.sh desktop react-native run-desktop SIMULATOR= run-ios: ##@run Run iOS build + scripts/run-pre-build-check.sh ios ifneq ("$(SIMULATOR)", "") react-native run-ios --simulator="$(SIMULATOR)" else diff --git a/scripts/lib/setup/installers.sh b/scripts/lib/setup/installers.sh index 1df735a2d5..8f94462fc4 100755 --- a/scripts/lib/setup/installers.sh +++ b/scripts/lib/setup/installers.sh @@ -354,7 +354,7 @@ function install_android_ndk() { cecho "@cyan[[Extracting Android NDK to $_ndkParentDir.]]" && \ unzip -q -o ./android-ndk.zip -d "$_ndkParentDir" && \ rm -f ./android-ndk.zip && \ - _ndkTargetDir="$_ndkParentDir/$(ls $_ndkParentDir | head -n 1)" && \ + _ndkTargetDir="$_ndkParentDir/$(ls $_ndkParentDir | grep ndk)" && \ echo "ndk.dir=$_ndkTargetDir" | tee -a $_localPropertiesPath && \ cecho "@blue[[Android NDK installation completed in $_ndkTargetDir.]]" fi diff --git a/scripts/prepare-for-platform.sh b/scripts/prepare-for-platform.sh index 7cf1c45f2d..90db25950d 100755 --- a/scripts/prepare-for-platform.sh +++ b/scripts/prepare-for-platform.sh @@ -9,19 +9,25 @@ PLATFORM_FOLDER="" #if no arguments passed, inform user about possible ones -if [ $# -eq 0 ] - then - echo -e "${GREEN}This script should be invoked with platform argument: 'mobile' or 'desktop'${NC}" - echo "When called it links" - # echo "If invoked with 'mobile' argument it will make a copying: " - # echo "package.json.mobile -> package.json" - # echo "etc.." - exit 1 - else - PLATFORM=$1 - PLATFORM_FOLDER="${PLATFORM}_files" +if [ $# -eq 0 ]; then + echo -e "${GREEN}This script should be invoked with platform argument: 'android', 'ios' or 'desktop'${NC}" + echo "If invoked with 'mobile' argument it will link: " + echo "package.json.mobile -> package.json" + echo "etc.." + exit 1 +else + case $1 in + android | ios) + PLATFORM='mobile' + ;; + *) + PLATFORM=$1 + ;; + esac + PLATFORM_FOLDER="${PLATFORM}_files" fi +scripts/run-pre-build-check.sh $1 echo "Creating link: package.json -> ${PLATFORM_FOLDER}/package.json " ln -sf ${PLATFORM_FOLDER}/package.json package.json diff --git a/scripts/run-pre-build-check.sh b/scripts/run-pre-build-check.sh new file mode 100755 index 0000000000..ce43eb33d1 --- /dev/null +++ b/scripts/run-pre-build-check.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' +PLATFORM="" + +#if no arguments passed, inform user about possible ones + +if [ $# -eq 0 ]; then + echo -e "${GREEN}This script should be invoked with platform argument: 'android', 'ios' or 'desktop'${NC}" + exit 1 +else + PLATFORM=$1 +fi + +npm_version=$(npm -v) +if [[ $npm_version != "5.5.1" ]]; then + echo -e "${YELLOW}+ npm version $npm_version is installed. npm version 5.5.1 is recommended.${NC}" +fi + +if [[ $PLATFORM == 'android' ]]; then + _localPropertiesPath=./android/local.properties + if ! grep -Fq "ndk.dir" $_localPropertiesPath; then + if [ -z $ANDROID_NDK_HOME ]; then + echo -e "${GREEN}NDK directory not configured, please run 'make setup' or add the line to ${_localPropertiesPath}!${NC}" + exit 1 + fi + fi +fi + +echo -e "${GREEN}Finished!${NC}"