2020-05-18 10:15:49 +00:00
|
|
|
{ stdenv, pkgs, deps, lib, config, callPackage,
|
|
|
|
watchmanFactory, androidPkgs, patchMavenSources,
|
|
|
|
jsbundle, status-go }:
|
2019-06-04 16:50:29 +00:00
|
|
|
|
2020-04-26 12:40:06 +00:00
|
|
|
{
|
|
|
|
buildEnv ? "prod", # Value for BUILD_ENV checked by Clojure code at compile time
|
|
|
|
secretsFile ? "", # Path to the file containing secret environment variables
|
2019-09-10 09:50:09 +00:00
|
|
|
watchmanSockPath ? "", # Path to the socket file exposed by an external watchman instance (workaround needed for building Android on macOS)
|
2019-06-04 16:50:29 +00:00
|
|
|
}:
|
|
|
|
|
2020-04-26 12:40:06 +00:00
|
|
|
assert (lib.stringLength watchmanSockPath) > 0 -> stdenv.isDarwin;
|
2019-09-10 09:50:09 +00:00
|
|
|
|
2019-06-04 16:50:29 +00:00
|
|
|
let
|
2020-05-06 13:33:54 +00:00
|
|
|
inherit (lib) toLower optionalString stringLength getConfig makeLibraryPath;
|
2020-04-26 12:40:06 +00:00
|
|
|
|
2020-04-23 18:19:12 +00:00
|
|
|
buildType = getConfig "build-type" "prod";
|
|
|
|
buildNumber = getConfig "build-number" 9999;
|
|
|
|
gradleOpts = getConfig "android.gradle-opts" null;
|
|
|
|
keystorePath = getConfig "android.keystore-path" null;
|
|
|
|
|
2019-11-29 10:20:08 +00:00
|
|
|
baseName = "release-android";
|
2019-07-15 16:34:33 +00:00
|
|
|
name = "status-react-build-${baseName}";
|
2020-04-26 12:40:06 +00:00
|
|
|
|
|
|
|
envFileName = if (buildType == "release" || buildType == "nightly" || buildType == "e2e")
|
|
|
|
then ".env.${buildType}"
|
|
|
|
else if buildType != "" then ".env.jenkins"
|
|
|
|
else ".env";
|
|
|
|
|
|
|
|
# There are only two types of Gradle builds: pr and release
|
|
|
|
gradleBuildType = if (buildType == "pr" || buildType == "e2e")
|
|
|
|
then "Pr"
|
|
|
|
else "Release"; # PR builds shouldn't replace normal releases
|
|
|
|
|
2020-05-07 10:21:39 +00:00
|
|
|
apksPath = "./android/app/build/outputs/apk/${toLower gradleBuildType}";
|
2019-09-10 09:50:09 +00:00
|
|
|
patchedWatchman = watchmanFactory watchmanSockPath;
|
2019-06-04 16:50:29 +00:00
|
|
|
|
2020-04-26 12:40:06 +00:00
|
|
|
in stdenv.mkDerivation rec {
|
2019-06-04 16:50:29 +00:00
|
|
|
inherit name;
|
2020-05-07 10:21:39 +00:00
|
|
|
src = let path = ./../../..;
|
2020-04-26 12:40:06 +00:00
|
|
|
# We use builtins.path so that we can name the resulting derivation
|
|
|
|
in builtins.path {
|
|
|
|
inherit path;
|
|
|
|
name = "status-react-source-${baseName}";
|
|
|
|
# Keep this filter as restrictive as possible in order to avoid unnecessary rebuilds and limit closure size
|
|
|
|
filter = lib.mkFilter {
|
|
|
|
root = path;
|
|
|
|
include = [
|
2020-05-07 12:28:24 +00:00
|
|
|
"mobile/js_files.*" "resources/.*" "translations/.*"
|
2020-05-07 10:21:39 +00:00
|
|
|
"modules/react-native-status/android.*" "android/.*"
|
2020-04-26 12:40:06 +00:00
|
|
|
envFileName "VERSION" ".watchmanconfig"
|
|
|
|
"status-go-version.json" "react-native.config.js"
|
|
|
|
];
|
2019-06-04 16:50:29 +00:00
|
|
|
};
|
2020-04-26 12:40:06 +00:00
|
|
|
};
|
|
|
|
|
2020-05-18 10:15:49 +00:00
|
|
|
buildInputs = with pkgs; [ nodejs openjdk ];
|
|
|
|
nativeBuildInputs = with pkgs; [ bash gradle unzip ]
|
2020-04-26 12:40:06 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [ file gnumake patchedWatchman ];
|
|
|
|
|
|
|
|
# Used by Clojure at compile time to include JS modules
|
|
|
|
BUILD_ENV = buildEnv;
|
|
|
|
|
2020-05-06 13:33:54 +00:00
|
|
|
# custom env variables derived from config
|
|
|
|
STATUS_GO_SRC_OVERRIDE = getConfig "nimbus.src-override" null;
|
|
|
|
ANDROID_ABI_SPLIT = getConfig "android.abi-split" "false";
|
|
|
|
ANDROID_ABI_INCLUDE = getConfig "android.abi-include" "armeabi-v7a;arm64-v8a;x86";
|
2020-04-26 12:40:06 +00:00
|
|
|
|
2020-05-07 10:21:39 +00:00
|
|
|
# Android SDK/NDK for use by Gradle
|
2020-05-06 13:33:54 +00:00
|
|
|
ANDROID_SDK_ROOT = "${androidPkgs}";
|
|
|
|
ANDROID_NDK_ROOT = "${androidPkgs}/ndk-bundle";
|
|
|
|
|
|
|
|
# Used by the Android Gradle build script in android/build.gradle
|
|
|
|
STATUS_GO_ANDROID_LIBDIR = "${status-go}";
|
|
|
|
|
|
|
|
phases = [
|
2020-05-07 10:21:39 +00:00
|
|
|
"unpackPhase" "secretPhase" "buildPhase" "checkPhase" "installPhase"
|
2020-05-06 13:33:54 +00:00
|
|
|
];
|
2019-08-06 16:16:51 +00:00
|
|
|
|
2020-05-06 13:33:54 +00:00
|
|
|
unpackPhase = ''
|
2020-05-07 10:21:39 +00:00
|
|
|
cp -ar $src/. ./
|
|
|
|
chmod u+w -R ./
|
2019-08-06 16:16:51 +00:00
|
|
|
runHook postUnpack
|
|
|
|
'';
|
2020-04-23 18:19:12 +00:00
|
|
|
postUnpack = assert lib.assertMsg (keystorePath != null) "keystore-file has to be set!"; ''
|
2020-05-06 13:33:54 +00:00
|
|
|
# Keep the same keystore path for determinism
|
2020-05-07 10:21:39 +00:00
|
|
|
export KEYSTORE_PATH="$PWD/status-im.keystore"
|
2020-05-06 13:33:54 +00:00
|
|
|
cp -a --no-preserve=ownership "${keystorePath}" "$KEYSTORE_PATH"
|
2019-06-04 16:50:29 +00:00
|
|
|
|
|
|
|
# Ensure we have the right .env file
|
2020-05-07 10:21:39 +00:00
|
|
|
cp -f ./${envFileName} ./.env
|
|
|
|
|
|
|
|
# create mobile node/yarn symlinks
|
|
|
|
ln -sf ./mobile/js_files/* ./
|
2019-06-04 16:50:29 +00:00
|
|
|
|
2019-09-07 12:57:22 +00:00
|
|
|
# Copy index.js and app/ input files
|
2020-05-07 10:21:39 +00:00
|
|
|
cp -ra --no-preserve=ownership ${jsbundle}/* ./
|
2019-06-04 16:50:29 +00:00
|
|
|
|
|
|
|
# Copy android/ directory
|
2020-05-07 10:21:39 +00:00
|
|
|
mkdir -p ./android/build
|
|
|
|
chmod -R +w ./android
|
|
|
|
|
|
|
|
# Copy node_modules/ directory. The -L is CRUCIAL!
|
|
|
|
# Otherwise Metro failes to find modules due to symlinks.
|
2020-05-18 10:15:49 +00:00
|
|
|
cp -aL ${deps.nodejs-patched}/node_modules/ ./
|
2020-05-07 10:21:39 +00:00
|
|
|
chmod +w -R ./node_modules
|
|
|
|
|
|
|
|
# Patch build.gradle to use local repo
|
|
|
|
${patchMavenSources} ./android/build.gradle ${deps.gradle}
|
2019-06-04 16:50:29 +00:00
|
|
|
'';
|
2020-05-06 13:33:54 +00:00
|
|
|
secretPhase = optionalString (secretsFile != "") ''
|
|
|
|
source "${secretsFile}"
|
|
|
|
'';
|
2020-04-26 12:40:06 +00:00
|
|
|
buildPhase = let
|
|
|
|
adhocEnvVars = optionalString stdenv.isLinux
|
2020-05-18 10:15:49 +00:00
|
|
|
"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ pkgs.zlib ]}";
|
2020-04-26 12:40:06 +00:00
|
|
|
in
|
2020-05-06 13:33:54 +00:00
|
|
|
assert ANDROID_ABI_SPLIT != null && ANDROID_ABI_SPLIT != "";
|
|
|
|
assert stringLength ANDROID_ABI_INCLUDE > 0;
|
2020-04-26 12:40:06 +00:00
|
|
|
''
|
2020-05-07 10:21:39 +00:00
|
|
|
pushd ./android
|
2020-05-18 10:15:49 +00:00
|
|
|
${adhocEnvVars} ${pkgs.gradle}/bin/gradle \
|
|
|
|
${toString gradleOpts} \
|
2020-05-07 10:21:39 +00:00
|
|
|
--offline --stacktrace \
|
2020-05-07 10:21:39 +00:00
|
|
|
-Dmaven.repo.local='${deps.gradle}' \
|
2020-05-06 13:33:54 +00:00
|
|
|
-PversionCode=${toString buildNumber} \
|
|
|
|
assemble${gradleBuildType} \
|
|
|
|
|| exit 1
|
2019-06-04 16:50:29 +00:00
|
|
|
popd > /dev/null
|
|
|
|
'';
|
2019-08-06 16:16:51 +00:00
|
|
|
doCheck = true;
|
|
|
|
checkPhase = ''
|
2020-05-18 10:15:49 +00:00
|
|
|
ls ${apksPath}/*.apk \
|
|
|
|
| xargs -n1 ${pkgs.unzip}/bin/unzip -qql \
|
|
|
|
| grep 'assets/index.android.bundle'
|
2019-08-06 16:16:51 +00:00
|
|
|
'';
|
2019-06-04 16:50:29 +00:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2019-09-13 17:16:13 +00:00
|
|
|
cp ${apksPath}/*.apk $out/
|
2019-06-04 16:50:29 +00:00
|
|
|
'';
|
|
|
|
}
|