Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 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 | # |
Chiao Cheng | d7a603c | 2012-09-07 13:35:41 -0700 | [diff] [blame] | 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. |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 22 | # |
Chiao Cheng | d7a603c | 2012-09-07 13:35:41 -0700 | [diff] [blame] | 23 | # To use, run the following command from either your repo root or |
| 24 | # development/tools/idegen: |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 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 )" |
Chiao Cheng | d7a603c | 2012-09-07 13:35:41 -0700 | [diff] [blame] | 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 |
Chiao Cheng | c8201d5 | 2013-06-13 13:41:24 -0700 | [diff] [blame] | 41 | tmp_file=${root_dir}/tmp.txt |
| 42 | dest_file=${root_dir}/module-index.txt |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 43 | |
| 44 | echo "Generating index file $dest_file..." |
Brandon McAnsh | 66e5fb0 | 2019-03-21 14:39:26 -0400 | [diff] [blame] | 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 | |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 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 |
Brandon McAnsh | 66e5fb0 | 2019-03-21 14:39:26 -0400 | [diff] [blame] | 67 | |
| 68 | if [ $darwin == 1 ]; |
| 69 | then |
| 70 | end=$(($(date +%s) / 1000000)) |
| 71 | else |
| 72 | end=$(($(date +%s%N) / 1000000)) |
| 73 | fi |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 74 | elapse=$(($end - $start)) |
| 75 | echo "Took ${elapse}ms" |