Migrate from installing tooling the traditional way to Nix

This commit is contained in:
Pedro Pombeiro 2019-02-01 11:44:51 +01:00
parent e8116e7d62
commit 692de32931
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
16 changed files with 263 additions and 136689 deletions

View File

@ -3,13 +3,14 @@ android-sdk-build-tools;28.0.1;
android-sdk-platform;android-27;
android-sdk;4333796;aa190cfd7299cd6a1c687355bb2764e4
bundler;1.17.2;bundler
clojure_cli;1.9.0.381;
cmake;3.12.2;
clojure_cli;1.9.0.391;
cmake;3.11.2;
conan;1.9.0;
golang;1.10.2;
golang;1.10.8;
leiningen;2.8.1;
maven;3.5.2;
node;10.12.0;
maven;3.5.4;
nix;2.2.1;
node;8.15.0;
nvm;0.33.11;
qt;5.11.2;974fda61267cfb6e45984ee5f0a285f8
qtci;55ffd9f225708b3aa1443851cfa8dead2c1f9959;

View File

@ -36,7 +36,6 @@ project.xcworkspace
#
.idea
.gradle
local.properties
*.iml
# Atom

1
.envrc Normal file
View File

@ -0,0 +1 @@
layout node

1
.gitignore vendored
View File

@ -29,7 +29,6 @@ project.xcworkspace
#
.idea
.gradle
local.properties
*.iml
**/android/.project

File diff suppressed because one or more lines are too long

View File

@ -1,6 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
lastUpdateCheck 1547116152734
yarn-path ".yarn/releases/yarn-1.13.0.js"

122
Makefile
View File

