1#!/bin/bash
2
3# TODO: Currently only checks trunk_staging. Should check trunk_staging first,
4#       then use the product-specfic releases. Only applies to -c though.
5
6function Help() {
7cat <<@EOF@
8Usage: lunchable [options]
9
10Lists products that have no functioning lunch combo.
11
12options:
13-c    prints all failing lunch combos for all targets;
14-w    why? Prints the error message after each failed lunch combo. Only
15      works with -c
16
17@EOF@
18}
19
20complete=0
21why=0
22while getopts "cwh" option; do
23  case $option in
24    c)
25      complete=1;;
26    w)
27      why=1;;
28    h)
29      Help
30      exit;;
31  esac
32done
33
34# Getting all named products can fail if we haven't lunched anything
35source $(pwd)/build/envsetup.sh &> /dev/null
36all_named_products=( $(get_build_var all_named_products 2> /dev/null) )
37if [[ $? -ne 0 ]]; then
38  echo "get_build_var all_named_products failed. Lunch something first?" >&2
39  exit 1
40fi
41total_products=${#all_named_products[@]}
42current_product=0
43
44for product in "${all_named_products[@]}"; do
45  (( current_product += 1 ))
46  single_pass=0
47  printf " Checking ${current_product}/${total_products} \r" >&2
48  for release in trunk_staging; do
49    for variant in eng user userdebug; do
50      lunchcombo="${product}-${release}-${variant}"
51      lunch_error="$(lunch $lunchcombo 2>&1 > /dev/null)"
52      if [[ $? -ne 0 ]]; then
53        # Lunch failed
54        if [[ $complete -eq 1 ]]; then
55          echo -e "${product} : ${lunchcombo}"
56          if [[ $why -eq 1 ]]; then
57            echo -e "$(sed 's/^/    /g' <<<$lunch_error)"
58          fi
59        fi
60      elif [[ $complete -ne 1 ]]; then
61        single_pass=1
62        break # skip variant
63      fi
64    done
65    if [[ $single_pass -eq 1 ]]; then
66      break # skip release
67    fi
68  done
69  if [[ $complete -eq 0 ]] && [[ $single_pass -eq 0 ]]; then
70    echo "${product}"
71  fi
72done
73