Steven Dee | c74d3e4 | 2016-02-02 16:32:23 +0000 | [diff] [blame] | 1 | #! /usr/bin/env bash |
| 2 | # |
| 3 | # Copyright 2016 The Bazel Authors. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # This script locates the android sdk (via ANDROID_HOME) and ndk |
| 18 | # (via ANDROID_NDK) on your system, and writes a WORKSPACE.user.bzl |
| 19 | # that points to them. |
| 20 | |
| 21 | set -euo pipefail |
| 22 | |
| 23 | while [ ! -f WORKSPACE ]; do |
| 24 | cd .. |
| 25 | if [ "/" = $(pwd) ] |
| 26 | then |
| 27 | echo "WORKSPACE not found." 1>&2 |
| 28 | exit 1 |
| 29 | fi |
| 30 | done |
| 31 | |
Adam Michael | be364ff | 2016-12-05 15:56:24 +0000 | [diff] [blame] | 32 | function highest_api_level() { |
| 33 | ls $ANDROID_HOME/platforms | cut -d '-' -f 2 | sort -n | tail -n 1 |
| 34 | } |
Steven Dee | c74d3e4 | 2016-02-02 16:32:23 +0000 | [diff] [blame] | 35 | |
| 36 | if [ -n "${ANDROID_HOME:-}" ]; then |
Adam Michael | be364ff | 2016-12-05 15:56:24 +0000 | [diff] [blame] | 37 | : ${ANDROID_API_LEVEL:=$(highest_api_level)} |
Steven Dee | c74d3e4 | 2016-02-02 16:32:23 +0000 | [diff] [blame] | 38 | cat <<EOF >WORKSPACE.user.bzl |
| 39 | def android_sdk(): |
| 40 | native.android_sdk_repository( |
| 41 | name = "androidsdk", |
| 42 | path = "${ANDROID_HOME}", |
Steven Dee | c74d3e4 | 2016-02-02 16:32:23 +0000 | [diff] [blame] | 43 | # Available versions are under /path/to/sdk/platforms/. |
| 44 | api_level = ${ANDROID_API_LEVEL}, |
| 45 | ) |
| 46 | native.bind(name = "android_sdk_for_testing", actual = "@androidsdk//:files") |
| 47 | EOF |
| 48 | else |
| 49 | cat <<EOF >WORKSPACE.user.bzl |
| 50 | def android_sdk(): |
| 51 | native.bind(name = "android_sdk_for_testing", actual = "//:dummy") |
| 52 | EOF |
| 53 | fi |
| 54 | |
| 55 | if [ -n "${ANDROID_NDK:-}" ]; then |
| 56 | cat <<EOF >>WORKSPACE.user.bzl |
| 57 | def android_ndk(): |
| 58 | native.android_ndk_repository( |
| 59 | name = "androidndk", |
| 60 | path = "${ANDROID_NDK}", |
| 61 | api_level = ${ANDROID_API_LEVEL}, |
| 62 | ) |
| 63 | native.bind(name = "android_ndk_for_testing", actual = "@androidndk//:files") |
| 64 | EOF |
| 65 | else |
| 66 | cat <<EOF >>WORKSPACE.user.bzl |
| 67 | def android_ndk(): |
| 68 | native.bind(name = "android_ndk_for_testing", actual = "//:dummy") |
| 69 | EOF |
| 70 | fi |
| 71 | |
| 72 | cat <<EOF >>WORKSPACE.user.bzl |
| 73 | def android_repositories(): |
| 74 | android_sdk() |
| 75 | android_ndk() |
| 76 | EOF |