2022-08-09 18:49:59 +00:00
|
|
|
{ stdenv, pkgs, deps, lib
|
2022-05-26 09:11:34 +00:00
|
|
|
, androidPkgs, patchMavenSources, 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 ? "",
|
2019-06-04 16:50:29 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2022-05-26 09:11:34 +00:00
|
|
|
inherit (lib) toLower optionalString stringLength getConfig makeLibraryPath elem;
|
2020-04-26 12:40:06 +00:00
|
|
|
|
2022-10-19 14:59:55 +00:00
|
|
|
# Pass secretsFile for POKT_TOKEN to jsbundle build
|
2020-10-05 12:53:20 +00:00
|
|
|
builtJsBundle = jsbundle { inherit secretsFile; };
|
|
|
|
|
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;
|
2021-09-17 16:04:39 +00:00
|
|
|
commitHash = getConfig "commit-hash" "unknown";
|
2020-04-23 18:19:12 +00:00
|
|
|
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-04-23 18:19:12 +00:00
|
|
|
|
2022-08-09 18:49:59 +00:00
|
|
|
envFileName =
|
|
|
|
if androidAbiInclude == "x86" then ".env.e2e"
|
2020-07-15 11:11:07 +00:00
|
|
|
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-06-04 16:50:29 +00:00
|
|
|
|
2022-05-26 09:11:34 +00:00
|
|
|
baseName = "${buildType}-android";
|
2020-04-26 12:40:06 +00:00
|
|
|
in stdenv.mkDerivation rec {
|
2022-07-17 12:37:46 +00:00
|
|
|
name = "status-mobile-build-${baseName}";
|
2022-05-26 09:11:34 +00:00
|
|
|
|
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;
|
2022-07-17 12:37:46 +00:00
|
|
|
name = "status-mobile-source-${baseName}";
|
2020-04-26 12:40:06 +00:00
|
|
|
# Keep this filter as restrictive as possible in order to avoid unnecessary rebuilds and limit closure size
|
|
|
|
filter = lib.mkFilter {
|
|
|
|
root = path;
|
|
|
|
include = [
|
2022-11-24 21:05:58 +00:00
|
|
|
"package.json" "yarn.lock" "metro.config.js" "babel.config.js"
|
2023-05-16 16:42:56 +00:00
|
|
|
"resources/.*" "translations/.*" "src/js/.*" "index.js"
|
2020-05-07 10:21:39 +00:00
|
|
|
"modules/react-native-status/android.*" "android/.*"
|
2022-08-09 18:49:59 +00:00
|
|
|
envFileName "VERSION" "status-go-version.json" "react-native.config.js"
|
2020-04-26 12:40:06 +00:00
|
|
|
];
|
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 ]
|
2022-08-09 18:49:59 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [ file gnumake ];
|
|
|
|
|
|
|
|
# Disable metro watching for file changes. (#13783)
|
|
|
|
CI = true;
|
2020-04-26 12:40:06 +00:00
|
|
|
|
|
|
|
# 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
|
2021-11-15 11:11:11 +00:00
|
|
|
STATUS_GO_SRC_OVERRIDE = getConfig "status-go.src-override" null;
|
2020-05-06 13:33:54 +00:00
|
|
|
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
|
2021-07-22 10:51:05 +00:00
|
|
|
ANDROID_SDK_ROOT = "${androidPkgs.sdk}";
|
|
|
|
ANDROID_NDK_ROOT = "${androidPkgs.ndk}";
|
2020-05-06 13:33:54 +00:00
|
|
|
|
2022-08-31 23:30:35 +00:00
|
|
|
# Fix for ERR_OSSL_EVP_UNSUPPORTED error.
|
|
|
|
NODE_OPTIONS = "--openssl-legacy-provider";
|
|
|
|
|
2020-05-06 13:33:54 +00:00
|
|
|
# Used by the Android Gradle build script in android/build.gradle
|
2022-08-04 08:20:44 +00:00
|
|
|
STATUS_GO_ANDROID_LIBDIR = status-go;
|
2020-05-06 13:33:54 +00:00
|
|
|
|
|
|
|
phases = [
|
2022-04-22 08:20:01 +00:00
|
|
|
"unpackPhase" "secretsPhase" "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
|
|
|
|
2022-08-09 18:49:59 +00:00
|
|
|
# Export all vars from .env file
|
|
|
|
export $(cut -d= -f1 .env)
|
2020-11-02 08:43:54 +00:00
|
|
|
|
2023-05-16 16:42:56 +00:00
|
|
|
# Symlink React Native entrypoint.
|
|
|
|
cp -Lr ${builtJsBundle} ./result
|
|
|
|
pwd
|
|
|
|
find -L result
|
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
|
|
|
|
2022-04-22 08:20:01 +00:00
|
|
|
# Secrets file is passed to sandbox using extra-sandbox-paths.
|
2020-06-03 19:47:01 +00:00
|
|
|
secretsPhase = if (secretsFile != "") then ''
|
2020-05-06 13:33:54 +00:00
|
|
|
source "${secretsFile}"
|
2022-04-22 08:20:01 +00:00
|
|
|
'' else ''
|
|
|
|
echo 'WARNING: No secrets provided!' >&2
|
2020-06-05 09:23:22 +00:00
|
|
|
'';
|
2022-04-22 08:20:01 +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 ]}";
|
2022-08-09 18:49:59 +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-07-16 11:01:56 +00:00
|
|
|
# Fixes issue with failing to load libnative-platform.so
|
|
|
|
export GRADLE_USER_HOME=$(mktemp -d)
|
2021-01-19 12:42:59 +00:00
|
|
|
export ANDROID_SDK_HOME=$(mktemp -d)
|
2020-07-16 11:01:56 +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-08-06 12:23:18 +00:00
|
|
|
--console=plain \
|
2023-06-14 01:47:41 +00:00
|
|
|
--offline \
|
|
|
|
--no-daemon \
|
|
|
|
--no-scan \
|
|
|
|
--no-watch-fs \
|
|
|
|
--no-build-cache \
|
2020-05-07 10:21:39 +00:00
|
|
|
-Dmaven.repo.local='${deps.gradle}' \
|
2020-05-06 13:33:54 +00:00
|
|
|
-PversionCode=${toString buildNumber} \
|
2021-09-17 16:04:39 +00:00
|
|
|
-PcommitHash=${commitHash} \
|
2020-05-06 13:33:54 +00:00
|
|
|
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 \
|
2023-06-14 01:47:41 +00:00
|
|
|
| grep '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
|
|
|
'';
|
|
|
|
}
|