blob: 4ad5ab8a79800c8f01c8ed7e464f3e06dffb892b [file] [log] [blame]
Steven Deec74d3e42016-02-02 16:32:23 +00001#! /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
21set -euo pipefail
22
23while [ ! -f WORKSPACE ]; do
24 cd ..
25 if [ "/" = $(pwd) ]
26 then
27 echo "WORKSPACE not found." 1>&2
28 exit 1
29 fi
30done
31
Adam Michaelbe364ff2016-12-05 15:56:24 +000032function highest_api_level() {
33 ls $ANDROID_HOME/platforms | cut -d '-' -f 2 | sort -n | tail -n 1
34}
Steven Deec74d3e42016-02-02 16:32:23 +000035
36if [ -n "${ANDROID_HOME:-}" ]; then
Adam Michaelbe364ff2016-12-05 15:56:24 +000037 : ${ANDROID_API_LEVEL:=$(highest_api_level)}
Steven Deec74d3e42016-02-02 16:32:23 +000038 cat <<EOF >WORKSPACE.user.bzl
39def android_sdk():
40 native.android_sdk_repository(
41 name = "androidsdk",
42 path = "${ANDROID_HOME}",
Steven Deec74d3e42016-02-02 16:32:23 +000043 # 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")
47EOF
48else
49 cat <<EOF >WORKSPACE.user.bzl
50def android_sdk():
51 native.bind(name = "android_sdk_for_testing", actual = "//:dummy")
52EOF
53fi
54
55if [ -n "${ANDROID_NDK:-}" ]; then
56 cat <<EOF >>WORKSPACE.user.bzl
57def 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")
64EOF
65else
66 cat <<EOF >>WORKSPACE.user.bzl
67def android_ndk():
68 native.bind(name = "android_ndk_for_testing", actual = "//:dummy")
69EOF
70fi
71
72cat <<EOF >>WORKSPACE.user.bzl
73def android_repositories():
74 android_sdk()
75 android_ndk()
76EOF