Home | History | Annotate | Download | only in hidl
      1 #!/bin/bash
      2 
      3 #TODO(b/35570956): Do with Soong instead.
      4 
      5 #Note: see do_makefiles_update below.
      6 
      7 function package_root_to_package() {
      8   echo $1 | cut -f1 -d:
      9 }
     10 
     11 function package_root_to_root() {
     12   echo $1 | cut -f2 -d:
     13 }
     14 
     15 ##
     16 # Makes sure the appropriate directories are visible.
     17 # Usage: check_dirs [package:root ...]
     18 function check_dirs() {
     19   for package_root in "$@"; do
     20       dir=$(package_root_to_root $package_root)
     21       if [ ! -d $dir ] ; then
     22         echo "Where is $dir?";
     23         return 1;
     24       fi
     25   done
     26 }
     27 
     28 ##
     29 # Gets all packages in a directory.
     30 # Usage: get_packages package root
     31 function get_packages() {
     32   local current_dir=$1
     33   local current_package=$2
     34   pushd $current_dir > /dev/null;
     35   find . -type f -name \*.hal -exec dirname {} \; | sort -u | \
     36     cut -c3- | \
     37     awk -F'/' \
     38     '{printf("'$current_package'"); for(i=1;i<NF;i++){printf(".%s", $i);}; printf("@%s\n", $NF);}';
     39   popd > /dev/null;
     40 }
     41 
     42 ##
     43 # Package roots to arguments.
     44 # Usage: get_root_arguments [package:root ...]
     45 function get_root_arguments() {
     46   for package_root in "$@"; do
     47       echo "-r $package_root"
     48   done
     49 }
     50 
     51 ##
     52 # Subdirectories of a directory which contain Android.bps
     53 # Note, does not return Android.bp in the current directory.
     54 #
     55 # Usage: get_bp_dirs dir
     56 function get_bp_dirs() {
     57   find $1/*                          \
     58     -mindepth 1                      \
     59     -name "Android.bp"               \
     60     -printf "%H\n"                   \
     61     | sort | uniq
     62 }
     63 
     64 ##
     65 # Helps manage the package root of a HAL directory.
     66 # Should be called from the android root directory.
     67 #
     68 # Usage: do_makefiles_update [package:root ...]
     69 # Where the first package root is the current one.
     70 #
     71 function do_makefiles_update() {
     72   local current_package=$(package_root_to_package $1)
     73   local current_dir=$(package_root_to_root $1)
     74 
     75   echo "Updating makefiles for $current_package in $current_dir."
     76 
     77   check_dirs $@ || return 1
     78 
     79   local packages=$(get_packages $current_dir $current_package) || return 1
     80   local root_arguments=$(get_root_arguments $@) || return 1
     81 
     82   for p in $packages; do
     83     echo "Updating $p";
     84     hidl-gen -Lmakefile $root_arguments $p;
     85     rc=$?; if [[ $rc != 0 ]]; then return $rc; fi
     86     hidl-gen -Landroidbp $root_arguments $p;
     87     rc=$?; if [[ $rc != 0 ]]; then return $rc; fi
     88   done
     89 
     90   local android_dirs=$(get_bp_dirs $current_dir) || return 1
     91 
     92   echo "Updating Android.bp files."
     93 
     94   for bp_dir in $android_dirs; do
     95     bp="$bp_dir/Android.bp"
     96     # locations of Android.bp files in specific subdirectory of frameworks/hardware/interfaces
     97     android_bps=$(find $bp_dir                   \
     98                   -name "Android.bp"             \
     99                   ! -path $bp_dir/Android.bp     \
    100                   -printf "%h\n"                 \
    101                   | sort)
    102 
    103     echo "// This is an autogenerated file, do not edit." > "$bp";
    104     echo "subdirs = [" >> "$bp";
    105     for a in $android_bps; do
    106       echo "    \"${a#$bp_dir/}\"," >> "$bp";
    107     done
    108     echo "]" >> "$bp";
    109   done
    110 }
    111