Home | History | Annotate | Download | only in findunused
      1 #!/bin/bash
      2 
      3 if ! which xmlstarlet > /dev/null
      4 then
      5     echo "You need to have the 'xmlstarlet' command in your path"
      6     exit
      7 fi
      8 
      9 apps=$1
     10 CWD=$(pwd)/
     11 if [ "$apps" = "" ]
     12 then
     13     echo "Please specify the path to an application, or '--all' to process all applications"
     14     exit
     15 elif [ "$apps" = "--all" ]
     16 then
     17     apps=$ANDROID_BUILD_TOP/packages/apps/*
     18 fi
     19 
     20 BASE=$(pwd)/$(dirname $0)
     21 
     22 for app in $apps
     23 do
     24     pushd $app
     25     $BASE/findunusedresources -p . | {
     26         read LINE NUM
     27         while [ "$LINE" != "" ]
     28         do
     29             if [ "Z$LINE" = "Z-----------------------------------------------------------" ]
     30             then
     31                 # skip
     32                 true
     33             elif [ "$LINE" = "$app" ]
     34             then
     35                 # skip
     36                 true
     37             else
     38                 # try to find the missing resource
     39                 find res | grep -w $LINE  | {
     40                     read RESLINE
     41                     while [ "$RESLINE" != "" ]
     42                     do
     43                         if [ -f $RESLINE ]
     44                         then
     45                             echo REMOVING FILE: $RESLINE
     46                             git rm $RESLINE > /dev/null
     47                         else
     48                             echo WARNING unexpected result for $LINE
     49                         fi
     50                         read RESLINE
     51                     done
     52                 }
     53                 grep -Rwl $LINE res | {
     54                     read RESLINE
     55                     while [ "$RESLINE" != "" ]
     56                     do
     57                         ISSTRING=$(echo "$RESLINE" | grep -w "strings\.xml")
     58                         if [ -n "$ISSTRING" ]
     59                         then
     60                             echo REMOVING STRING $LINE from $RESLINE
     61                             xmlstarlet ed -P -S -d "/resources/string[@name='$LINE']" $RESLINE > tf$$
     62                             mv tf$$ $RESLINE
     63                             git add $RESLINE
     64                         else
     65                             echo REMOVING $LINE from $RESLINE
     66                             xmlstarlet ed -P -S -d "/resources/*[@name='$LINE']" $RESLINE > tf$$
     67                             mv tf$$ $RESLINE
     68                             git add $RESLINE
     69                         fi
     70                         read RESLINE
     71                     done
     72                 }
     73             fi
     74             read LINE NUM
     75         done
     76     }
     77     popd
     78 done
     79 echo
     80 echo "Done."
     81 echo "Please rebuild the updated applications to make sure that everything still builds."
     82 echo "After rebuilding, rerun 'findunusedresources' or 'removeunusedresources' to see if any more resources are now unused."
     83 echo "When you're done, you can 'git commit' the change."
     84 echo
     85