Improve makefile to only make Nix install the bare minimum for intended platform

Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
Pedro Pombeiro 2019-04-12 10:36:30 +02:00
parent 42a3b7d195
commit 89f34a7707
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
7 changed files with 46 additions and 13 deletions

View File

@ -25,6 +25,7 @@ HELP_FUN = \
}; \ }; \
print "\n"; \ print "\n"; \
} }
HOST_OS := $(shell uname | tr '[:upper:]' '[:lower:]')
export NIX_CONF_DIR = $(PWD)/nix export NIX_CONF_DIR = $(PWD)/nix
@ -61,37 +62,45 @@ 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: export TARGET_OS ?= android
release-android: ##@build build release for Android release-android: ##@build build release for Android
@$(MAKE) prod-build-android && \ @$(MAKE) prod-build-android && \
react-native run-android --variant=release react-native run-android --variant=release
release-ios: export TARGET_OS ?= ios
release-ios: ##@build build release for iOS release release-ios: ##@build build release for iOS release
# Open XCode inside the Nix context # Open XCode inside the Nix context
@$(MAKE) prod-build-ios && \ @$(MAKE) prod-build-ios && \
@echo "Build in XCode, see https://status.im/build_status/ for instructions" && \ echo "Build in XCode, see https://status.im/build_status/ for instructions" && \
open ios/StatusIm.xcworkspace open ios/StatusIm.xcworkspace
release-desktop: export TARGET_OS ?= $(HOST_OS)
release-desktop: ##@build build release for desktop release release-desktop: ##@build build release for desktop release
@$(MAKE) prod-build-desktop && \ @$(MAKE) prod-build-desktop && \
scripts/build-desktop.sh scripts/build-desktop.sh
release-windows-desktop: export TARGET_OS ?= windows
release-windows-desktop: ##@build build release for desktop release release-windows-desktop: ##@build build release for desktop release
@$(MAKE) prod-build-desktop && \ @$(MAKE) prod-build-desktop && \
TARGET_SYSTEM_NAME=Windows scripts/build-desktop.sh TARGET_SYSTEM_NAME=Windows scripts/build-desktop.sh
release-desktop: export TARGET_OS ?= $(HOST_OS)
prod-build: 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: export TARGET_OS ?= android
prod-build-android: 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: export TARGET_OS ?= ios
prod-build-ios: 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-android: export TARGET_OS ?= android
prod-build-desktop: 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 && \
@ -107,20 +116,27 @@ _watch-%: ##@watch Start development for device
scripts/prepare-for-platform.sh $(SYSTEM) scripts/prepare-for-platform.sh $(SYSTEM)
clj -R:dev build.clj watch --platform $(SYSTEM) --$(SYSTEM)-device $(DEVICE) clj -R:dev build.clj watch --platform $(SYSTEM) --$(SYSTEM)-device $(DEVICE)
watch-ios-real: export TARGET_OS ?= ios
watch-ios-real: _watch-ios-real ##@watch Start development for iOS real device watch-ios-real: _watch-ios-real ##@watch Start development for iOS real device
watch-ios-simulator: export TARGET_OS ?= ios
watch-ios-simulator: _watch-ios-simulator ##@watch Start development for iOS simulator watch-ios-simulator: _watch-ios-simulator ##@watch Start development for iOS simulator
watch-android-real: export TARGET_OS ?= android
watch-android-real: _watch-android-real ##@watch Start development for Android real device watch-android-real: _watch-android-real ##@watch Start development for Android real device
watch-android-avd: export TARGET_OS ?= android
watch-android-avd: _watch-android-avd ##@watch Start development for Android AVD watch-android-avd: _watch-android-avd ##@watch Start development for Android AVD
watch-android-genymotion: export TARGET_OS ?= android
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: export TARGET_OS ?= $(HOST_OS)
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: export TARGET_OS ?= $(HOST_OS)
desktop-server: desktop-server:
@scripts/prepare-for-platform.sh desktop && \ @scripts/prepare-for-platform.sh desktop && \
node ubuntu-server.js node ubuntu-server.js
@ -133,13 +149,16 @@ _run-%:
@scripts/prepare-for-platform.sh $(SYSTEM) && \ @scripts/prepare-for-platform.sh $(SYSTEM) && \
react-native run-$(SYSTEM) react-native run-$(SYSTEM)
run-android: export TARGET_OS ?= android
run-android: ##@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: export TARGET_OS ?= $(HOST_OS)
run-desktop: _run-desktop ##@run Run Desktop build run-desktop: _run-desktop ##@run Run Desktop build
SIMULATOR= SIMULATOR=
run-ios: export TARGET_OS ?= ios
run-ios: ##@run Run iOS build run-ios: ##@run Run iOS build
ifneq ("$(SIMULATOR)", "") ifneq ("$(SIMULATOR)", "")
@scripts/prepare-for-platform.sh ios && \ @scripts/prepare-for-platform.sh ios && \
@ -162,19 +181,23 @@ test-auto: ##@test Run tests in interactive (auto) mode in NodeJS
#-------------- #--------------
# Other # Other
#-------------- #--------------
run-desktop: export TARGET_OS ?= $(HOST_OS)
react-native: ##@other Start react native packager react-native: ##@other Start react native packager
@scripts/start-react-native.sh @scripts/start-react-native.sh
geth-connect: export TARGET_OS ?= android
geth-connect: ##@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: export TARGET_OS ?= android
android-ports: ##@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: export TARGET_OS ?= android
android-logcat: android-logcat:
adb logcat | grep -e StatusModule -e ReactNativeJS -e StatusNativeLogs adb logcat | grep -e StatusModule -e ReactNativeJS -e StatusNativeLogs
@ -184,23 +207,29 @@ _list:
_unknown-startdev-target-%: SHELL := /bin/sh _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-%: _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} || exit 1
@ if [ -z "$(DEVICE)" ]; then \ @ if [ -z "$(DEVICE)" ]; then \
$(MAKE) watch-$(SYSTEM) || $(MAKE) _unknown-startdev-target-$@; \ $(MAKE) watch-$(SYSTEM) || $(MAKE) _unknown-startdev-target-$@; \
else \ else \
$(MAKE) watch-$(SYSTEM)-$(DEVICE) || $(MAKE) _unknown-startdev-target-$@; \ $(MAKE) watch-$(SYSTEM)-$(DEVICE) || $(MAKE) _unknown-startdev-target-$@; \
fi fi
startdev-android-avd: export TARGET_OS ?= android
startdev-android-avd: _startdev-android-avd startdev-android-avd: _startdev-android-avd
startdev-android-genymotion: export TARGET_OS ?= android
startdev-android-genymotion: _startdev-android-genymotion startdev-android-genymotion: _startdev-android-genymotion
startdev-android-real: export TARGET_OS ?= android
startdev-android-real: _startdev-android-real startdev-android-real: _startdev-android-real
startdev-desktop: export TARGET_OS ?= $(HOST_OS)
startdev-desktop: _startdev-desktop startdev-desktop: _startdev-desktop
startdev-ios-real: export TARGET_OS ?= ios
startdev-ios-real: _startdev-ios-real startdev-ios-real: _startdev-ios-real
startdev-ios-simulator: export TARGET_OS ?= ios
startdev-ios-simulator: _startdev-ios-simulator startdev-ios-simulator: _startdev-ios-simulator

