From 23c46cf42453bfef7f1bd88e21e422a75a281281 Mon Sep 17 00:00:00 2001 From: Roland Levillain Date: Tue, 31 Mar 2020 16:11:05 +0100 Subject: [PATCH] Print a user-friendly message when `lunch` cannot use the default product. In some environments (e.g. with the master-art branch), the default product (aosp_arm-eng) cannot be built, and thus prevents `lunch` from printing the lunch menu (as it cannot initialize the build system in order to fetch the common lunch choices). When this happens, show an explicit error message from `lunch` instead of a Soong UI error. Test: Check that this command line displays the expected error message: unset TARGET_PRODUCT && . build/envsetup.sh && lunch Bug: 152762648 Change-Id: I40c66bca5b075d88dbc8364b36b2db713e6ad93e --- envsetup.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/envsetup.sh b/envsetup.sh index 791a43d78..5e924ab42 100644 --- a/envsetup.sh +++ b/envsetup.sh @@ -119,13 +119,13 @@ function get_build_var() if [ "$BUILD_VAR_CACHE_READY" = "true" ] then eval "echo \"\${var_cache_$1}\"" - return + return 0 fi local T=$(gettop) if [ ! "$T" ]; then echo "Couldn't locate the top of the tree. Try setting TOP." >&2 - return + return 1 fi (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1) } @@ -576,10 +576,25 @@ function add_lunch_combo() function print_lunch_menu() { local uname=$(uname) - local choices=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES) + local choices + choices=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES 2>/dev/null) + local ret=$? + echo echo "You're building on" $uname echo + + if [ $ret -ne 0 ] + then + echo "Warning: Cannot display lunch menu." + echo + echo "Note: You can invoke lunch with an explicit target:" + echo + echo " usage: lunch [target]" >&2 + echo + return + fi + echo "Lunch menu... pick a combo:" local i=1