@ -1,4 +1,4 @@
.PHONY: clean setup react-native test release
.PHONY: clean setup react-native test release _ensure-in-nix-shell _list
help: ##@other Show this help
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
@ -19,9 +19,11 @@ OS := $(shell uname)
# To add new item into help output, simply add comments
# starting with '##'. To add category, use @category.
GREEN := $(shell tput -Txterm setaf 2)
RED := $(shell tput -Txterm setaf 1)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
BOLD := $(shell tput bold)
HELP_FUN = \
%help; \
while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
@ -40,17 +42,41 @@ __toolversion = $(shell $(GIT_ROOT)/scripts/toolversion $(1))
# Main targets
clean: ##@prepare Remove all output folders
git clean -dxf -f -e android/local.properties
git clean -dxf -f
setup: ##@prepare Install all the requirements for status-react
@./scripts/setup
@./scripts/run-environment-check.sh setup
prepare-desktop: ##@prepare Install desktop platform dependencies and prepare workspace
_ensure-in-nix-shell:
ifndef IN_NIX_SHELL
$(error '$(RED)Please run '$(BOLD)$(MAKE) shell$(RESET)$(RED)' first$(RESET)')
endif
shell: ##@prepare Enter into a pre-configured shell
ifndef IN_NIX_SHELL
@if command -v "nix" >/dev/null 2>&1 || [ -f ~/.nix-profile/etc/profile.d/nix.sh ]; then \
echo "Configuring Nix shell..."; \
if ! command -v "nix" >/dev/null 2>&1; then \
. ~/.nix-profile/etc/profile.d/nix.sh; \
NIX_CONF_DIR=$(PWD)/scripts/lib/setup/nix \
nix-shell; \
else \
NIX_CONF_DIR=$(PWD)/scripts/lib/setup/nix \
nix-shell; \
fi \
else \
echo "Please run 'make setup' first"; \
fi
else
@echo "Nix shell is already active"
endif
prepare-desktop: _ensure-in-nix-shell ##@prepare Install desktop platform dependencies and prepare workspace
scripts/prepare-for-platform.sh desktop
yarn install --frozen-lockfile
$(STATUS_GO_IOS_ARCH):
@echo "Downloading status-go artifact from DigitalOcean Bucket"; \
curl --fail --silent --location \
"${DO_SPACE_URL}/status-go-ios-$(STATUS_GO_VER).zip" \
--output "$(STATUS_GO_IOS_ARCH)"; \
@ -71,6 +97,7 @@ $(STATUS_GO_IOS_ARCH):
$(STATUS_GO_DRO_ARCH):
mkdir -p $(ANDROID_LIBS_DIR)
@echo "Downloading status-go artifact from DigitalOcean Bucket"; \
curl --fail --silent --location \
"${DO_SPACE_URL}/status-go-android-$(STATUS_GO_VER).aar" \
--output "$(STATUS_GO_DRO_ARCH)"; \
@ -84,17 +111,19 @@ $(STATUS_GO_DRO_ARCH):
fi \
fi
prepare-ios: $(STATUS_GO_IOS_ARCH) ##@prepare Install and prepare iOS-specific dependencies
prepare-ios: _ensure-in-nix-shell $(STATUS_GO_IOS_ARCH) ##@prepare Install and prepare iOS-specific dependencies
scripts/prepare-for-platform.sh ios
yarn install --frozen-lockfile
unzip -q -o "$(STATUS_GO_IOS_ARCH)" -d "$(RCTSTATUS_DIR)"
ifeq ($(OS),Darwin)
# TODO: remove this patch when we upgrade to RN 0.57+
git apply --check ios/patches/ios-legacy-build-system.patch 2> /dev/null && git apply ios/patches/ios-legacy-build-system.patch || echo "Patch already applied"
# CocoaPods are trash and can't handle other pod instances running at the same time
./scripts/wait-for.sh pod 240
cd ios && pod install
endif
prepare-android: $(STATUS_GO_DRO_ARCH) ##@prepare Install and prepare Android-specific dependencies
prepare-android: _ensure-in-nix-shell $(STATUS_GO_DRO_ARCH) ##@prepare Install and prepare Android-specific dependencies
scripts/prepare-for-platform.sh android
yarn install --frozen-lockfile
cd android && ./gradlew react-native-android:installArchives
@ -107,39 +136,49 @@ prepare-mobile: prepare-android prepare-ios ##@prepare Install and prepare mobil
release: release-android release-ios ##@build build release for Android and iOS
release-android: prod-build-android ##@build build release for Android
ifdef IN_NIX_SHELL
react-native run-android --variant=release
endif
release-ios: prod-build-ios ##@build build release for iOS release
ifdef IN_NIX_SHELL
@echo "Build in XCode, see https://status.im/build_status/ for instructions"
# Open XCode inside the Nix context
open ios/StatusIm.xcworkspace
endif
release-desktop: prod-build-desktop ##@build build release for desktop release
ifdef IN_NIX_SHELL
scripts/build-desktop.sh
endif
release-windows-desktop: prod-build-desktop ##@build build release for desktop release
ifdef IN_NIX_SHELL
TARGET_SYSTEM_NAME=Windows scripts/build-desktop.sh
endif
prod-build:
prod-build: _ensure-in-nix-shell
scripts/run-environment-check.sh android
scripts/run-environment-check.sh ios
lein prod-build
prod-build-android:
prod-build-android: _ensure-in-nix-shell
rm ./modules/react-native-status/android/libs/status-im/status-go/local/status-go-local.aar 2> /dev/null || true
scripts/run-environment-check.sh android
lein prod-build-android
prod-build-ios:
prod-build-ios: _ensure-in-nix-shell
rm -r ./modules/react-native-status/ios/RCTStatus/Statusgo.framework/ 2> /dev/null || true
scripts/run-environment-check.sh ios
lein prod-build-ios
full-prod-build: ##@build build prod for both Android and iOS
full-prod-build: _ensure-in-nix-shell ##@build build prod for both Android and iOS
./scripts/bundle-status-go.sh ios android
$(MAKE) prod-build
rm -r ./modules/react-native-status/ios/RCTStatus/Statusgo.framework/ 2> /dev/null || true
rm ./modules/react-native-status/android/libs/status-im/status-go/local/status-go-local.aar 2> /dev/null
prod-build-desktop:
prod-build-desktop: _ensure-in-nix-shell
git clean -qdxf -f ./index.desktop.js desktop/
scripts/run-environment-check.sh desktop
lein prod-build-desktop
@ -148,25 +187,21 @@ prod-build-desktop:
# REPL
# -------------
watch-ios-real: ##@watch Start development for iOS real device
scripts/run-environment-check.sh ios
clj -R:dev build.clj watch --platform ios --ios-device real
_watch-%: _ensure-in-nix-shell ##@watch Start development for device
$(eval SYSTEM := $(word 2, $(subst -, , $@)))
$(eval DEVICE := $(word 3, $(subst -, , $@)))
scripts/run-environment-check.sh $(SYSTEM)
clj -R:dev build.clj watch --platform $(SYSTEM) --$(SYSTEM)-device $(DEVICE)
watch-ios-simulator: ##@watch Start development for iOS simulator
scripts/run-environment-check.sh ios
clj -R:dev build.clj watch --platform ios --ios-device simulator
watch-ios-real: _watch-ios-real ##@watch Start development for iOS real device
watch-android-real: ##@watch Start development for Android real device
scripts/run-environment-check.sh android
clj -R:dev build.clj watch --platform android --android-device real
watch-ios-simulator: _watch-ios-simulator ##@watch Start development for iOS simulator
watch-android-avd: ##@watch Start development for Android AVD
scripts/run-environment-check.sh android
clj -R:dev build.clj watch --platform android --android-device avd
watch-android-real: _watch-android-real ##@watch Start development for Android real device
watch-android-genymotion: ##@watch Start development for Android Genymotion
scripts/run-environment-check.sh android
clj -R:dev build.clj watch --platform android --android-device genymotion
watch-android-avd: _watch-android-avd ##@watch Start development for Android AVD
watch-android-genymotion: _watch-android-genymotion ##@watch Start development for Android Genymotion
watch-desktop: ##@watch Start development for Desktop
scripts/run-environment-check.sh desktop
@ -175,16 +210,17 @@ watch-desktop: ##@watch Start development for Desktop
#--------------
# Run
# -------------
run-android: ##@run Run Android build
scripts/run-environment-check.sh android
react-native run-android --appIdSuffix debug
_run-%: _ensure-in-nix-shell
$(eval SYSTEM := $(word 2, $(subst -, , $@)))
scripts/run-environment-check.sh $(SYSTEM)
react-native run-$(SYSTEM)
run-desktop: ##@run Run Desktop build
scripts/run-environment-check.sh desktop
react-native run-desktop
run-android: _run-android ##@run Run Android build
run-desktop: _run-desktop ##@run Run Desktop build
SIMULATOR=
run-ios: ##@run Run iOS build
run-ios: _ensure-in-nix-shell ##@run Run iOS build
scripts/run-environment-check.sh ios
ifneq ("$(SIMULATOR)", "")
react-native run-ios --simulator="$(SIMULATOR)"
@ -196,29 +232,29 @@ endif
# Tests
#--------------
test: ##@test Run tests once in NodeJS
test: _ensure-in-nix-shell ##@test Run tests once in NodeJS
lein with-profile test doo node test once
test-auto: ##@test Run tests in interactive (auto) mode in NodeJS
test-auto: _ensure-in-nix-shell ##@test Run tests in interactive (auto) mode in NodeJS
lein with-profile test doo node test
#--------------
# Other
#--------------
react-native: ##@other Start react native packager
react-native: _ensure-in-nix-shell ##@other Start react native packager
@scripts/start-react-native.sh
geth-connect: ##@other Connect to Geth on the device
geth-connect: _ensure-in-nix-shell ##@other Connect to Geth on the device
adb forward tcp:8545 tcp:8545
build/bin/geth attach http://localhost:8545
android-ports: ##@other Add proxies to Android Device/Simulator
android-ports: _ensure-in-nix-shell ##@other Add proxies to Android Device/Simulator
adb reverse tcp:8081 tcp:8081
adb reverse tcp:3449 tcp:3449
adb reverse tcp:4567 tcp:4567
adb forward tcp:5561 tcp:5561
android-logcat:
android-logcat: _ensure-in-nix-shell
adb logcat | grep -e StatusModule -e ReactNativeJS -e StatusNativeLogs
_list:
@ -229,14 +265,14 @@ _unknown-startdev-target-%:
@ ${MAKE} _list | grep "watch-" | sed s/watch-/startdev-/
@ exit 1
_startdev-%:
_startdev-%: _ensure-in-nix-shell
$(eval SYSTEM := $(word 2, $(subst -, , $@)))
$(eval DEVICE := $(word 3, $(subst -, , $@)))
${MAKE} prepare-${SYSTEM} || ${MAKE} _unknown-startdev-target-$@
$(MAKE) prepare-${SYSTEM} || $(MAKE) _unknown-startdev-target-$@
@ if [ -z "$(DEVICE)" ]; then \
${MAKE} watch-$(SYSTEM) || ${MAKE} _unknown-startdev-target-$@; \
$(MAKE) watch-$(SYSTEM) || $(MAKE) _unknown-startdev-target-$@; \
else \
${MAKE} watch-$(SYSTEM)-$(DEVICE) || ${MAKE} _unknown-startdev-target-$@; \
$(MAKE) watch-$(SYSTEM)-$(DEVICE) || $(MAKE) _unknown-startdev-target-$@; \
fi
startdev-android-avd: _startdev-android-avd

