unify multiple Makefile targets

Changes:
- Drop a bunch of `watch-{android,ios}-*` tagets
- Replace them with one `run-clojure`
- Drop a bunch of `react-native-*` targets
- Replace them with one `run-metro`
- Replace `run-{android,ios}` with `run-{android,ios}`
- Drop `startdev-{android,ios,desktop}*` targets
- Drop `prod-build-{android,ios}` as deprecated
- Drop `src/status_im/android/core.cljs`
- Drop `src/status_im/ios/core.cljs`
- Move `lsof` tool to `default` shell
- Replace them with one `init` `src/status_im/core.cljs`
- Use `init` in one `shadow-cljs.edn` target `mobile`
- Use `mobile` target in `nix/mobile/android/jsbundle`
- Update instructions in `STARTING_GUIDE.md`
- Use `gradle` shell for `android-clean` target

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-05-14 13:58:05 +02:00
parent 78a3f5aff5
commit 2f9593a7d2
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
10 changed files with 67 additions and 148 deletions

138
Makefile
View File

@ -1,4 +1,4 @@
.PHONY: nix-add-gcroots clean nix-clean react-native-android react-native-ios react-native-desktop test release _list _fix-node-perms _tmpdir-mk _tmpdir-rm
.PHONY: nix-add-gcroots clean nix-clean run-metro react-native-desktop test release _list _fix-node-perms _tmpdir-mk _tmpdir-rm
help: SHELL := /bin/sh
help: ##@other Show this help
@ -180,9 +180,6 @@ release-windows-desktop: ##@build build release for windows desktop release
scripts/build-desktop.sh; \
$(MAKE) watchman-clean
prod-build-android: jsbundle-android ##@legacy temporary legacy alias for jsbundle-android
@echo "${YELLOW}This a deprecated target name, use jsbundle-android.$(RESET)"
jsbundle-android: SHELL := /bin/sh
jsbundle-android: export TARGET := android
jsbundle-android: export BUILD_ENV ?= prod
@ -191,21 +188,14 @@ jsbundle-android: ##@jsbundle Compile JavaScript and Clojurescript into app dire
nix/scripts/build.sh targets.mobile.android.jsbundle && \
mv result/* ./
prod-build-ios: jsbundle-ios ##@legacy temporary legacy alias for jsbundle-ios
@echo "${YELLOW}This a deprecated target name, use jsbundle-ios.$(RESET)"
jsbundle-ios: export TARGET := ios
jsbundle-ios: export BUILD_ENV ?= prod
jsbundle-ios: ##@jsbundle Compile JavaScript and Clojure into index.ios.js
yarn shadow-cljs release ios
yarn shadow-cljs release mobile
#--------------
# status-go lib
# -------------
status-go-desktop: SHELL := /bin/sh
status-go-desktop: ##@status-go Compile status-go for desktop app
nix/scripts/build.sh targets.status-go.desktop
#--------------
status-go-android: SHELL := /bin/sh
status-go-android: ##@status-go Compile status-go for Android app
@ -215,49 +205,35 @@ status-go-ios: SHELL := /bin/sh
status-go-ios: ##@status-go Compile status-go for iOS app
nix/scripts/build.sh targets.status-go.mobile.ios
status-go-desktop: SHELL := /bin/sh
status-go-desktop: ##@status-go Compile status-go for desktop app
nix/scripts/build.sh targets.status-go.desktop
#--------------
# Watch, Build & Review changes
#--------------
# Clojure REPL
# -------------
_watch-%: ##@watch Start development for device
$(eval SYSTEM := $(word 2, $(subst -, , $@)))
$(eval DEVICE := $(word 3, $(subst -, , $@)))
yarn shadow-cljs watch $(SYSTEM)
run-clojure: export TARGET := default
run-clojure: ##@run Watch for and build Clojure changes for mobile
yarn shadow-cljs watch mobile
watch-ios-real: export TARGET := ios
watch-ios-real: _watch-ios-real
watch-ios-simulator: export TARGET := ios
watch-ios-simulator: _watch-ios-simulator
watch-android-real: export TARGET := android
watch-android-real: _watch-android-real
watch-android-avd: export TARGET := android
watch-android-avd: _watch-android-avd
watch-android-genymotion: export TARGET ?= android
watch-android-genymotion: _watch-android-genymotion
watch-desktop: export TARGET ?= $(HOST_OS)
watch-desktop:
run-clojure-desktop: export TARGET ?= $(HOST_OS)
run-clojure-desktop: #@run Watch for and build Clojure changes for desktop
clj -R:dev build.clj watch --platform desktop
desktop-server: export TARGET ?= $(HOST_OS)
desktop-server:
node ubuntu-server.js
run-metro: export TARGET := default
run-metro: ##@run Start Metro to build React Native changes
@scripts/start-react-native.sh
#--------------
# Run React-Native app
#--------------
_run-%:
$(eval SYSTEM := $(word 2, $(subst -, , $@)))
npx react-native run-$(SYSTEM)
run-re-frisk: export TARGET := clojure
run-re-frisk: ##@run Start re-frisk server
yarn shadow-cljs run re-frisk-remote.core/start
# TODO: Migrate this to a Nix recipe, much the same way as nix/mobile/android/targets/release-android.nix
run-android: export TARGET := android
run-android: ##@run Build Android APK and start it on the device
npx react-native run-android --appIdSuffix debug
run-desktop: export TARGET ?= $(HOST_OS)
run-desktop: _run-desktop ##@run Run Desktop build
SIMULATOR=
run-ios: export TARGET := ios
run-ios: ##@run Build iOS app and start it in a simulator/device
@ -267,6 +243,10 @@ else
npx react-native run-ios
endif
run-desktop: export TARGET ?= $(HOST_OS)
run-desktop: ##@run Run Desktop build
npx react-native run-desktop
#--------------
# Tests
#--------------
@ -296,29 +276,24 @@ coverage: ##@test Run tests once in NodeJS generating coverage
#--------------
# Other
#--------------
start-desktop-server: export TARGET ?= $(HOST_OS)
start-desktop-server: #@other Start ubuntu-server.js for desktop
node ubuntu-server.js
react-native-desktop: export TARGET ?= $(HOST_OS)
react-native-desktop: export _NIX_PURE ?= true
react-native-desktop: ##@other Start react native packager
@scripts/start-react-native.sh
react-native-android: export TARGET := android
react-native-android: export _NIX_PURE ?= true
react-native-android: ##@other Start react native packager for Android client
@scripts/start-react-native.sh
react-native-ios: export TARGET := ios
react-native-ios: export _NIX_PURE ?= true
react-native-ios: ##@other Start react native packager for Android client
@scripts/start-react-native.sh
geth-connect: export TARGET := android-env
geth-connect: ##@other Connect to Geth on the device
adb forward tcp:8545 tcp:8545 && \
build/bin/geth attach http://localhost:8545
android-clean: export TARGET := android
android-clean: export TARGET := gradle
android-clean: ##@prepare Clean Gradle state
git clean -dxf -f ./android/app/build
git clean -dxf -f ./android/app/build; \
[[ -d android/.gradle ]] && cd android && ./gradlew clean
android-ports: export TARGET := android-env
@ -345,49 +320,12 @@ _list: SHELL := /bin/sh
_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 '^$@$$'
_unknown-startdev-target-%: SHELL := /bin/sh
_unknown-startdev-target-%:
@ echo "Unknown target device '$*'. Supported targets:"; \
${MAKE} _list | grep "watch-" | sed s/watch-/startdev-/; \
exit 1
#--------------
# REPLs
#--------------
_startdev-%: SHELL := /bin/sh
_startdev-%:
$(eval SYSTEM := $(word 2, $(subst -, , $@)))
$(eval DEVICE := $(word 3, $(subst -, , $@)))
@ if [ -z "$(DEVICE)" ]; then \
$(MAKE) watch-$(SYSTEM) || $(MAKE) _unknown-startdev-target-$@; \
else \
$(MAKE) watch-$(SYSTEM)-$(DEVICE) || $(MAKE) _unknown-startdev-target-$@; \
fi
repl-clojure: export TARGET := clojure
repl-clojure: ##@repl Start Clojure repl for mobile App
yarn shadow-cljs cljs-repl mobile
startdev-android-avd: export TARGET = android
startdev-android-avd: _startdev-android-avd
startdev-android-avd: ##@startdev Compile Clojure for Android AVD
startdev-android-genymotion: export TARGET = android
startdev-android-genymotion: _startdev-android-genymotion
startdev-android-genymotion: ##@startdev Compile Clojure for Genymotion
startdev-android-real: export TARGET = android
startdev-android-real: _startdev-android-real
startdev-android-real: ##@startdev Compile Clojure for Android real device
startdev-ios-real: export TARGET = ios
startdev-ios-real: _startdev-ios-real
startdev-ios-real: ##@startdev Compile Clojure for iOS device
startdev-ios-simulator: export TARGET = ios
startdev-ios-simulator: _startdev-ios-simulator
startdev-ios-simulator: ##@startdev Compile Clojure for iOS simulator
startdev-desktop: export TARGET ?= $(HOST_OS)
startdev-desktop: _startdev-desktop
re-frisk: export TARGET := clojure
re-frisk: ##@re-frisk start re-frisk server
yarn shadow-cljs run re-frisk-remote.core/start
repl-ios: export TARGET := clojure
repl-ios: ##@repl-ios start repl for ios project
yarn shadow-cljs cljs-repl ios
repl-android: export TARGET := clojure
repl-android: ##@repl-android start repl for android project
yarn shadow-cljs cljs-repl android
repl-nix: nix-repl ##@repl Start an interactive Nix REPL

View File

@ -21,11 +21,11 @@ For more `make` targets run `make help`.
There are three steps necessary to start development, in this case for Android:
1. `make startdev-android-real` - Compiles Clojure into JavaScript for real device
2. `make react-native-android` - Watches JavaScript code and updates the App
1. `make run-clojure` - Compiles Clojure into JavaScript, watches for changes on cljs files, and hot-reloads code in the app
2. `make run-metro` - Starts metro bundler and watches JavaScript code
3. `make run-android` - Builds the Android app and starts it on the device
The first two will continue watching for changes and keep re-building the app.
The first two will continue watching for changes and keep re-building the app. They need to be ready first.
The last one will exit once the app is up and ready.
# Manual Steps

View File

@ -51,7 +51,7 @@ Developer updates `package.json` file with a new dependency using a GitHub URL.
```
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#feature/exportKeyWithPath",
```
Afterwards, when running e.g. `make react-native-android`, they might see the following confusing error:
Afterwards, when running e.g. `make run-metro`, they might see the following confusing error:
```
# macOS
fatal: unable to access 'https://github.com/siphiuel/react-native-status-keycard.git/': SSL certificate problem: unable to get local issuer certificate

View File

@ -2,11 +2,10 @@
# This Nix expression builds the js files for the current repository given a node modules Nix expression
#
{ target ? "android"
, stdenv, lib, deps, pkgs }:
{ stdenv, lib, deps, pkgs }:
stdenv.mkDerivation {
name = "status-react-build-jsbundle-${target}";
name = "status-react-build-jsbundle-android";
src =
let path = ./../../../..;
in builtins.path { # We use builtins.path so that we can name the resulting derivation, otherwise the name would be taken from the checkout directory, which is outside of our control
@ -55,10 +54,12 @@ stdenv.mkDerivation {
buildPhase = ''
# Assemble CLASSPATH from available clojure dependencies.
# We append 'src' so it can find the local sources.
export CLASS_PATH="$(find ${deps.clojure} -iname '*.jar' | tr '\n' ':')src"
export CLASS_PATH="$(find ${deps.clojure} \
-iname '*.jar' | tr '\n' ':')src"
# target must be one of the builds defined in shadow-cljs.edn
java -cp "$CLASS_PATH" clojure.main -m shadow.cljs.devtools.cli release ${target}
java -cp "$CLASS_PATH" clojure.main \
-m shadow.cljs.devtools.cli release mobile
'';
installPhase = ''
mkdir -p $out

View File

@ -20,6 +20,7 @@ let
# core utilities that should always be present in a shell
bash curl wget file unzip flock rsync
git gnumake jq ncurses gnugrep parallel
lsof # used in start-react-native.sh
# build specific utilities
clojure maven watchman
# other nice to have stuff

View File

@ -32,10 +32,10 @@
:cache-blockers #{status-im.utils.js-resources}
:builds {:android
:builds {:mobile
{:target :react-native
:output-dir "app"
:init-fn status-im.android.core/init
:init-fn status-im.core/init
:dev {:devtools {:after-load status-im.reloader/reload
:preloads [re-frisk-remote.preload]}
:compiler-options {:closure-defines
@ -55,27 +55,6 @@
:fn-invoke-direct true
:optimizations :advanced
:js-options {:js-provider :closure}}}}
:ios
{:target :react-native
:output-dir "app"
:init-fn status-im.ios.core/init
:dev {:devtools {:after-load status-im.reloader/reload
:preloads [re-frisk-remote.preload]}
:compiler-options {:closure-defines
{re-frame.trace/trace-enabled? true}
:source-map false}
;; if you want to use a real device, set your local ip
;; in the SHADOW_HOST env variable to make sure that
;; it will use the right interface
:local-ip #shadow/env "SHADOW_HOST"}
:chunks {:fleets status-im.default-fleet/default-fleets}
:release {:compiler-options {:output-feature-set :es6
:warnings-as-errors true
:infer-externs :auto
:static-fns true
:fn-invoke-direct true
:optimizations :advanced
:js-options {:js-provider :closure}}}}
;; the tests are ran with node, react-native dependencies are mocked
;; by using node --require override.js, which uses the node-library
;; produced by the target :mocks below and redefines node require

View File

@ -1,7 +0,0 @@
(ns status-im.android.core
(:require [status-im.native-module.core :as status]
[status-im.core :as core]))
(defn init []
(status/set-soft-input-mode status/adjust-resize)
(core/init core/root))

View File

@ -11,6 +11,7 @@
[reagent.core :as reagent]
[reagent.impl.batching :as batching]
[status-im.i18n :as i18n]
[status-im.native-module.core :as status]
[status-im.ui.components.react :as react]
[status-im.ui.screens.views :as views]
[status-im.utils.error-handler :as error-handler]
@ -77,10 +78,12 @@
:display-name "root"
:reagent-render views/main}))
(defn init [app-root]
(defn init []
(utils.logs/init-logs)
(error-handler/register-exception-handler!)
(enableScreens)
(re-frame/dispatch-sync [:init/app-started])
(.registerComponent ^js app-registry "StatusIm" #(reagent/reactify-component app-root))
(when platform/android?
(status/set-soft-input-mode status/adjust-resize))
(.registerComponent ^js app-registry "StatusIm" #(reagent/reactify-component root))
(snoopy/subscribe!))

View File

@ -1,15 +1,20 @@
(ns status-im.desktop.core
(:require [reagent.core :as reagent]
[re-frame.core :as re-frame]
["react-native" :as rn]
status-im.utils.db
status-im.subs
[status-im.ui.screens.views :as views]
[status-im.ui.components.react :as react]
[status-im.core :as core]
[status-im.utils.snoopy :as snoopy]
[status-im.utils.error-handler :as error-handler]
[status-im.utils.logging.core :as utils.logs]
[status-im.ui.screens.desktop.views :as desktop-views]
[status-im.desktop.deep-links :as deep-links]
[status-im.utils.config :as config]))
(def app-registry (.-AppRegistry rn))
(defn app-state-change-handler [state]
(re-frame/dispatch [:app-state-change state]))
@ -34,4 +39,8 @@
desktop-views/main)})))
(defn init []
(core/init app-root))
(utils.logs/init-logs)
(error-handler/register-exception-handler!)
(re-frame/dispatch-sync [:init/app-started])
(.registerComponent ^js app-registry "StatusIm" #(reagent/reactify-component app-root))
(snoopy/subscribe!))

View File

@ -1,5 +0,0 @@
(ns status-im.ios.core
(:require [status-im.core :as core]))
(defn init []
(core/init core/root))