Make nix-shell implicit and add `desktop-server` target

- The makefile now defines environment variables for the Desktop debug environment that allows running side by side with release

Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
Pedro Pombeiro 2019-04-05 19:22:49 +02:00
parent ea837ff353
commit 3230f00c6c
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
5 changed files with 85 additions and 75 deletions

122
Makefile
View File

@ -1,4 +1,4 @@
.PHONY: clean setup react-native test release _ensure-in-nix-shell _list .PHONY: clean clean-nix react-native test release _list
help: ##@other Show this help help: ##@other Show this help
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST) @perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
@ -28,35 +28,30 @@ HELP_FUN = \
export NIX_CONF_DIR = $(PWD)/nix export NIX_CONF_DIR = $(PWD)/nix
export REACT_SERVER_PORT ?= 5001 # any value different from default 5000 will work; this has to be specified for both the Node.JS server process and the Qt process
export STATUS_NODE_PORT ?= 12345 # no need to specify this if just running dev instance alongside release build
export STATUS_DATA_DIR ?= ~/status-files/data1 # this is where Realm data files, Geth node data, and logs will reside; also not strictly needed for dev alongside release
# WARNING: This has to be located right before the targets
ifdef IN_NIX_SHELL
SHELL := env bash
else
SHELL := ./nix/shell.sh
endif
# Main targets # Main targets
clean: SHELL := /bin/sh
clean: ##@prepare Remove all output folders clean: ##@prepare Remove all output folders
git clean -dxf -f git clean -dxf -f
clean-nix: SHELL := /bin/sh
clean-nix: ##@prepare Remove complete nix setup clean-nix: ##@prepare Remove complete nix setup
sudo rm -rf /nix ~/.cache/nix sudo rm -rf /nix ~/.cache/nix
setup: ##@prepare Install all the requirements for status-react
@./scripts/setup
_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 shell: ##@prepare Enter into a pre-configured shell
ifndef IN_NIX_SHELL ifndef IN_NIX_SHELL
@if command -v "nix" >/dev/null 2>&1 || [ -f ~/.nix-profile/etc/profile.d/nix.sh ]; then \ @ENTER_NIX_SHELL
echo "Configuring Nix shell..."; \
if ! command -v "nix" >/dev/null 2>&1; then \
. ~/.nix-profile/etc/profile.d/nix.sh; \
nix-shell; \
else \
nix-shell; \
fi \
else \
echo "Please run 'make setup' first"; \
fi
else else
@echo "Nix shell is already active" @echo "Nix shell is already active"
endif endif
@ -66,51 +61,47 @@ endif
#---------------- #----------------
release: release-android release-ios ##@build build release for Android and iOS release: release-android release-ios ##@build build release for Android and iOS
release-android: prod-build-android ##@build build release for Android release-android: ##@build build release for Android
ifdef IN_NIX_SHELL @$(MAKE) prod-build-android && \
react-native run-android --variant=release react-native run-android --variant=release
endif
release-ios: prod-build-ios ##@build build release for iOS release release-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 XCode inside the Nix context
@$(MAKE) prod-build-ios && \
@echo "Build in XCode, see https://status.im/build_status/ for instructions" && \
open ios/StatusIm.xcworkspace open ios/StatusIm.xcworkspace
endif
release-desktop: prod-build-desktop ##@build build release for desktop release release-desktop: ##@build build release for desktop release
ifdef IN_NIX_SHELL @$(MAKE) prod-build-desktop && \
scripts/build-desktop.sh scripts/build-desktop.sh
endif
release-windows-desktop: prod-build-desktop ##@build build release for desktop release release-windows-desktop: ##@build build release for desktop release
ifdef IN_NIX_SHELL @$(MAKE) prod-build-desktop && \
TARGET_SYSTEM_NAME=Windows scripts/build-desktop.sh TARGET_SYSTEM_NAME=Windows scripts/build-desktop.sh
endif
prod-build: _ensure-in-nix-shell prod-build:
scripts/prepare-for-platform.sh android scripts/prepare-for-platform.sh android && \
scripts/prepare-for-platform.sh ios scripts/prepare-for-platform.sh ios && \
lein prod-build lein prod-build
prod-build-android: _ensure-in-nix-shell prod-build-android:
scripts/prepare-for-platform.sh android scripts/prepare-for-platform.sh android && \
lein prod-build-android lein prod-build-android
prod-build-ios: _ensure-in-nix-shell prod-build-ios:
scripts/prepare-for-platform.sh ios scripts/prepare-for-platform.sh ios && \
lein prod-build-ios lein prod-build-ios
prod-build-desktop: _ensure-in-nix-shell prod-build-desktop:
git clean -qdxf -f ./index.desktop.js desktop/ git clean -qdxf -f ./index.desktop.js desktop/ && \
scripts/prepare-for-platform.sh desktop scripts/prepare-for-platform.sh desktop && \
lein prod-build-desktop lein prod-build-desktop
#-------------- #--------------
# REPL # REPL
# ------------- # -------------
_watch-%: _ensure-in-nix-shell ##@watch Start development for device _watch-%: ##@watch Start development for device
$(eval SYSTEM := $(word 2, $(subst -, , $@))) $(eval SYSTEM := $(word 2, $(subst -, , $@)))
$(eval DEVICE := $(word 3, $(subst -, , $@))) $(eval DEVICE := $(word 3, $(subst -, , $@)))
scripts/prepare-for-platform.sh $(SYSTEM) scripts/prepare-for-platform.sh $(SYSTEM)
@ -127,29 +118,34 @@ 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-android-genymotion: _watch-android-genymotion ##@watch Start development for Android Genymotion
watch-desktop: ##@watch Start development for Desktop watch-desktop: ##@watch Start development for Desktop
scripts/prepare-for-platform.sh desktop @scripts/prepare-for-platform.sh desktop && \
clj -R:dev build.clj watch --platform desktop clj -R:dev build.clj watch --platform desktop
desktop-server:
@scripts/prepare-for-platform.sh desktop && \
node ubuntu-server.js
#-------------- #--------------
# Run # Run
# ------------- # -------------
_run-%: _ensure-in-nix-shell _run-%:
$(eval SYSTEM := $(word 2, $(subst -, , $@))) $(eval SYSTEM := $(word 2, $(subst -, , $@)))
scripts/prepare-for-platform.sh $(SYSTEM) @scripts/prepare-for-platform.sh $(SYSTEM) && \
react-native run-$(SYSTEM) react-native run-$(SYSTEM)
run-android: _ensure-in-nix-shell ##@run Run Android build run-android: ##@run Run Android build
scripts/prepare-for-platform.sh android @scripts/prepare-for-platform.sh android && \
react-native run-android --appIdSuffix debug react-native run-android --appIdSuffix debug
run-desktop: _run-desktop ##@run Run Desktop build run-desktop: _run-desktop ##@run Run Desktop build
SIMULATOR= SIMULATOR=
run-ios: _ensure-in-nix-shell ##@run Run iOS build run-ios: ##@run Run iOS build
scripts/prepare-for-platform.sh ios
ifneq ("$(SIMULATOR)", "") ifneq ("$(SIMULATOR)", "")
@scripts/prepare-for-platform.sh ios && \
react-native run-ios --simulator="$(SIMULATOR)" react-native run-ios --simulator="$(SIMULATOR)"
else else
@scripts/prepare-for-platform.sh ios && \
react-native run-ios react-native run-ios
endif endif
@ -157,40 +153,42 @@ endif
# Tests # Tests
#-------------- #--------------
test: _ensure-in-nix-shell ##@test Run tests once in NodeJS test: ##@test Run tests once in NodeJS
lein with-profile test doo node test once lein with-profile test doo node test once
test-auto: _ensure-in-nix-shell ##@test Run tests in interactive (auto) mode in NodeJS test-auto: ##@test Run tests in interactive (auto) mode in NodeJS
lein with-profile test doo node test lein with-profile test doo node test
#-------------- #--------------
# Other # Other
#-------------- #--------------
react-native: _ensure-in-nix-shell ##@other Start react native packager react-native: ##@other Start react native packager
@scripts/start-react-native.sh @scripts/start-react-native.sh
geth-connect: _ensure-in-nix-shell ##@other Connect to Geth on the device geth-connect: ##@other Connect to Geth on the device
adb forward tcp:8545 tcp:8545 adb forward tcp:8545 tcp:8545 && \
build/bin/geth attach http://localhost:8545 build/bin/geth attach http://localhost:8545
android-ports: _ensure-in-nix-shell ##@other Add proxies to Android Device/Simulator android-ports: ##@other Add proxies to Android Device/Simulator
adb reverse tcp:8081 tcp:8081 adb reverse tcp:8081 tcp:8081 && \
adb reverse tcp:3449 tcp:3449 adb reverse tcp:3449 tcp:3449 && \
adb reverse tcp:4567 tcp:4567 adb reverse tcp:4567 tcp:4567 && \
adb forward tcp:5561 tcp:5561 adb forward tcp:5561 tcp:5561
android-logcat: _ensure-in-nix-shell android-logcat:
adb logcat | grep -e StatusModule -e ReactNativeJS -e StatusNativeLogs adb logcat | grep -e StatusModule -e ReactNativeJS -e StatusNativeLogs
_list: SHELL := /bin/sh
_list: _list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
_unknown-startdev-target-%: SHELL := /bin/sh
_unknown-startdev-target-%: _unknown-startdev-target-%:
@ echo "Unknown target device '$*'. Supported targets:" @ echo "Unknown target device '$*'. Supported targets:"
@ ${MAKE} _list | grep "watch-" | sed s/watch-/startdev-/ @ ${MAKE} _list | grep "watch-" | sed s/watch-/startdev-/
@ exit 1 @ exit 1
_startdev-%: _ensure-in-nix-shell _startdev-%:
$(eval SYSTEM := $(word 2, $(subst -, , $@))) $(eval SYSTEM := $(word 2, $(subst -, , $@)))
$(eval DEVICE := $(word 3, $(subst -, , $@))) $(eval DEVICE := $(word 3, $(subst -, , $@)))
scripts/prepare-for-platform.sh ${SYSTEM} || $(MAKE) _unknown-startdev-target-$@ scripts/prepare-for-platform.sh ${SYSTEM} || $(MAKE) _unknown-startdev-target-$@

