Home | History | Annotate | Download | only in vndk-compliance
      1 #!/bin/bash
      2 # This script uses log file saved from make >log 2>&1. It parses and
      3 # fixes the "file not found" errors by adding dependencies to reported
      4 # modules' Android.mk file. It works for following types of issues:
      5 # error: 'hardware/<file>.h' file not found
      6 # error: 'system/<file>.h' file not found
      7 # error: 'cutils/<file>.h' file not found
      8 # error: 'utils/<file>.h' file not found
      9 # error: 'log/<file>.h' file not found
     10 #
     11 # More can be added by expanding ADD_TO_*_LIBS string
     12 #
     13 # This script will create temp files log.<type> and log.<type>.paths
     14 #
     15 # This script requires manual intervention in 2 places:
     16 # 1. Visually inspecting log.<type>.paths and removing undesirable lines
     17 # 2. Manually checking in uncommitted files reported by repo status
     18 
     19 
     20 if [ "$PWD" != "$ANDROID_BUILD_TOP" ]; then
     21   echo "This script needs to be run at top level folder"
     22   exit 1
     23 fi
     24 if [ ! -f "log" ]; then
     25   echo "log file not found"
     26   exit 1
     27 fi
     28 
     29 echo "Parsing log"
     30 cat log | grep "FAILED\|error:" > log.error
     31 
     32 #libs that should be added to LOCAL_HEADER_LIBRARIES
     33 ADD_TO_HEADER_LIBS=(hardware system cutils utils)
     34 
     35 #libs that should be added to LOCAL_SHARED_LIBRARIES
     36 ADD_TO_SHARED_LIBS=(log)
     37 
     38 ALL_LIBS=(${ADD_TO_HEADER_LIBS[@]} ${ADD_TO_SHARED_LIBS[@]})
     39 
     40 for lib in "${ALL_LIBS[@]}"; do
     41   echo "Parsing log.error for $lib"
     42   cat log.error | grep -B1 "error: '$lib\/" | grep FAILED | awk 'BEGIN{FS="_intermediates"}{print $1}' | awk 'BEGIN{FS="S/";}{print $2}' | sort -u > log.$lib
     43 
     44   echo "Parsing log.$lib"
     45   for module in `cat log.$lib`; do find . -name Android.\* | xargs grep -w -H $module | grep "LOCAL_MODULE\|name:"; done > log.$lib.paths
     46 
     47   echo "Please inspect log.$lib.paths and remove lines for devices other than the one you are compiling for."
     48   echo "Also remove duplicate makefile paths, even if they have different module names."
     49   echo "Then press Enter"
     50   read enter
     51   if [ -s "log.$lib.paths" ]; then
     52     not_vendor_list=`cat log.$lib.paths | awk 'BEGIN{FS=":"}{print $1}' | xargs grep -L 'LOCAL_PROPRIETARY_MODULE\|LOCAL_VENDOR_MODULE'`
     53   else
     54     not_vendor_list=
     55   fi
     56   if [ ! -z "$not_vendor_list" ]; then
     57     echo "These modules do NOT have proprietary or vendor flag set."
     58     printf "%s\n" $not_vendor_list
     59     echo "Please check the makefile and update log."$lib".paths, then press Enter"
     60     read enter
     61   fi
     62 done
     63 
     64 for lib in "${ADD_TO_HEADER_LIBS[@]}"; do
     65   echo "Patching makefiles to fix "$lib" errors"
     66   cat log.$lib.paths | awk 'BEGIN{FS=":"}{print $1}' | xargs sed -i '/include \$(BUILD/i LOCAL_HEADER_LIBRARIES += lib'$lib'_headers'
     67   echo "Checking for unsaved files"
     68   repo status
     69   echo "Please COMMIT them, then press Enter:"
     70   read enter
     71 done
     72 
     73 for lib in "${ADD_TO_SHARED_LIBS[@]}"; do
     74   echo "Patching makefiles to fix "$lib" errors"
     75   if [ $lib -eq "log" ]; then
     76     cat log.$lib.paths | awk 'BEGIN{FS=":"}{print $1}' | xargs sed -i '/include \$(BUILD/i ifdef BOARD_VNDK_VERSION\nLOCAL_SHARED_LIBRARIES += lib'$lib'\nendif'
     77   else
     78     cat log.$lib.paths | awk 'BEGIN{FS=":"}{print $1}' | xargs sed -i '/include \$(BUILD/i LOCAL_SHARED_LIBRARIES += lib'$lib
     79   fi
     80   echo "Checking for unsaved files"
     81   repo status
     82   echo "Please COMMIT them, then press Enter:"
     83   read enter
     84 done
     85 
     86