View File

@ -38,7 +38,7 @@ pipeline {
stage('Build') { stage('Build') {
steps { steps {
sh """ sh """
nix build --no-link && nix build -v --no-link &&
nix-shell --run echo nix-shell --run echo
""" """
} }

View File

@ -39,7 +39,7 @@ pipeline {
steps { steps {
sh """ sh """
. ~/.nix-profile/etc/profile.d/nix.sh && \ . ~/.nix-profile/etc/profile.d/nix.sh && \
nix build --no-link && \ nix build -v --no-link && \
nix-shell --run echo nix-shell --run echo
""" """
} }

View File

@ -1,4 +1,4 @@
# target-os = [ 'windows' 'linux' 'macos' 'android' 'ios' 'all' ] # target-os = [ 'windows' 'linux' 'macos' 'darwin' 'android' 'ios' 'all' ]
{ config ? { android_sdk.accept_license = true; }, { config ? { android_sdk.accept_license = true; },
pkgs ? import ((import <nixpkgs> { }).fetchFromGitHub { pkgs ? import ((import <nixpkgs> { }).fetchFromGitHub {
owner = "status-im"; owner = "status-im";

View File

@ -1,4 +1,4 @@
# target-os = [ 'windows' 'linux' 'macos' 'android' 'ios' ] # target-os = [ 'windows' 'linux' 'macos' 'darwin' 'android' 'ios' ]
{ system ? builtins.currentSystem { system ? builtins.currentSystem
, config ? {}, overlays ? [] , config ? {}, overlays ? []
, pkgs ? (import <nixpkgs> { inherit system config overlays; }) , pkgs ? (import <nixpkgs> { inherit system config overlays; })
@ -7,15 +7,18 @@
with pkgs; with pkgs;
let let
sanitized-target-os = sanitized-target-os =
if (builtins.any (os: target-os == os) [ "linux" "android" "windows" "macos" "ios" "all" ]) if (builtins.any (os: target-os == os) [ "linux" "android" "windows" "macos" "darwin" "ios" "all" ])
then target-os then target-os
else throw "Unknown value for target-os: '${target-os}'"; else throw "Unknown value for target-os: '${target-os}'";
# based on the value passed in through target-os, check if we're targetting a desktop platform
targetDesktop = { targetDesktop = {
"linux" = true; "linux" = true;
"windows" = true; "windows" = true;
"macos" = true; "macos" = true;
"darwin" = true;
"all" = true; "all" = true;
}.${sanitized-target-os} or false; }.${sanitized-target-os} or false;
# based on the value passed in through target-os, check if we're targetting a mobile platform
targetMobile = { targetMobile = {
"android" = true; "android" = true;
"ios" = true; "ios" = true;

View File

@ -10,6 +10,7 @@ let
}.${target-os} or false; }.${target-os} or false;
targetDarwin = { targetDarwin = {
"macos" = true; "macos" = true;
"darwin" = true;
"all" = isDarwin; "all" = isDarwin;
}.${target-os} or false; }.${target-os} or false;
targetWindows = { targetWindows = {

View File

@ -20,10 +20,10 @@ if ! command -v "nix" >/dev/null 2>&1; then
fi fi
if command -v "nix" >/dev/null 2>&1; then if command -v "nix" >/dev/null 2>&1; then
echo -e "${GREEN}Configuring Nix shell...${NC}"; echo -e "${GREEN}Configuring Nix shell for target '${TARGET_OS:=all}'...${NC}";
if [[ $@ == "ENTER_NIX_SHELL" ]]; then if [[ $@ == "ENTER_NIX_SHELL" ]]; then
exec nix-shell --show-trace exec nix-shell --show-trace --argstr target-os ${TARGET_OS}
else else
exec nix-shell --show-trace --run "$@" exec nix-shell --show-trace --argstr target-os ${TARGET_OS} --run "$@"
fi fi
fi fi