Home | History | Annotate | Download | only in idegen
      1 #!/bin/bash
      2 #
      3 # Copyright (C) 2012 The Android Open Source Project
      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 # Generates a module index file by searching through android source
     18 # tree for make files.  The intellij-gen.sh script automatically calls
     19 # this script the first time or if you delete the generated indexed
     20 # file.  The only time you need to run this manually is if modules are
     21 # added or deleted.
     22 #
     23 # To use, run the following command from either your repo root or
     24 # development/tools/idegen:
     25 #   index-gen.sh
     26 #
     27 # Only tested on linux.  Should work for macs but have not tried.
     28 #
     29 set -e
     30 
     31 script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
     32 #root_dir=`readlink -f -n $script_dir/../../..`
     33 root_dir=$PWD
     34 if [ ! -e $root_dir/.repo ]; then
     35   root_dir=$PWD/../../..
     36   if [ ! -e $root_dir/.repo ]; then
     37     echo "Repo root not found. Run this script from your repo root or the idegen directory."
     38     exit 1
     39   fi
     40 fi
     41 tmp_file=${root_dir}/tmp.txt
     42 dest_file=${root_dir}/module-index.txt
     43 
     44 echo "Generating index file $dest_file..."
     45 
     46 [[ "$(uname -s)" == "Darwin" ]] && darwin=1 || darwin=0
     47 
     48 if [ $darwin == 1 ];
     49 then
     50   start=$(($(date +%s) / 1000000))
     51 else
     52   start=$(($(date +%s%N) / 1000000))
     53 fi
     54 
     55 find $root_dir -name '*.mk' \( ! -path "$root_dir/build*" -prune \) \
     56   \( -exec grep -H '^LOCAL_PACKAGE_NAME ' {} \; \
     57   -false -o -exec grep -H '^LOCAL_MODULE ' {} \; \) \
     58   > $tmp_file
     59 sed -e 's/LOCAL_PACKAGE_NAME *:= *//g' -e 's/LOCAL_MODULE *:= *//g' -e 's/\^M*$//g' < $tmp_file > $dest_file
     60 
     61 mv $dest_file $tmp_file
     62 # Exclude specific directories from index here.
     63 # TODO: make excludes more generic and configurable
     64 grep -v "^$root_dir/vendor/google" $tmp_file > $dest_file
     65 
     66 rm $tmp_file
     67 
     68 if [ $darwin == 1 ];
     69 then
     70   end=$(($(date +%s) / 1000000))
     71 else
     72   end=$(($(date +%s%N) / 1000000))
     73 fi
     74 elapse=$(($end - $start))
     75 echo "Took ${elapse}ms"
     76