From cf7cee3a1ec5184d0a0bbd0d6816906fb454c94d Mon Sep 17 00:00:00 2001 From: Gregory Comer Date: Tue, 26 Mar 2024 15:38:07 -0700 Subject: [PATCH] Differentiate between resolve_buck failing due to bad buck version and failing from unexpected error (#2696) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/2696 Differential Revision: D55391962 Pulled By: GregoryComer --- build/Utils.cmake | 17 +++++++++++++---- build/resolve_buck.py | 6 ++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/build/Utils.cmake b/build/Utils.cmake index 10844b453cb..d57e47baea3 100644 --- a/build/Utils.cmake +++ b/build/Utils.cmake @@ -188,13 +188,22 @@ function(resolve_buck2) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE) + message("${resolve_buck2_exit_code}") + if(resolve_buck2_exit_code EQUAL 0) set(BUCK2 ${resolve_buck2_output} PARENT_SCOPE) message(STATUS "Resolved buck2 as ${resolve_buck2_output}.") - else() + elseif(resolve_buck2_exit_code EQUAL 2) # Wrong buck version used. Stop here to ensure that the user sees # the error. - message(FATAL_ERROR "Failed to resolve buck2.") - message(FATAL_ERROR ${resolve_buck2_error}) + message(FATAL_ERROR "Failed to resolve buck2.\n${resolve_buck2_error}") + else() + # Unexpected failure of the script. Warn. + message(WARNING "Failed to resolve buck2.") + message(WARNING "${resolve_buck2_error}") + + if("${BUCK2}" STREQUAL "") + set(BUCK2 "buck2" PARENT_SCOPE) + endif() endif() -endfunction() \ No newline at end of file +endfunction() diff --git a/build/resolve_buck.py b/build/resolve_buck.py index 6cd816494d7..cba151ab340 100644 --- a/build/resolve_buck.py +++ b/build/resolve_buck.py @@ -154,8 +154,10 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]: ) # Return an error, since the build will fail later. This lets us - # give the user a more useful error message. - return -1 + # give the user a more useful error message. Note that an exit + # code of 2 allows us to distinguish from an unexpected error, + # such as a failed import, which exits with 1. + return 2 else: # Look for system buck2 and check version. Note that this can return # None.