diff --git a/Makefile b/Makefile index 5fe98140b9..bf849b7096 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,10 @@ export NIX_USER_CONF_FILES = $(PWD)/nix/nix.conf # Location of symlinks to derivations that should not be garbage collected export _NIX_GCROOTS = /nix/var/nix/gcroots/per-user/$(USER)/status-mobile # Defines which variables will be kept for Nix pure shell, use semicolon as divider -export _NIX_KEEP ?= TMPDIR,BUILD_ENV,STATUS_GO_SRC_OVERRIDE +export _NIX_KEEP ?= TMPDIR,BUILD_ENV,\ + BUILD_TYPE,BUILD_NUMBER,COMMIT_HASH,\ + ANDROID_GRADLE_OPTS,ANDROID_ABI_SPLIT,ANDROID_ABI_INCLUDE,\ + STATUS_GO_SRC_OVERRIDE,STATUS_GO_IPFS_GATEWAY_URL # Useful for Android release builds TMP_BUILD_NUMBER := $(shell ./scripts/version/gen_build_no.sh | cut -c1-10) diff --git a/android/app/build.gradle b/android/app/build.gradle index ea0a888407..b640e900f6 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -168,6 +168,7 @@ def getVersionCode = { -> def getVersionName = { -> new ByteArrayOutputStream().withStream { stdOut -> + // TODO: probably not used, cleanup if (project.hasProperty("releaseVersion")) { return project.releaseVersion } diff --git a/ci/Jenkinsfile.android b/ci/Jenkinsfile.android index 159f1cc90e..7ce966f980 100644 --- a/ci/Jenkinsfile.android +++ b/ci/Jenkinsfile.android @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' /* Options section can't access functions in objects. */ def isPRBuild = utils.isPRBuild() diff --git a/ci/Jenkinsfile.combined b/ci/Jenkinsfile.combined index 701c41357d..ed4929b68e 100644 --- a/ci/Jenkinsfile.combined +++ b/ci/Jenkinsfile.combined @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' pipeline { agent { label 'linux' } diff --git a/ci/Jenkinsfile.e2e-nightly b/ci/Jenkinsfile.e2e-nightly index 637a1910da..db0707e8d8 100644 --- a/ci/Jenkinsfile.e2e-nightly +++ b/ci/Jenkinsfile.e2e-nightly @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.9' +library 'status-jenkins-lib@v1.7.12' pipeline { agent { label 'linux' } diff --git a/ci/Jenkinsfile.ios b/ci/Jenkinsfile.ios index f54c6ce135..4f3d91a408 100644 --- a/ci/Jenkinsfile.ios +++ b/ci/Jenkinsfile.ios @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' /* Options section can't access functions in objects. */ def isPRBuild = utils.isPRBuild() diff --git a/ci/Jenkinsfile.tests b/ci/Jenkinsfile.tests index dd1c3bb776..7552320352 100644 --- a/ci/Jenkinsfile.tests +++ b/ci/Jenkinsfile.tests @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' /* Options section can't access functions in objects. */ def isPRBuild = utils.isPRBuild() diff --git a/ci/tests/Jenkinsfile.e2e-nightly b/ci/tests/Jenkinsfile.e2e-nightly index 647adf72aa..a2185c9760 100644 --- a/ci/tests/Jenkinsfile.e2e-nightly +++ b/ci/tests/Jenkinsfile.e2e-nightly @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' pipeline { diff --git a/ci/tests/Jenkinsfile.e2e-nightly-build-number b/ci/tests/Jenkinsfile.e2e-nightly-build-number index 58c8559986..42b379347b 100644 --- a/ci/tests/Jenkinsfile.e2e-nightly-build-number +++ b/ci/tests/Jenkinsfile.e2e-nightly-build-number @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.9' +library 'status-jenkins-lib@v1.7.12' pipeline { diff --git a/ci/tests/Jenkinsfile.e2e-prs b/ci/tests/Jenkinsfile.e2e-prs index 05b83313c8..8e3d882335 100644 --- a/ci/tests/Jenkinsfile.e2e-prs +++ b/ci/tests/Jenkinsfile.e2e-prs @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' pipeline { diff --git a/ci/tests/Jenkinsfile.e2e-upgrade b/ci/tests/Jenkinsfile.e2e-upgrade index 2d6a389ce2..90c69194a5 100644 --- a/ci/tests/Jenkinsfile.e2e-upgrade +++ b/ci/tests/Jenkinsfile.e2e-upgrade @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' pipeline { diff --git a/ci/tools/Jenkinsfile.fastlane-clean b/ci/tools/Jenkinsfile.fastlane-clean index 7d956a955a..312e1d5078 100644 --- a/ci/tools/Jenkinsfile.fastlane-clean +++ b/ci/tools/Jenkinsfile.fastlane-clean @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' pipeline { agent { label 'macos' } diff --git a/ci/tools/Jenkinsfile.nix-cache b/ci/tools/Jenkinsfile.nix-cache index d879bdd1f3..25e6b515ff 100644 --- a/ci/tools/Jenkinsfile.nix-cache +++ b/ci/tools/Jenkinsfile.nix-cache @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' pipeline { agent { label params.AGENT_LABEL } diff --git a/ci/tools/Jenkinsfile.playstore-meta b/ci/tools/Jenkinsfile.playstore-meta index 35f3d570a9..e35040b581 100644 --- a/ci/tools/Jenkinsfile.playstore-meta +++ b/ci/tools/Jenkinsfile.playstore-meta @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' pipeline { agent { label 'linux' } diff --git a/ci/tools/Jenkinsfile.xcode-clean b/ci/tools/Jenkinsfile.xcode-clean index 6f0a5f6b09..d4b834c234 100644 --- a/ci/tools/Jenkinsfile.xcode-clean +++ b/ci/tools/Jenkinsfile.xcode-clean @@ -1,5 +1,5 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.7.10' +library 'status-jenkins-lib@v1.7.12' pipeline { agent { diff --git a/nix/DETAILS.md b/nix/DETAILS.md index 52914c023b..d834c7e6bd 100644 --- a/nix/DETAILS.md +++ b/nix/DETAILS.md @@ -23,7 +23,6 @@ There are a few main files that define the whole build environment: * [`nix/shells.nix`](./shells.nix) - Definitions of other Nix shells used in builds * [`nix/targets.nix`](./targets.nix) - Hierarchy of main build targets * [`nix/pkgs.nix`](./pkgs.nix) - Definition of a custom `nixpkgs` repo -* [`nix/config.nix`](./config.nix) - Default config values for instantiating `nixpkgs` * [`nix/overlay.nix`](./overlay.nix) - Overrides for `nixpkgs`, custom packages The [`default.nix`](../default.nix) and [`shell.nix`](../shell.nix) files at th repo root are just a gateway into the `nix` sub folder. @@ -75,13 +74,6 @@ nix-build \ --attr targets.mobile.android.release \ --argstr secrets-file '/tmp/tmp-status-mobile-559a3a441/tmp.xAnrPuNtAP' \ --option extra-sandbox-paths '/home/joe/.gradle/status-im.keystore /tmp/tmp-status-mobile-559a3a441/tmp.xAnrPuNtAP' \ - --arg config '{ \ - status-im.build-type="nightly"; - status-im.build-number="2020022418"; - status-im.android.keystore-path="/home/joe/.gradle/status-im.keystore"; - status-im.android.abi-split="false"; - status-im.android.abi-include="armeabi-v7a;arm64-v8a;x86"; - }' \ default.nix ``` Some of those are required which is why just calling: diff --git a/nix/README.md b/nix/README.md index 7e5e86e737..cbcd376136 100644 --- a/nix/README.md +++ b/nix/README.md @@ -8,27 +8,27 @@ The main config file is [`nix/nix.conf`](/nix/nix.conf) and its main purpose is ## Build arguments -We leverage the `config` argument of standard `nixpkgs` for our own parameterization of the builds (e.g. to pass a build number or build type). +We leverage the environment variables for parameterization of the builds (e.g. to pass a build number or build type). -Here is a sample structure of the `config` attribute set: - -```nix -{ - status-im = { - build-type = "pr"; # Build type (influences which .env file gets used for feature flags) - build-number = 9999; # Used for versionCode and CFBundleVersion in Android and iOS respectively - android = { - gradle-opts = ""; # Gradle options passed for Android builds - abi-split = false; # If APKs should be split based on architectures - abi-include = "x86"; # Android architectures to build for - }; - status-go = { - src-override = "$HOME/my/source/status-go"; # local source override - }; - }; -} +Here is the list of variables you can use to override defaults: +```shell +# Build type (influences which .env file gets used for feature flags) +export BUILD_TYPE="pr" +# Used for versionCode and CFBundleVersion in Android and iOS respectively +export BUILD_NUMBER=9999 +# Gradle options passed for Android builds +export ANDROID_GRADLE_OPTS="" +# If APKs should be split based on architectures +export ANDROID_ABI_SPLIT=false +# Android architectures to build for +export ANDROID_ABI_INCLUDE="x86" +# Local source override, see below +export STATUS_GO_SRC_OVERRIDE="$HOME/my/source/status-go" +export STATUS_GO_IPFS_GATEWAY_URL="https://ipfs.status.im/" ``` -You can see the defaults in [`nix/config.nix`](./config.nix). +You can see the defaults in code: +- [`nix/status-go/default.nix`](./status-go/default.nix) +- [`nix/mobile/android/release.nix`](./mobile/android/release.nix) ## Shell diff --git a/nix/config.nix b/nix/config.nix deleted file mode 100644 index 0790641a22..0000000000 --- a/nix/config.nix +++ /dev/null @@ -1,24 +0,0 @@ -# Status defaults for config -{ - status-im = { - build-type = "pr"; # Build type (influences which .env file gets used for feature flags) - build-number = 9999; # Used for versionCode and CFBundleVersion in Android and iOS respectively - commit-hash = "unknown"; # Included in APK Manifest for easier identification. - - android = { - gradle-opts = null; # Gradle options passed for Android builds - apk-signed = true; # F-Droid builds aren't signed by us - abi-split = false; # If APKs should be split based on architectures - abi-include = "armeabi-v7a;arm64-v8a;x86"; # Android architectures to build for - }; - - status-go = { - src-override = null; - ipfs-gateway-url = "https://ipfs.status.im/"; - }; - }; - - # Android SDK requires an accepted license - android_sdk.accept_license = true; - allowUnfree = true; -} diff --git a/nix/lib/default.nix b/nix/lib/default.nix index a233e716c0..91ec86c680 100644 --- a/nix/lib/default.nix +++ b/nix/lib/default.nix @@ -1,8 +1,9 @@ -{ lib, config }: +{ lib }: { - getConfig = import ./getConfig.nix { inherit lib config; }; + getEnvWithDefault = import ./getEnvWithDefault.nix; mkFilter = import ./mkFilter.nix { inherit lib; }; mergeSh = import ./mergeSh.nix { inherit lib; }; checkEnvVarSet = import ./checkEnvVarSet.nix; + sanitizeVersion = import ./sanitizeVersion.nix { inherit lib; }; } diff --git a/nix/lib/getConfig.nix b/nix/lib/getConfig.nix deleted file mode 100644 index 5b11685a4c..0000000000 --- a/nix/lib/getConfig.nix +++ /dev/null @@ -1,11 +0,0 @@ -# helper for getting status-im config values in a safe way -# - -{ lib, config }: - -let inherit (lib) splitString attrByPath; -in name: default: -let - path = [ "status-im" ] ++ (splitString "." name); - value = attrByPath path default config; -in if value != null then value else default diff --git a/nix/lib/getEnvWithDefault.nix b/nix/lib/getEnvWithDefault.nix new file mode 100644 index 0000000000..354b0e4e37 --- /dev/null +++ b/nix/lib/getEnvWithDefault.nix @@ -0,0 +1,8 @@ +name: default: let + envOverride = builtins.getEnv name; + logEnvOverride = value: + builtins.trace "getEnvWithDefault ${name} (default: ${toString default}): ${value}" value; +in + if envOverride != "" + then logEnvOverride envOverride + else default diff --git a/nix/lib/sanitizeVersion.nix b/nix/lib/sanitizeVersion.nix new file mode 100644 index 0000000000..ab6435e2c2 --- /dev/null +++ b/nix/lib/sanitizeVersion.nix @@ -0,0 +1,14 @@ +{ lib }: + +version: +let + # paths don't like slashes in them + dropSlashes = builtins.replaceStrings [ "/" ] [ "_" ]; + # if version doesn't match this it's probably a commit, it's lax semver + versionRegex = "^v?[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+[[:alnum:]+_.-]*$"; +in + if (builtins.match versionRegex version) != null + # Geth forces a 'v' prefix for all versions + then lib.removePrefix "v" (dropSlashes version) + # reduce metrics cardinality in Prometheus + else lib.traceValFn (_: "WARNING: Marking build version as 'develop'!") "develop" diff --git a/nix/mobile/android/release.nix b/nix/mobile/android/release.nix index 0be180d683..53541c5e15 100644 --- a/nix/mobile/android/release.nix +++ b/nix/mobile/android/release.nix @@ -6,20 +6,30 @@ buildEnv ? "prod", # Path to the file containing secret environment variables secretsFile ? "", + # Build type (influences which .env file gets used for feature flags) + # TODO: pr or relase for default? + buildType ? lib.getEnvWithDefault "BUILD_TYPE" "release", + # Used for versionCode + buildNumber ? lib.getEnvWithDefault "BUILD_NUMBER" 9999, + # Included in APK Manifest for easier identification. + # TODO: or GIT_COMMIT from Jenkins? + commitHash ? lib.getEnvWithDefault "COMMIT_HASH" "unknown", + # Gradle options passed for Android builds + androidGradleOpts ? lib.getEnvWithDefault "ANDROID_GRADLE_OPTS" null, + statusGoSrcOverride ? lib.getEnvWithDefault "STATUS_GO_SRC_OVERRIDE" null, + # If APKs should be split based on architectures + androidAbiSplit ? lib.getEnvWithDefault "ANDROID_ABI_SPLIT" "false", + # Android architectures to build for + # Used to detect end-to-end builds + androidAbiInclude ? lib.getEnvWithDefault "ANDROID_ABI_INCLUDE" "armeabi-v7a;arm64-v8a;x86", }: let - inherit (lib) toLower optionalString stringLength getConfig makeLibraryPath elem; + inherit (lib) toLower optionalString stringLength makeLibraryPath elem; # Pass secretsFile for POKT_TOKEN to jsbundle build builtJsBundle = jsbundle { inherit secretsFile; }; - buildType = getConfig "build-type" "release"; - buildNumber = getConfig "build-number" 9999; - commitHash = getConfig "commit-hash" "unknown"; - gradleOpts = getConfig "android.gradle-opts" null; - # Used to detect end-to-end builds - androidAbiInclude = getConfig "android.abi-include" "armeabi-v7a;arm64-v8a;x86"; envFileName = if androidAbiInclude == "x86" then ".env.e2e" @@ -63,9 +73,8 @@ in stdenv.mkDerivation rec { # Used by Clojure at compile time to include JS modules BUILD_ENV = buildEnv; - # custom env variables derived from config - STATUS_GO_SRC_OVERRIDE = getConfig "status-go.src-override" null; - ANDROID_ABI_SPLIT = getConfig "android.abi-split" "false"; + STATUS_GO_SRC_OVERRIDE = statusGoSrcOverride; + ANDROID_ABI_SPLIT = androidAbiSplit; ANDROID_ABI_INCLUDE = androidAbiInclude; # Android SDK/NDK for use by Gradle @@ -122,17 +131,9 @@ in stdenv.mkDerivation rec { buildPhase = let adhocEnvVars = optionalString stdenv.isLinux "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ pkgs.zlib ]}"; - in - assert ANDROID_ABI_SPLIT != null && ANDROID_ABI_SPLIT != ""; - assert stringLength ANDROID_ABI_INCLUDE > 0; - '' - # Fixes issue with failing to load libnative-platform.so - export GRADLE_USER_HOME=$(mktemp -d) - export ANDROID_SDK_HOME=$(mktemp -d) - - pushd ./android - ${adhocEnvVars} ${pkgs.gradle}/bin/gradle \ - ${toString gradleOpts} \ + gradleCommand = '' + ${pkgs.gradle}/bin/gradle \ + ${toString androidGradleOpts} \ --console=plain \ --offline \ --no-daemon \ @@ -142,8 +143,21 @@ in stdenv.mkDerivation rec { -Dmaven.repo.local='${deps.gradle}' \ -PversionCode=${toString buildNumber} \ -PcommitHash=${commitHash} \ - assemble${gradleBuildType} \ - || exit 1 + assemble${gradleBuildType} + ''; + in + assert ANDROID_ABI_SPLIT != null && ANDROID_ABI_SPLIT != ""; + assert stringLength ANDROID_ABI_INCLUDE > 0; + '' + # Fixes issue with failing to load libnative-platform.so + export GRADLE_USER_HOME=$(mktemp -d) + export ANDROID_SDK_HOME=$(mktemp -d) + + echo "Adhoc ENV: ${adhocEnvVars}" + echo "Running: ${gradleCommand}" + + pushd ./android + ${adhocEnvVars} ${gradleCommand} popd > /dev/null ''; doCheck = true; diff --git a/nix/overlay.nix b/nix/overlay.nix index f175a9ad46..97ae908810 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -13,11 +13,8 @@ in { # Fix for MacOS mkShell = super.mkShell.override { stdenv = stdenvNoCC; }; - # Various utilities - utils = callPackage ./tools/utils.nix { }; lib = (super.lib or { }) // (import ./lib { inherit (super) lib; - inherit (self) config; }); # Project dependencies @@ -29,9 +26,6 @@ in { react-native = callPackage ./deps/react-native { }; }; - # For parsing gradle.properties into an attrset - gradlePropParser = callPackage ./tools/gradlePropParser.nix { }; - # Fix for missing libarclite_macosx.a in Xcode 14.3. # https://github.com/ios-control/ios-deploy/issues/580 ios-deploy = super.darwin.ios-deploy.overrideAttrs (old: rec { diff --git a/nix/pkgs.nix b/nix/pkgs.nix index 9b178f42cb..321321d934 100644 --- a/nix/pkgs.nix +++ b/nix/pkgs.nix @@ -13,7 +13,10 @@ let }; # Status specific configuration defaults - defaultConfig = import ./config.nix; + defaultConfig = { + android_sdk.accept_license = true; + allowUnfree = true; + }; # Override some packages and utilities pkgsOverlay = import ./overlay.nix; diff --git a/nix/scripts/shell.sh b/nix/scripts/shell.sh index 0a64e1d182..32e3384ca2 100755 --- a/nix/scripts/shell.sh +++ b/nix/scripts/shell.sh @@ -41,16 +41,6 @@ nixArgs=( "--attr shells.${TARGET}" ) -config='' -if [[ -n "${STATUS_GO_SRC_OVERRIDE}" ]]; then - config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";" -fi -config+="status-im.build-type=\"${BUILD_TYPE}\";" - -if [[ -n "$config" ]]; then - nixArgs+=("--arg config {$config}") -fi - # This variable allows specifying which env vars to keep for Nix pure shell # The separator is a colon if [[ -n "${_NIX_KEEP}" ]]; then diff --git a/nix/status-go/default.nix b/nix/status-go/default.nix index 4de9a64786..d4c2f864db 100644 --- a/nix/status-go/default.nix +++ b/nix/status-go/default.nix @@ -1,7 +1,7 @@ { lib, callPackage, mkShell }: let - inherit (lib) getConfig attrValues mapAttrs; + inherit (lib) getEnvWithDefault attrValues mapAttrs; # Metadata common to all builds of status-go meta = { @@ -18,7 +18,7 @@ let GitCommit = source.rev; Version = source.cleanVersion; # FIXME: This should be moved to status-go config. - IpfsGatewayURL = getConfig "status-go.ipfs-gateway-url" "https://ipfs.status.im/"; + IpfsGatewayURL = getEnvWithDefault "STATUS_GO_IPFS_GATEWAY_URL" "https://ipfs.status.im/"; }; # These are necessary for status-go to show correct version diff --git a/nix/status-go/mobile/build.nix b/nix/status-go/mobile/build.nix index d760f4a35f..befd130a29 100644 --- a/nix/status-go/mobile/build.nix +++ b/nix/status-go/mobile/build.nix @@ -1,4 +1,4 @@ -{ lib, utils, buildGoPackage +{ callPackage, lib, buildGoPackage , androidPkgs, openjdk, gomobile, xcodeWrapper, removeReferencesTo , meta , source @@ -13,6 +13,7 @@ let inherit (lib) concatStringsSep optionalString optional; isIOS = platform == "ios"; isAndroid = platform == "android"; + enforceXCodeAvailable = callPackage ./enforceXCodeAvailable.nix { }; in buildGoPackage { pname = source.repo; @@ -35,7 +36,7 @@ in buildGoPackage { ANDROID_HOME = optionalString isAndroid androidPkgs.sdk; # Ensure XCode is present for iOS, instead of failing at the end of the build. - preConfigure = optionalString isIOS utils.enforceXCodeAvailable; + preConfigure = optionalString isIOS enforceXCodeAvailable; buildPhase = '' runHook preBuild diff --git a/nix/status-go/mobile/enforceXCodeAvailable.nix b/nix/status-go/mobile/enforceXCodeAvailable.nix new file mode 100644 index 0000000000..df7ce05b83 --- /dev/null +++ b/nix/status-go/mobile/enforceXCodeAvailable.nix @@ -0,0 +1,30 @@ +{ xcodeWrapper }: + +let + RED = "\\033[0;31m"; + GREEN = "\\033[0;32m"; + NC = "\\033[0m"; + + _xcodeToolsTest = '' + xcode=0 + iPhoneSDK=0 + export PATH=${xcodeWrapper}/bin:$PATH + xcrun xcodebuild -version && xcode=1 + [ $xcode -eq 1 ] && xcrun --sdk iphoneos --show-sdk-version > /dev/null && iPhoneSDK=1 + ''; + _xcodeToolReportScript = tool-name: ''[ $SELECTED -eq 0 ] && echo -e "${NC}- ${RED}[ ] ${tool-name}" || echo -e "${NC}- ${GREEN}[√] ${tool-name}${RED}"''; + _xcodeToolsReportScript = '' + echo -e "${RED}There are some required tools missing in the system:" + export SELECTED=$xcode; ${_xcodeToolReportScript "Xcode ${_xcodeVersion}"} + export SELECTED=$iPhoneSDK; ${_xcodeToolReportScript "iPhone SDK"} + ''; + _xcodeVersion = builtins.replaceStrings ["xcode-wrapper-"] [""] xcodeWrapper.name; +in + '' + ${_xcodeToolsTest} + if [ $xcode -eq 0 ]; then + ${_xcodeToolsReportScript} + echo -e "Please install Xcode ${_xcodeVersion} from the App Store.${NC}" + exit 1 + fi + '' diff --git a/nix/status-go/source.nix b/nix/status-go/source.nix index 7a5e03a0e9..2bcf68ee90 100644 --- a/nix/status-go/source.nix +++ b/nix/status-go/source.nix @@ -1,9 +1,10 @@ -{ utils, lib, fetchFromGitHub }: +{ lib, fetchFromGitHub }: let - inherit (lib) strings traceValFn importJSON getConfig; + inherit (lib) strings traceValFn importJSON getEnvWithDefault; - srcOverride = getConfig "status-go.src-override" null; + # TODO: move to default? + srcOverride = getEnvWithDefault "STATUS_GO_SRC_OVERRIDE" null; # Warning message about using local sources localSrcWarn = (path: "Using local status-go sources from ${path}"); @@ -43,7 +44,7 @@ let rev = versionJSON.commit-sha1; shortRev = strings.substring 0 7 rev; rawVersion = versionJSON.version; - cleanVersion = utils.sanitizeVersion versionJSON.version; + cleanVersion = lib.sanitizeVersion versionJSON.version; # Need to pretend this is from status-im to let Go build it. goPackagePath = "github.com/status-im/${repo}"; src = fetchFromGitHub { diff --git a/nix/tools/envParser.nix b/nix/tools/envParser.nix deleted file mode 100644 index 1dcc8c7659..0000000000 --- a/nix/tools/envParser.nix +++ /dev/null @@ -1,35 +0,0 @@ -# This Nix expression takes care of reading/parsing the correct .env configuration file and return it as an attr set -{ config, lib }: - -let - inherit (builtins) listToAttrs head tail readFile; - inherit (lib) attrByPath filter hasPrefix nameValuePair splitString; - - build-type = attrByPath ["status-im" "build-type"] "" config; - - readLinesFromFile = - file: - let - lines = splitString "\n" (readFile file); - removeComments = filter (line: line != "" && !(hasPrefix "#" line)); - meaningfulLines = removeComments lines; - in - meaningfulLines; - readFlagsFromFile = - file: - let - lines = readLinesFromFile file; - genAttrs = lines: - listToAttrs (map (line: - let flag = splitString "=" line; - in nameValuePair (head flag) (head (tail flag))) lines); - in - genAttrs lines; - envFileName = - if build-type == "release" then ../../.env.release else - if build-type == "nightly" then ../../.env.nightly else - if build-type == "e2e" then ../../.env.e2e else - if build-type == "pr" then ../../.env.jenkins else ../../.env; - flags = readFlagsFromFile envFileName; # TODO: Simplify this path search with lib.locateDominatingFile - -in flags diff --git a/nix/tools/gradlePropParser.nix b/nix/tools/gradlePropParser.nix deleted file mode 100644 index 891177e46f..0000000000 --- a/nix/tools/gradlePropParser.nix +++ /dev/null @@ -1,20 +0,0 @@ -# Parser for android/gradle.properties file. -# Returns an attrset with keys and values from it. -{ lib }: - -gradlePropsFile: - -let - inherit (lib) head last filter listToAttrs splitString nameValuePair hasPrefix readFile; - - # Read lines - lines = splitString "\n" (readFile gradlePropsFile); - - isKeyValueLine = line: line != "" && !hasPrefix "#" line; - cleanup = filter isKeyValueLine; - extractKeyValues = line: - let flag = splitString "=" line; - in nameValuePair (head flag) (last flag); - parseAttrs = lines: listToAttrs (map extractKeyValues lines); -in - parseAttrs (cleanup lines) diff --git a/nix/tools/utils.nix b/nix/tools/utils.nix deleted file mode 100644 index 53965cf2d6..0000000000 --- a/nix/tools/utils.nix +++ /dev/null @@ -1,64 +0,0 @@ -{ xcodeWrapper, lib }: - -# -# This is a collection of various utilities used throught this repo. -# - -let - RED = "\\033[0;31m"; - GREEN = "\\033[0;32m"; - NC = "\\033[0m"; - - _xcodeToolsTest = '' - xcode=0 - iPhoneSDK=0 - export PATH=${xcodeWrapper}/bin:$PATH - xcrun xcodebuild -version && xcode=1 - [ $xcode -eq 1 ] && xcrun --sdk iphoneos --show-sdk-version > /dev/null && iPhoneSDK=1 - ''; - _xcodeToolReportScript = tool-name: ''[ $SELECTED -eq 0 ] && echo -e "${NC}- ${RED}[ ] ${tool-name}" || echo -e "${NC}- ${GREEN}[√] ${tool-name}${RED}"''; - _xcodeToolsReportScript = '' - echo -e "${RED}There are some required tools missing in the system:" - export SELECTED=$xcode; ${_xcodeToolReportScript "Xcode ${_xcodeVersion}"} - export SELECTED=$iPhoneSDK; ${_xcodeToolReportScript "iPhone SDK"} - ''; - _xcodeVersion = builtins.replaceStrings ["xcode-wrapper-"] [""] xcodeWrapper.name; - - enforceXCodeAvailable = '' - ${_xcodeToolsTest} - if [ $xcode -eq 0 ]; then - ${_xcodeToolsReportScript} - echo -e "Please install Xcode ${_xcodeVersion} from the App Store.${NC}" - exit 1 - fi - ''; - - enforceiPhoneSDKAvailable = '' - ${_xcodeToolsTest} - if [ $iPhoneSDK -eq 0 ]; then - ${_xcodeToolsReportScript} - if [ $xcode -eq 1 ]; then - echo -e "Please install the iPhone SDK in Xcode.${NC}"" - else - echo -e "Please install Xcode ${_xcodeVersion} from the App Store, and then the iPhone SDK.${NC}"" - fi - exit 1 - fi - ''; - - # paths don't like slashes in them - dropSlashes = builtins.replaceStrings [ "/" ] [ "_" ]; - # if version doesn't match this it's probably a commit, it's lax semver - versionRegex = "^v?[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+[[:alnum:]+_.-]*$"; - sanitizeVersion = version: - if (builtins.match versionRegex version) != null - # Geth forces a 'v' prefix for all versions - then lib.removePrefix "v" (dropSlashes version) - # reduce metrics cardinality in Prometheus - else lib.traceValFn (_: "WARNING: Marking build version as 'develop'!") "develop"; - -in { - inherit sanitizeVersion - enforceXCodeAvailable - enforceiPhoneSDKAvailable; -} diff --git a/scripts/build-android.sh b/scripts/build-android.sh index fdbe7edc1a..cf5b5ae297 100755 --- a/scripts/build-android.sh +++ b/scripts/build-android.sh @@ -22,15 +22,7 @@ function append_env_export() { echo "export ${VAR_NAME}=\"${VAR_VALUE}\";" >> "${SECRETS_FILE_PATH}" } -config='' -if [[ -n "${STATUS_GO_SRC_OVERRIDE}" ]]; then - config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";" -fi -config+="status-im.commit-hash=\"$(git rev-parse --verify HEAD)\";" -config+="status-im.build-type=\"$(must_get_env BUILD_TYPE)\";" -config+="status-im.build-number=\"$(must_get_env BUILD_NUMBER)\";" -config+="status-im.android.abi-split=\"$(must_get_env ANDROID_ABI_SPLIT)\";" -config+="status-im.android.abi-include=\"$(must_get_env ANDROID_ABI_INCLUDE)\";" +export COMMIT_HASH="$(git rev-parse --verify HEAD)" nixOpts=() # We create if now so the trap knows its location @@ -73,6 +65,5 @@ else nixOpts+=("--option" "build-use-sandbox" "true") fi -nixOpts+=("--arg" "config" "{${config}}") "${GIT_ROOT}/nix/scripts/build.sh" targets.mobile.android.release "${nixOpts[@]}"