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=tmp.txt
     42 dest_file=module-index.txt
     43 
     44 echo "Generating index file $dest_file..."
     45 start=$(($(date +%s%N) / 1000000))
     46 find $root_dir -name '*.mk' \( ! -path "$root_dir/build*" -prune \) \
     47   \( -exec grep -H '^LOCAL_PACKAGE_NAME ' {} \; \
     48   -false -o -exec grep -H '^LOCAL_MODULE ' {} \; \) \
     49   > $tmp_file
     50 sed -e 's/LOCAL_PACKAGE_NAME *:= *//g' -e 's/LOCAL_MODULE *:= *//g' -e 's/\^M*$//g' < $tmp_file > $dest_file
     51 
     52 mv $dest_file $tmp_file
     53 # Exclude specific directories from index here.
     54 # TODO: make excludes more generic and configurable
     55 grep -v "^$root_dir/vendor/google" $tmp_file > $dest_file
     56 
     57 rm $tmp_file
     58 end=$(($(date +%s%N) / 1000000))
     59 elapse=$(($end - $start))
     60 echo "Took ${elapse}ms"
     61