45
default.nix Normal file
View File

@ -0,0 +1,45 @@
let
pkgs = import ((import <nixpkgs> { }).fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "168cbb39691cca2822ce1fdb3e8c0183af5c6d0d";
sha256 = "0fqasswfqrz2rbag9bz17j8y7615s0p9l23cw4sk2f384gk0zf6c";
}) { config = { }; };
in pkgs.stdenv.mkDerivation rec {
name = "env";
env = pkgs.buildEnv { name = name; paths = buildInputs; };
statusDesktopBuildInputs = with pkgs; [
cmake
extra-cmake-modules
go_1_10
] ++ stdenv.lib.optional stdenv.isLinux python37; # for Conan
buildInputs = with pkgs; [
clojure
jq
leiningen
lsof # used in scripts/start-react-native.sh
maven
nodejs
openjdk
python27 # for e.g. gyp
watchman
unzip
wget
yarn
] ++ statusDesktopBuildInputs
++ stdenv.lib.optional stdenv.isDarwin cocoapods;
shellHook = with pkgs; ''
local toolversion="$(git rev-parse --show-toplevel)/scripts/toolversion"
export JAVA_HOME="${openjdk}"
export ANDROID_HOME=~/.status/Android/Sdk
export ANDROID_SDK_ROOT="$ANDROID_HOME"
export ANDROID_NDK_ROOT="$ANDROID_SDK_ROOT/android-ndk-$($toolversion android-ndk)"
export ANDROID_NDK_HOME="$ANDROID_NDK_ROOT"
export ANDROID_NDK="$ANDROID_NDK_ROOT"
export PATH="$ANDROID_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$PATH"
[ -d "$ANDROID_NDK_ROOT" ] || ./scripts/setup # we assume that if the NDK dir does not exist, make setup needs to be run
'';
}

