2020-05-18 10:15:49 +00:00
|
|
|
{ stdenv, pkgs, deps, lib, config, callPackage,
|
|
|
|
watchmanFactory, androidPkgs, patchMavenSources,
|
2020-06-03 19:47:01 +00:00
|
|
|
keystore, jsbundle, status-go }:
|
2019-06-04 16:50:29 +00:00
|
|
|
|
2020-04-26 12:40:06 +00:00
|
|
|
{
|
2020-06-03 19:47:01 +00:00
|
|
|
# Value for BUILD_ENV checked by Clojure code at compile time
|
|
|
|
buildEnv ? "prod",
|
|
|
|
# Path to the file containing secret environment variables
|
|
|
|
secretsFile ? "",
|
|
|
|
# Path to the socket file exposed by an external watchman instance
|
|
|
|
# (workaround needed for building Android on macOS)
|
|
|
|
watchmanSockPath ? "",
|
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-06-03 19:47:01 +00:00
|
|
|
inherit (lib)
|
2020-06-05 09:23:22 +00:00
|
|
|
toLower optionalString stringLength assertMsg
|
2020-07-08 14:08:51 +00:00
|
|
|
getConfig makeLibraryPath assertEnvVarSet elem;
|
2020-04-26 12:40:06 +00:00
|
|
|
|
2020-07-08 14:08:51 +00:00
|
|
|
buildType = getConfig "build-type" "release";
|
2020-04-23 18:19:12 +00:00
|
|
|
buildNumber = getConfig "build-number" 9999;
|
|
|
|
gradleOpts = getConfig "android.gradle-opts" null;
|
2020-07-08 14:08:51 +00:00
|
|
|
# Used to detect end-to-end builds
|
|
|
|
androidAbiInclude = getConfig "android.abi-include" "armeabi-v7a;arm64-v8a;x86";
|
2020-06-03 19:47:01 +00:00
|
|
|
# Keystore can be provided via config and extra-sandbox-paths.
|
|
|
|
# If it is not we use an ad-hoc one generated with default password.
|
|
|
|
keystorePath = getConfig "android.keystore-path" keystore;
|
2020-04-23 18:19:12 +00:00
|
|
|
|
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
|
|
|
|
2020-07-08 14:08:51 +00:00
|
|
|
envFileName =
|
2020-07-15 11:11:07 +00:00
|
|
|
if androidAbiInclude == "x86" then ".env.e2e"
|
|
|
|
else if (elem buildType ["release" "nightly"]) then ".env.${buildType}"
|
|
|
|
else if (elem buildType ["pr" "manual"]) then ".env.jenkins"
|
2020-04-26 12:40:06 +00:00
|
|
|
else ".env";
|
|
|
|
|
2020-07-08 14:08:51 +00:00
|
|
|
# There are only two types of Gradle build targets: pr and release
|
|
|
|
gradleBuildType = if buildType == "pr" then "Pr" else "Release";
|
2020-04-26 12:40:06 +00:00
|
|
|
|
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-07-01 19:45:39 +00:00
|
|
|
"package.json" "yarn.lock" "metro.config.js"
|
|
|
|
"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";
|
2020-07-08 14:08:51 +00:00
|
|
|
ANDROID_ABI_INCLUDE = androidAbiInclude;
|
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-06-03 19:47:01 +00:00
|
|
|
"unpackPhase" "secretsPhase" "secretsCheckPhase"
|
2020-06-05 09:23:22 +00:00
|
|
|
"keystorePhase" "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-06-05 09:23:22 +00:00
|
|
|
postUnpack = ''
|
2019-06-04 16:50:29 +00:00
|
|
|
# Ensure we have the right .env file
|
2020-07-08 14:08:51 +00:00
|
|
|
cp -bf ./${envFileName} ./.env
|
2020-05-07 10:21:39 +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
|
2020-05-19 18:15:41 +00:00
|
|
|
${patchMavenSources} ./android/build.gradle
|
2019-06-04 16:50:29 +00:00
|
|
|
'';
|
2020-06-05 09:23:22 +00:00
|
|
|
|
2020-06-03 19:47:01 +00:00
|
|
|
# if secretsFile is not set we use generate keystore
|
|
|
|
secretsPhase = if (secretsFile != "") then ''
|
2020-05-06 13:33:54 +00:00
|
|
|
source "${secretsFile}"
|
2020-06-03 19:47:01 +00:00
|
|
|
'' else keystore.shellHook;
|
2020-06-05 09:23:22 +00:00
|
|
|
|
|
|
|
# if keystorePath is set copy it into build directory
|
|
|
|
keystorePhase =
|
|
|
|
assert assertMsg (keystorePath != null) "keystorePath has to be set!";
|
|
|
|
''
|
|
|
|
export KEYSTORE_PATH="$PWD/status-im.keystore"
|
|
|
|
cp -a --no-preserve=ownership "${keystorePath}" "$KEYSTORE_PATH"
|
|
|
|
'';
|
2020-06-03 19:47:01 +00:00
|
|
|
secretsCheckPhase = ''
|
|
|
|
${assertEnvVarSet "KEYSTORE_ALIAS"}
|
|
|
|
${assertEnvVarSet "KEYSTORE_PASSWORD"}
|
|
|
|
${assertEnvVarSet "KEYSTORE_KEY_PASSWORD"}
|
2020-05-06 13:33:54 +00:00
|
|
|
'';
|
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
|
|
|
'';
|
|
|
|
}
|