• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2# Copyright 2013 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Record the current working directory. This allows us to correctly interpret
17# relative paths
18CALLED_FROM=$( pwd -P )
19
20# Record the location of this script. The assumption is that the script is located in the
21# top-level build directory, so finding the script means finding the build directory.
22SCRIPTNAME=$(basename "$0")
23SCRIPTPATH=$( cd "$(dirname "$0")" ; pwd -P )
24GRADLE=$SCRIPTPATH/gradlew
25
26# Parameter 1 is the path from the cwd to the sample.
27SAMPLE_PATH=""
28if  [ -n "$1" ]; then
29    SAMPLE_PATH=$CALLED_FROM/$1
30fi
31
32# Calculate the relative path from the sample location to the main build directory. This
33# allows us to define build dependencies as relative paths, rather than requiring the developer
34# to add them to the environment.
35BUILDPATH=$(perl -e "use File::Spec; print File::Spec->abs2rel(@ARGV)" $SCRIPTPATH $SAMPLE_PATH)
36
37# Same thing for the samples common code: calculate the relative path.
38SAMPLES_COMMON=$( cd $SCRIPTPATH/../samples/android/common ; pwd -P)
39COMMONPATH=$(perl -e "use File::Spec; print File::Spec->abs2rel(@ARGV)" $SAMPLES_COMMON $SAMPLE_PATH)
40
41# Launch a Gradle build with the SampleGen creation parameters on the command line
42# Note: Daemon disabled since the script reads for System.console. This overrides user settings.
43$GRADLE -b $SCRIPTPATH/build.gradle --info --no-daemon create -Pout=$SAMPLE_PATH \
44    -PcalledFrom=$CALLED_FROM -PpathToSamplesCommon=$COMMONPATH -PpathToBuild=$BUILDPATH
45