aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Steven Dee <steven@choosemuse.com>2016-02-02 16:32:23 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-02-02 18:13:56 +0000
commitc74d3e4d9f2340c4a53f818f052df72a824660c0 (patch)
tree1e9598dfc631fb0e0cde76423f8243de2e4889e1
parent852e9e5cc9ca4ad10a8097ba2dc74cc4446dade8 (diff)
Get android path from env (fixes #746)
-- Change-Id: Ideb2011d23da470276420afcc8b5a71f1470f391 Reviewed-on: https://bazel-review.googlesource.com/#/c/2771 MOS_MIGRATED_REVID=113639747
-rw-r--r--.gitignore1
-rw-r--r--WORKSPACE35
-rwxr-xr-xscripts/workspace_user.sh76
3 files changed, 81 insertions, 31 deletions
diff --git a/.gitignore b/.gitignore
index fa433ac8a0..95270e99a9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
/.idea/
/.project
/.settings
+/WORKSPACE.user.bzl
/base_workspace/*
/bazel-bazel
/bazel-bin
diff --git a/WORKSPACE b/WORKSPACE
index 1cb41a8e00..76cbc6fcbd 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -12,37 +12,10 @@ jsonnet_repositories()
rust_repositories()
sass_repositories()
-# In order to run the Android integration tests, uncomment these rules, point
-# them to the Android NDK and the SDK, and point the bind rules under them
-# to @repository//:files .
-# android_sdk_repository(
-# name = "androidsdk",
-# path = "/path/to/sdk",
-# # Available versions are under /path/to/sdk/build-tools/.
-# build_tools_version = "21.1.1",
-# # Available versions are under /path/to/sdk/platforms/.
-# api_level = 19,
-# )
-
-# android_ndk_repository(
-# name = "androidndk",
-# path = "/path/to/ndk",
-# api_level = 19, # Set this to the SDK's api_level.
-# )
-
-bind(
- name = "android_sdk_for_testing",
- # Uncomment and delete the //:dummy line to run integration tests.
- # actual = "@androidsdk//:files",
- actual = "//:dummy",
-)
-
-bind(
- name = "android_ndk_for_testing",
- # Uncomment and delete the //:dummy line to run integration tests.
- # actual = "@androidndk//:files",
- actual = "//:dummy",
-)
+# In order to run the Android integration tests, run
+# scripts/workspace_user.sh and uncomment the next two lines.
+# load("/WORKSPACE.user", "android_repositories")
+# android_repositories()
# only used for the scala rule
new_http_archive(
diff --git a/scripts/workspace_user.sh b/scripts/workspace_user.sh
new file mode 100755
index 0000000000..dbcfeca366
--- /dev/null
+++ b/scripts/workspace_user.sh
@@ -0,0 +1,76 @@
+#! /usr/bin/env bash
+#
+# Copyright 2016 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This script locates the android sdk (via ANDROID_HOME) and ndk
+# (via ANDROID_NDK) on your system, and writes a WORKSPACE.user.bzl
+# that points to them.
+
+set -euo pipefail
+
+while [ ! -f WORKSPACE ]; do
+ cd ..
+ if [ "/" = $(pwd) ]
+ then
+ echo "WORKSPACE not found." 1>&2
+ exit 1
+ fi
+done
+
+: ${ANDROID_BUILD_TOOLS_VERSION:="21.1.1"}
+: ${ANDROID_API_LEVEL:="19"}
+
+if [ -n "${ANDROID_HOME:-}" ]; then
+ cat <<EOF >WORKSPACE.user.bzl
+def android_sdk():
+ native.android_sdk_repository(
+ name = "androidsdk",
+ path = "${ANDROID_HOME}",
+ # Available versions are under /path/to/sdk/build-tools/.
+ build_tools_version = "${ANDROID_BUILD_TOOLS_VERSION}",
+ # Available versions are under /path/to/sdk/platforms/.
+ api_level = ${ANDROID_API_LEVEL},
+ )
+ native.bind(name = "android_sdk_for_testing", actual = "@androidsdk//:files")
+EOF
+else
+ cat <<EOF >WORKSPACE.user.bzl
+def android_sdk():
+ native.bind(name = "android_sdk_for_testing", actual = "//:dummy")
+EOF
+fi
+
+if [ -n "${ANDROID_NDK:-}" ]; then
+ cat <<EOF >>WORKSPACE.user.bzl
+def android_ndk():
+ native.android_ndk_repository(
+ name = "androidndk",
+ path = "${ANDROID_NDK}",
+ api_level = ${ANDROID_API_LEVEL},
+ )
+ native.bind(name = "android_ndk_for_testing", actual = "@androidndk//:files")
+EOF
+else
+ cat <<EOF >>WORKSPACE.user.bzl
+def android_ndk():
+ native.bind(name = "android_ndk_for_testing", actual = "//:dummy")
+EOF
+fi
+
+cat <<EOF >>WORKSPACE.user.bzl
+def android_repositories():
+ android_sdk()
+ android_ndk()
+EOF