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