From 23f5d4423cbbe9851ef0eed2f24c06a2305a0cdd Mon Sep 17 00:00:00 2001 From: Hugues Evrard Date: Thu, 11 Jun 2020 10:18:25 +0100 Subject: [PATCH] Check NDK version in Bazel This makes sure we refuse to build with an invalid NDK version. Bug: b/158669059 --- BUILDING.md | 35 +++++++++++++++++++++++++--------- gapidapk/android/apk/rules.bzl | 2 +- kokoro/presubmit/build.sh | 11 ++++++++++- tools/build/rules/android.bzl | 27 ++++++++++++++++++++++++++ tools/build/workspace.bzl | 8 +++++++- 5 files changed, 71 insertions(+), 12 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 95e5c2929..891e8aea4 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -74,17 +74,20 @@ To fetch the required packages, using a console type: ``` cd -tools\bin\sdkmanager.bat "platforms;android-26" "build-tools;29.0.2" ndk-bundle +tools\bin\sdkmanager.bat "platforms;android-26" "build-tools;29.0.2" ``` -Note: this will install the latest NDK in `\ndk-bundle`. The recommended version of the NDK is **r21**. - If you do not have adb installed you can do so with: ``` cd tools\bin\sdkmanager.bat platform-tools ``` +Unzip the +[Android NDK **r21**](https://dl.google.com/android/repository/android-ndk-r21-windows-x86_64.zip) +into a directory of your choosing, and set the `ANDROID_NDK_HOME` environment +variable to point to this directory. + ### Configure the environment Either do this globally or in your shell every time. @@ -132,17 +135,24 @@ To fetch the required packages, using a console type: ``` cd -tools/bin/sdkmanager "platforms;android-26" "build-tools;29.0.2" ndk-bundle +tools/bin/sdkmanager "platforms;android-26" "build-tools;29.0.2" ``` -Note: this will install the latest NDK in `/ndk-bundle`. The recommended version of the NDK is **r21**. - If you do not have adb installed you can do so with: ``` cd tools/bin/sdkmanager platform-tools ``` +Unzip the +[Android NDK **r21**](https://dl.google.com/android/repository/android-ndk-r21-darwin-x86_64.zip) +into a directory of your choosing, and set the `ANDROID_NDK_HOME` environment +variable to point to this directory: + +``` +export ANDROID_NDK_HOME= +``` + ### Install the XCode command line tools After installing, ensure the XCode license is signed with: @@ -199,17 +209,24 @@ To fetch the required packages, using a console type: ``` cd -tools/bin/sdkmanager "platforms;android-26" "build-tools;29.0.2" ndk-bundle +tools/bin/sdkmanager "platforms;android-26" "build-tools;29.0.2" ``` -Note: this will install the latest NDK in `/ndk-bundle`. The recommended version of the NDK is **r21**. - If you do not have adb installed you can do so with: ``` cd tools/bin/sdkmanager platform-tools ``` +Unzip the +[Android NDK **r21**](https://dl.google.com/android/repository/android-ndk-r21-linux-x86_64.zip) +into a directory of your choosing, and set the `ANDROID_NDK_HOME` environment +variable to point to this directory: + +``` +export ANDROID_NDK_HOME= +``` + ### Install other libraries ``` diff --git a/gapidapk/android/apk/rules.bzl b/gapidapk/android/apk/rules.bzl index 81e28920e..c235fb178 100644 --- a/gapidapk/android/apk/rules.bzl +++ b/gapidapk/android/apk/rules.bzl @@ -110,7 +110,7 @@ def gapid_apk(name = "", abi = "", pkg = "", libs = {}, bins = {}): "//conditions:default": [], }), deps = select({ - "//tools/build:android-" + name: ["@ndk_vk_validation_layer//:" + abi], + "//tools/build:android-" + name: ["@ndk_version_check//:ndk_version_check", "@ndk_vk_validation_layer//:" + abi], "//conditions:default": [], }), ) diff --git a/kokoro/presubmit/build.sh b/kokoro/presubmit/build.sh index 16a3bf522..62ffd7e01 100755 --- a/kokoro/presubmit/build.sh +++ b/kokoro/presubmit/build.sh @@ -38,8 +38,17 @@ curl -L -k -s https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - sudo apt-get update sudo apt-get install -y clang-format-6.0 -# Setup environment. +# Mock the correct NDK version. +# Our Bazel scripts check that the correct NDK version is installed: rather +# than downloading the 1+GB NDK just to have a matching version to pass this +# presubmit test, we "mock" the version by overwriting it manually. export ANDROID_NDK_HOME=/opt/android-ndk-r16b +cat > $ANDROID_NDK_HOME/source.properties <