Home | History | Annotate | Download | only in build
      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
     18 CALLED_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.
     22 SCRIPTNAME=$(basename "$0")
     23 SCRIPTPATH=$( cd "$(dirname "$0")" ; pwd -P )
     24 GRADLE=$SCRIPTPATH/gradlew
     25 
     26 # Parameter 1 is the path from the cwd to the sample.
     27 SAMPLE_PATH=""
     28 if  [ -n "$1" ]; then
     29     SAMPLE_PATH=$CALLED_FROM/$1
     30 fi
     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.
     35 BUILDPATH=$(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.
     38 SAMPLES_COMMON=$( cd $SCRIPTPATH/../samples/android/common ; pwd -P)
     39 COMMONPATH=$(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