19
nix/shell.sh Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
GREEN='\033[0;32m'
NC='\033[0m'
export TERM=xterm # fix for colors
shift # we remove the first -c from arguments
if ! command -v "nix" >/dev/null 2>&1; then
echo -e "${GREEN}Setting up environment...${NC}"
./scripts/setup
fi
if command -v "nix" >/dev/null 2>&1 || [ -f ~/.nix-profile/etc/profile.d/nix.sh ]; then
echo -e "${GREEN}Configuring Nix shell...${NC}";
if [[ $@ == "ENTER_NIX_SHELL" ]]; then
. ~/.nix-profile/etc/profile.d/nix.sh && exec nix-shell
else
. ~/.nix-profile/etc/profile.d/nix.sh && exec nix-shell --run "$@"
fi
fi

View File

@ -23,16 +23,9 @@ function install_nix() {
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 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 fi
local buildFlags=''
[ -n "$CI_ENVIRONMENT" ] && buildFlags='-v'
. ${HOME}/.nix-profile/etc/profile.d/nix.sh && \
NIX_CONF_DIR=$(cd "${BASH_SOURCE%/*}" && pwd)/nix \
nix build --no-link ${buildFlags} -f ${GIT_ROOT}/default.nix
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo -e "${YELLOW}**********************************************************************************************************" echo -e "${YELLOW}**********************************************************************************************************"
echo "The Nix package manager was successfully installed. Please run \`make shell\` to initialize the Nix environment." echo "The Nix package manager was successfully installed."
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}" echo -e "**********************************************************************************************************${NC}"
fi fi
else else