View File

@ -0,0 +1,12 @@
diff --git a/node_modules/react-native/local-cli/runIOS/runIOS.js b/node_modules/react-native/local-cli/runIOS/runIOS.js
index dfabb92b8..5b2714729 100644
--- a/node_modules/react-native/local-cli/runIOS/runIOS.js
+++ b/node_modules/react-native/local-cli/runIOS/runIOS.js
@@ -283,6 +283,7 @@ function buildProject(
configuration,
'-scheme',
scheme,
+ '-UseModernBuildSystem=NO',
'-destination',
`id=${udid}`,
'-derivedDataPath',

View File

@ -14,7 +14,7 @@ STATUS_RELEASE_STORE_PASSWORD=$(property_gradle 'STATUS_RELEASE_STORE_PASSWORD')
STATUS_RELEASE_KEY_ALIAS=$(property_gradle 'STATUS_RELEASE_KEY_ALIAS')
STATUS_RELEASE_KEY_PASSWORD=$(property_gradle 'STATUS_RELEASE_KEY_PASSWORD')
[[ -e "${STORE_FILE/#\~/$HOME}" ]] && echo "Keystore $STORE_FILE already exists, please manually remove it if you want to regenerate." && exit 0
[[ -e "$STORE_FILE" ]] && echo "Keystore $STORE_FILE already exists, please manually remove it if you want to regenerate." && exit 0
echo "Generating keystore $STORE_FILE"
keydirname="$( dirname "$STORE_FILE" )"

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash
_localPropertiesPath=./android/local.properties
GIT_ROOT=$(git rev-parse --show-toplevel)
function downloadUrl() {
function download_url() {
if program_exists "aria2c"; then
aria2c --max-connection-per-server=16 --split=16 --dir="$1" -o "$2" "$3"
else
@ -10,397 +10,65 @@ function downloadUrl() {
fi
}
function install_nix() {
if ! program_exists nix; then
touch -a "${HOME}/.bash_profile"
local required_version=$(toolversion nix)
bash <(curl https://nixos.org/releases/nix/nix-${required_version}/install) --no-daemon
if [ $? -eq 0 ]; then
if is_linux && [ -f ~/.bashrc ] && ! grep -qF ".nix-profile/etc/profile.d/nix.sh" ~/.bashrc; then
# For some reason, new terminals are not started as login shells, so .profile and .bash_profile are not sourced.
# To get around it, we add Nix initialization to .bashrc as well, if it exists
echo "if [ -e ${HOME}/.nix-profile/etc/profile.d/nix.sh ]; then . ${HOME}/.nix-profile/etc/profile.d/nix.sh; fi # added by make setup Status script" >> ~/.bashrc
fi
. ${HOME}/.nix-profile/etc/profile.d/nix.sh && \
NIX_CONF_DIR=$(cd "${BASH_SOURCE%/*}" && pwd)/nix \
nix-build --no-out-link -A env.all ${GIT_ROOT}/default.nix
echo -e "${YELLOW}**********************************************************************************************************"
echo "The Nix package manager was successfully installed. Please run \`make shell\` to initialize the Nix environment."
echo "If this doesn't work, you might have to sign out and back in, in order for the environment to be reloaded."
echo -e "**********************************************************************************************************${NC}"
else
echo "Please see https://nixos.org/nix/manual/#chap-installation"
fi
exit
fi
}
function install_nsis() {
! is_linux && return 0
# NSIS (Nullsoft Scriptable Install System) is a professional open source system to create Windows installers. It is designed to be as small and flexible as possible and is therefore very suitable for internet distribution.
linux_install nsis
}
function install_node() {
if ! nvm_installed && ! program_exists 'node'; then
install_nvm
fi
if nvm_installed; then
install_node_via_nvm
if program_exists "apt"; then
apt_install "nsis"
else
install_node_via_package_manager
echo "nsis is not supported in this Linux distro. Generating Windows setup executables will not be possible"
fi
}
function install_and_setup_package_manager() {
if is_macos; then
install_homebrew_if_needed
brew_tap "caskroom/cask"
elif is_linux; then
# Linux
buildtools=(
autoconf
automake
build-essential
cmake
curl
g++
lib32ncurses5 # required for Android SDK
lib32stdc++6 # required for Android SDK
libssl-dev
libtool
make
pkg-config # required to e.g. build watchman
python-dev
rlwrap # required to use clj
wget
unzip
)
for package in "${buildtools[@]}"; do
linux_install "$package"
done
fi
}
function install_wget() {
if is_macos; then
brew_install wget 1.19.4 0505e48743f82ac2e9f5d0c9d6d811949982262e
fi
# it's installed on ubuntu/debian by default
}
function needs_java8_linux() {
! program_exists "java" || !(java -version 2>&1 | grep -q "1.8.0")
}
function install_java8() {
if is_macos; then
brew_cask_install "caskroom/versions/java8"
elif is_linux; then
if needs_java8_linux; then
sudo su << EOF
add-apt-repository ppa:webupd8team/java -y
apt update
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
apt install -y oracle-java8-installer
EOF
else
already_installed "java8"
fi
fi
}
function install_leiningen() {
if is_macos; then
brew_install leiningen $(toolversion leiningen) f7e10afc6d04a13d28e825db71326d16c12e9724
elif is_linux; then
install_leiningen_linux
fi
}
function install_leiningen_linux() {
local destination=/usr/bin/lein
local required_version=$(toolversion leiningen)
if ! program_version_exists "lein" "$required_version"; then
cecho "@b@blue[[+ Installing lein...]]"
sudo su << EOF
curl --silent \
https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein \
-o $destination
chmod 755 $destination
cd $HOME && lein downgrade $required_version
EOF
else
already_installed "lein"
fi
}
function install_clojure_cli() {
if is_macos; then
local required_version=$(toolversion clojure_cli)
brew_install clojure $required_version 90ea0cb4b194282b5906108dcec522c5a1ed7ce0
elif is_linux; then
install_clojure_cli_linux
fi
}
function install_clojure_cli_linux() {
local required_version=$(toolversion clojure_cli)
if ! program_exists "clojure" || ! echo "$(clj -r <<< '(System/exit 0)')" | grep -q -o ${required_version%.*}; then
cecho "@b@blue[[+ Installing Clojure CLI...]]"
local current_dir=$(pwd)
sudo su << EOF
curl --silent \
https://download.clojure.org/install/linux-install-${required_version}.sh \
-o /tmp/clojure
chmod +x /tmp/clojure
cd /tmp
./clojure
EOF
cd "$current_dir"
else
already_installed "Clojure CLI"
fi
}
function install_watchman() {
local required_version=$(toolversion watchman)
if is_macos; then
brew_install watchman $required_version 1a41406af8db6bbc0c94811cf60043a7436be3c4
elif is_linux; then
if ! program_version_exists "watchman" "$required_version"; then
local current_dir=$(pwd)
local clone_path="/tmp/watchman"
rm -rf $clone_path
git clone https://github.com/facebook/watchman.git $clone_path
cd $clone_path
git checkout v$required_version
./autogen.sh && \
./configure && \
make && \
sudo make install
cd "$current_dir"
else
already_installed "watchman"
fi
fi
}
function install_homebrew_if_needed() {
! is_macos && return 1
if test ! $(which brew); then
cecho "@b@blue[[+ Installing homebrew]]"
ruby -e "$(curl -fsSL \
https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
else
already_installed "Homebrew"
fi
}
function export_android_sdk_vars() {
local profile
local target_path
if is_macos; then
profile=$HOME/.bash_profile
elif is_linux; then
profile=$HOME/.bashrc
fi
[ -f $profile ] || touch $profile
if ! grep -Fq "export ANDROID_SDK_ROOT=" $profile; then
echo "export ANDROID_HOME=\"$1\"" >> $profile && \
echo "export ANDROID_SDK_ROOT=\"$1\"" >> $profile && \
echo "export PATH=\"$1/tools:$1/tools/bin:\$PATH\"" >> $profile
fi
export ANDROID_HOME="$1" && \
export ANDROID_SDK_ROOT="$1" && \
export PATH="$1/tools:$1/tools/bin:$PATH"
}
function install_android_sdk() {
if is_macos; then
brew_cask_install android-sdk
[ -z "$ANDROID_SDK_ROOT" ] && export_android_sdk_vars /usr/local/share/android-sdk
elif is_linux; then
install_android_sdk_linux
fi
use_android_sdk
}
function install_android_sdk_linux() {
if [ -z "$ANDROID_SDK_ROOT" ]; then
if grep -Fq "sdk.dir" $_localPropertiesPath; then
local _sdkParentDir="$(awk -F'=' "/^sdk.dir=/{print \$2}" "$_localPropertiesPath")"
export_android_sdk_vars $_sdkParentDir
cecho "@green[[Android SDK already declared.]]"
else
local required_version=$(toolversion android-sdk)
local _sdkParentDir=$HOME/Android/Sdk
mkdir -p $_sdkParentDir
cecho "@cyan[[Downloading Android SDK.]]"
downloadUrl . sdk-tools-linux.zip https://dl.google.com/android/repository/sdk-tools-linux-${required_version}.zip && \
cecho "@cyan[[Extracting Android SDK to $_sdkParentDir.]]" && \
unzip -q -o ./sdk-tools-linux.zip -d "$_sdkParentDir" && \
rm -f ./sdk-tools-linux.zip && \
_sdkTargetDir="$_sdkParentDir" && \
echo "sdk.dir=$_sdkTargetDir" | tee -a $_localPropertiesPath && \
export_android_sdk_vars $_sdkParentDir && \
cecho "@blue[[Android SDK installation completed in $_sdkTargetDir.]]" || \
return 0
fi
if [ -d "$ANDROID_SDK_ROOT" ]; then
cecho "@green[[Android SDK already installed.]]"
else
if ! grep -Fq "sdk.dir" $_localPropertiesPath; then
echo "sdk.dir=$ANDROID_SDK_ROOT" | tee -a $_localPropertiesPath
fi
cecho "@green[[Android SDK already declared.]]"
local required_version=$(toolversion android-sdk)
mkdir -p $ANDROID_SDK_ROOT
cecho "@cyan[[Downloading Android SDK.]]"
local PLATFORM=$(echo "$OS" | tr '[:upper:]' '[:lower:]')
download_url . sdk-tools-${PLATFORM}.zip https://dl.google.com/android/repository/sdk-tools-${PLATFORM}-${required_version}.zip && \
cecho "@cyan[[Extracting Android SDK to $ANDROID_SDK_ROOT.]]" && \
unzip -q -o ./sdk-tools-${PLATFORM}.zip -d "$ANDROID_SDK_ROOT" && \
rm -f ./sdk-tools-${PLATFORM}.zip && \
cecho "@blue[[Android SDK installation completed in $ANDROID_SDK_ROOT.]]" || \
exit $?
fi
return 1
}
[ $? -eq 0 ] && use_android_sdk
function install_maven() {
local required_version=$(toolversion maven)
brew_install maven $required_version 4c23c22dc71eadaeb7b25d6e6c10fd53bfc26976
linux_install maven
}
function install_react_native_cli() {
cd "$(repo_path)"
local npm_command='npm'
local required_version=$(toolversion react_native_cli)
if is_linux && ! nvm_installed; then
# aptitude version of node requires sudo for global install
npm_command="sudo $npm_command"
fi
if npm list -g "react-native-cli@{required_version}" &>/dev/null; then
already_installed "react-native-cli@{required_version}"
else
$npm_command install -g react-native-cli@${required_version}
fi
}
function install_yarn() {
local required_version=$(toolversion yarn)
if ! program_exists "yarn"; then
npm install -g yarn@$required_version # Install the required yarn version
else
cecho "+ yarn already installed... skipping."
fi
if program_exists "yarn"; then
local yarn_version=$(yarn -v)
if [[ $yarn_version != "$required_version" ]]; then
cecho "@b@yellow[[+ yarn version $yarn_version is installed. Downloading yarn version $required_version in the local repo.]]"
yarn policies set-version $required_version
fi
fi
}
function install_nvm() {
local required_version=$(toolversion nvm)
if ! program_version_exists 'nvm' "$required_version"; then
cecho "@b@blue[[+ Installing nvm $required_version]]"
# Ensure a profile file exists, otherwise NVM will not add its configuration anywhere
# and will therefore be inaccessible
[ -f "~/.bash_profile" ] || touch ~/.bash_profile
sudo apt install -y build-essential libssl-dev
source scripts/3rd-party/nvm/${required_version}/install.sh
load_nvm_if_available
else
cecho "+ nvm already installed... skipping."
fi
}
function install_node_via_nvm() {
local required_version=$(toolversion node)
cd "$(repo_path)"
if [ "$(nvm version v""$required_version"")" = "N/A" ]; then
cecho "@b@blue[[+ Installing Node $required_version]]"
nvm install $required_version
nvm alias status-im $required_version
nvm use status-im
else
if [ "$(nvm version status-im)" != "v$required_version" ]; then
nvm alias status-im $required_version
fi
nvm use status-im
local version=$(node -v)
cecho "+ Node already installed (status-im $version via NVM)... skipping."
fi
}
function install_node_via_package_manager() {
local required_version=$(toolversion node)
if ! program_version_exists "node" "v$required_version"; then
if is_macos; then
brew_install node "$required_version" b801cc6b71e7c09448b4f823e493710665de68eb
elif is_linux; then
curl -sL https://deb.nodesource.com/setup_${required_version%%\.*}.x | sudo -E bash -
linux_update
linux_install nodejs
fi
else
cecho \
"+ Node already installed ($(node -v) via package manager)... skipping."
fi
}
function required_pod_version() {
cat "$(repo_path)/ios/Podfile.lock" | grep "COCOAPODS: " | awk '{ print $2 }'
}
function correct_pod_version_is_installed() {
! program_exists "pod" && return 1
[[ "$(required_pod_version)" == "$(pod --version)" ]]
}
function using_rvm() {
program_exists "rvm"
}
function initialize_rvm() {
cd "$(repo_path)"
if [ ! -e "$(repo_path)/.ruby-version" ]; then
rvm use --default > /dev/null
echo "$(rvm current)" > .ruby-version
fi
rvm use . >/dev/null
}
function using_cocoapods() {
is_macos
}
function install_cocoapods() {
! using_cocoapods && return 1
local gem_command="sudo gem"
local destination="system Ruby"
local version=$(required_pod_version)
if using_rvm; then
initialize_rvm
gem_command="gem"
destination="RVM ($(rvm current))"
fi
if ! program_exists "pod"; then
$gem_command install cocoapods -v "$version"
elif ! correct_pod_version_is_installed; then
cecho "@b@blue[[+ Updating to cocoapods $version]]"
$gem_command uninstall cocoapods --ignore-dependencies --silent
$gem_command install cocoapods -v "$version"
else
cecho "+ cocoapods already installed to $destination... skipping."
fi
return 0
}
function dependency_setup() {
@ -416,11 +84,7 @@ function dependency_setup() {
}
function use_android_sdk() {
if [ -n "$ANDROID_SDK_ROOT" ]; then
if ! grep -Fq "sdk.dir" $_localPropertiesPath; then
echo "sdk.dir=$ANDROID_SDK_ROOT" | tee -a $_localPropertiesPath
fi
if [ -d "$ANDROID_SDK_ROOT" ]; then
local ANDROID_BUILD_TOOLS_VERSION=$(toolversion android-sdk-build-tools)
local ANDROID_PLATFORM_VERSION=$(toolversion android-sdk-platform)
touch ~/.android/repositories.cfg
@ -440,25 +104,21 @@ function use_android_sdk() {
}
function install_android_ndk() {
if grep -Fq "ndk.dir" $_localPropertiesPath; then
cecho "@green[[Android NDK already declared.]]"
if [ -d "$ANDROID_NDK_ROOT" ]; then
cecho "@green[[Android NDK already installed.]]"
else
local ANDROID_NDK_VERSION=$(toolversion android-ndk)
local _ndkParentDir=~/Android/Sdk
local _ndkParentDir=$(dirname $ANDROID_NDK_ROOT)
mkdir -p $_ndkParentDir
cecho "@cyan[[Downloading Android NDK.]]"
local PLATFORM="linux"
if is_macos; then
PLATFORM="darwin"
fi
local PLATFORM=$(echo "$OS" | tr '[:upper:]' '[:lower:]')
downloadUrl . android-ndk.zip https://dl.google.com/android/repository/android-ndk-$ANDROID_NDK_VERSION-$PLATFORM-x86_64.zip && \
download_url . android-ndk.zip https://dl.google.com/android/repository/android-ndk-$ANDROID_NDK_VERSION-$PLATFORM-x86_64.zip && \
cecho "@cyan[[Extracting Android NDK to $_ndkParentDir.]]" && \
unzip -q -o ./android-ndk.zip -d "$_ndkParentDir" && \
rm -f ./android-ndk.zip && \
_ndkTargetDir="$_ndkParentDir/$(ls $_ndkParentDir | grep ndk)" && \
echo "ndk.dir=$_ndkTargetDir" | tee -a $_localPropertiesPath && \
cecho "@blue[[Android NDK installation completed in $_ndkTargetDir.]]"
fi
}

View File

@ -0,0 +1,2 @@
extra-substituters = https://nix-cache.status.im/
trusted-public-keys = nix-cache.status.im-1:x/93lOfLU+duPplwMSBR+OlY4+mo+dCN7n0mr4oPwgY= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

View File

@ -30,106 +30,15 @@ function toolversion() {
${GIT_ROOT}/scripts/toolversion "${1}"
}
########
# Homebrew
########
function brew_install() {
local package=$1
local required_version=$2
local url="https://raw.githubusercontent.com/Homebrew/homebrew-core/${3:-master}/Formula/$package.rb"
if ! is_macos; then
return 1
fi
local pkginfo=$(brew info "$package")
if [ $? -eq 0 ]; then
# Package already exists locally
local prefix_expr="HOMEBREW_PREFIX: "
local brew_base=$(brew config | grep "$prefix_expr" | sed "s|$prefix_expr||")
local pkg_base="$brew_base/Cellar/$package/"
local installed_versions=$(echo "$pkginfo" | grep "$pkg_base" | sed -E "s:$pkg_base([^ ]+).*$:\1:")
local active_version=$(echo "$pkginfo" | grep -E "$pkg_base.*\*$" | sed -E "s:$pkg_base([^ ]+).*\*$:\1:")
for installed_version in $installed_versions;
do
if [ "$installed_version" = "$required_version" ]; then
if [ "$active_version" = "$required_version" ]; then
already_installed "$package $required_version"
else
brew unlink "$package"
brew switch "$package" "$required_version"
fi
return
fi
done
fi
brew install $url
}
function brew_cask_install() {
local package=$1
if ! is_macos; then
return 1
fi
if brew cask list | grep -q "$package"; then
already_installed "$package"
else
brew cask install $@
fi
}
function brew_tap() {
local cask=$1
if ! is_macos; then
return 1
fi
if ! brew tap | grep -q "$cask"; then
brew tap "$cask"
fi
}
###############
# Linux
###############
function linux_update() {
! is_linux && return 1
if program_exists "apt"; then
apt_update
elif program_exists "pacman"; then
pacman_update
else
echo "Unsupported Linux distro."
exit 1;
fi
}
function linux_is_installed() {
! is_linux && return 1
if program_exists 'apt'; then
apt_is_installed "$@"
elif program_exists 'pacman'; then
pacman_is_installed "$@"
else
echo "Unsupported Linux distro."
exit 1;
fi
}
# FIXME This command assumes that package names in different package managers (apt, pacman) are same.
# At this moment, it works as expected because we only call it for installing maven and nodejs.
# If this list grows, please consider adding some sort of mapping mechanism.
function linux_install() {
! is_linux && return 1
! is_linux && return 0
if program_exists "apt"; then
apt_install "$@"
@ -196,16 +105,3 @@ function pacman_install() {
function load_rvm_if_available() {
[ -f ~/.rvm/scripts/rvm ] && source ~/.rvm/scripts/rvm
}
###############
# NVM
###############
function load_nvm_if_available() {
local nvm_path=${NVM_DIR:-~/.nvm}
[ -f ${nvm_path}/nvm.sh ] && chmod +x ${nvm_path}/nvm.sh && source ${nvm_path}/nvm.sh
}
function nvm_installed() {
declare -F nvm &>/dev/null
}

View File

@ -10,6 +10,10 @@ function is_linux() {
[[ "$OS" =~ Linux ]]
}
function is_nixos() {
is_linux && [[ "$(uname -v)" == *NixOS* ]]
}
function exit_unless_os_supported() {
if ! is_macos && ! is_linux; then
cecho "@red[[This install script currently supports Mac OS X and Linux \

View File

@ -22,10 +22,6 @@ else
PLATFORM=$1
fi
if [[ $PLATFORM == 'setup' ]]; then
load_nvm_if_available
fi
if ! program_version_exists node $EXPECTED_NODE_VERSION || ! program_version_exists yarn $EXPECTED_YARN_VERSION; then
echo -e "${YELLOW}********************************************************************************************"
@ -36,27 +32,23 @@ if ! program_version_exists node $EXPECTED_NODE_VERSION || ! program_version_exi
echo -e " \t\tfound\t\t$(yarn -v) ($(which yarn))"
echo -e "Please open another console to reload the environment, and then run 'make setup' if necessary."
load_nvm_if_available
if nvm_installed; then
echo -e "Afterwards, run 'nvm use status-im' in the terminal and try again."
fi
echo -e "**********************************************************************************************${NC}"
exit 1
fi
if [[ $PLATFORM == 'android' ]]; then
_localPropertiesPath=./android/local.properties
if [ ! -f $_localPropertiesPath ] || ! grep -Fq "ndk.dir" $_localPropertiesPath > /dev/null; 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
if [ ! -d $ANDROID_SDK_ROOT ]; then
echo -e "${GREEN}NDK setup not complete, please run 'make setup'!${NC}"
exit 1
fi
if [ ! -d $ANDROID_NDK_ROOT ]; then
echo -e "${GREEN}NDK setup not complete, please run 'make setup'!${NC}"
exit 1
fi
fi
if [[ $PLATFORM == 'setup' ]]; then
echo -e "${YELLOW}Finished! Please close your terminal, and reopen a new one before building Status.${NC}"
echo -e "${YELLOW}Finished! Please close your terminal, reopen a new one and type 'nix-shell' before building Status.${NC}"
else
echo -e "${GREEN}Finished!${NC}"
fi

View File

@ -7,6 +7,9 @@
# Usage: scripts/setup
########################################################################
YELLOW='\033[1;33m'
NC='\033[0m'
_current_dir=$(cd "${BASH_SOURCE%/*}" && pwd)
source "$_current_dir/lib/setup/path-support.sh"
@ -17,30 +20,58 @@ source_lib "installers.sh"
exit_unless_os_supported
load_nvm_if_available
load_rvm_if_available
####
setup_header "Checking prerequisites..."
if program_exists nix; then
if [ -z "$IN_NIX_SHELL" ]; then
if is_nixos; then
cecho "@b@yellow[[All's good, you can run 'make shell' now]]"
exit 0
else
cecho "@b@red[[Please run 'make shell' first]]"
exit 1
fi
fi
fi
if ! program_exists "curl"; then
cecho "@b@yellow[[Please install curl before running setup.]]"
exit 1
fi
if is_linux; then
watches=$(cat /proc/sys/fs/inotify/max_user_watches)
required_watches=524288
if [ $watches -lt $required_watches ]; then
cecho "@b@cyan[[fs.inotify.max_user_watches limit is too low ($watches), increasing it]]"
echo fs.inotify.max_user_watches=$required_watches | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
fi
if [ -f "/etc/arch-release" ]; then
# Arch Linux
userns=$(sysctl -n kernel.unprivileged_userns_clone)
if [ "$userns" != '1' ]; then
sudo sysctl kernel.unprivileged_userns_clone=1
fi
fi
fi
####
setup_header "Installing requirements..."
install_and_setup_package_manager
install_wget
install_java8
install_clojure_cli
install_leiningen
install_nsis
install_node
install_yarn
install_watchman
install_react_native_cli
install_android_sdk
install_android_ndk
install_maven
install_cocoapods
install_nix && \
install_react_native_cli && \
install_nsis && \
install_android_sdk && \
install_android_ndk || \
exit $?
####
echo && setup_header "Installing dependencies..."
dependency_setup make prepare-mobile
dependency_setup make prepare-mobile && \
setup_complete