View File

@ -38,7 +38,7 @@ if [ -z "$IN_NIX_SHELL" ]; then
fi fi
fi fi
if [[ $PLATFORM == 'android' ]]; then if [ "$PLATFORM" == 'android' ]; then
if [ ! -d $ANDROID_SDK_ROOT ]; then if [ ! -d $ANDROID_SDK_ROOT ]; then
echo -e "${GREEN}NDK setup not complete, please run 'make setup'!${NC}" echo -e "${GREEN}NDK setup not complete, please run 'make setup'!${NC}"
exit 1 exit 1
@ -47,6 +47,9 @@ if [[ $PLATFORM == 'android' ]]; then
echo -e "${GREEN}NDK setup not complete, please run 'make setup'!${NC}" echo -e "${GREEN}NDK setup not complete, please run 'make setup'!${NC}"
exit 1 exit 1
fi fi
elif [ "$PLATFORM" == 'ios' ] && [ "$(uname)" != "Darwin" ]; then
echo -e "${RED}iOS builds are only possible on macOS hosts${NC}"
exit 1
fi fi
if [[ $PLATFORM == 'setup' ]]; then if [[ $PLATFORM == 'setup' ]]; then

View File

@ -2,14 +2,11 @@
######################################################################## ########################################################################
# This install script will setup your development dependencies on OS X # This install script will setup your development dependencies on OS X
# or Ubuntu. Ubuntu 16.04 is the only tested version. # or Ubuntu. Ubuntu 18.04 is the only tested version.
# #
# Usage: scripts/setup # Usage: scripts/setup
######################################################################## ########################################################################
YELLOW='\033[1;33m'
NC='\033[0m'
_current_dir=$(cd "${BASH_SOURCE%/*}" && pwd) _current_dir=$(cd "${BASH_SOURCE%/*}" && pwd)
source "$_current_dir/lib/setup/path-support.sh" source "$_current_dir/lib/setup/path-support.sh"