Skip to content

Commit 7149a9c

Browse files
GregoryComerfacebook-github-bot
authored andcommitted
Differentiate between resolve_buck failing due to bad buck version and failing from unexpected error (#2696)
Summary: A missing dependency (or other unexpected error) in resolve_buck.py can cause the CMake build to fail. It needs to gracefully fall back to the previous behavior in this case. bypass-github-export-checks bypass-github-executorch-ci-checks Pull Request resolved: #2696 Test Plan: Uninstalled zstd via pip uninstall zstd. Ran cmake ... Confirmed output message contained warning on script failure and gracefully fell back to system buck2. Repeated above with cmake -DBUCK2=buck2-et2. Confirmed script failure warning and successful build. Reinstalled zstd via pip install zstd. Reviewed By: lucylq Differential Revision: D55391962 Pulled By: GregoryComer fbshipit-source-id: 3711546fb222169a7da954a773e9c057303778ca
1 parent f4b97b2 commit 7149a9c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

build/Utils.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,17 @@ function(resolve_buck2)
191191
if(resolve_buck2_exit_code EQUAL 0)
192192
set(BUCK2 ${resolve_buck2_output} PARENT_SCOPE)
193193
message(STATUS "Resolved buck2 as ${resolve_buck2_output}.")
194-
else()
194+
elseif(resolve_buck2_exit_code EQUAL 2)
195195
# Wrong buck version used. Stop here to ensure that the user sees
196196
# the error.
197-
message(FATAL_ERROR "Failed to resolve buck2.")
198-
message(FATAL_ERROR ${resolve_buck2_error})
197+
message(FATAL_ERROR "Failed to resolve buck2.\n${resolve_buck2_error}")
198+
else()
199+
# Unexpected failure of the script. Warn.
200+
message(WARNING "Failed to resolve buck2.")
201+
message(WARNING "${resolve_buck2_error}")
202+
203+
if("${BUCK2}" STREQUAL "")
204+
set(BUCK2 "buck2" PARENT_SCOPE)
205+
endif()
199206
endif()
200-
endfunction()
207+
endfunction()

build/resolve_buck.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
154154
)
155155

156156
# Return an error, since the build will fail later. This lets us
157-
# give the user a more useful error message.
158-
return -1
157+
# give the user a more useful error message. Note that an exit
158+
# code of 2 allows us to distinguish from an unexpected error,
159+
# such as a failed import, which exits with 1.
160+
return 2
159161
else:
160162
# Look for system buck2 and check version. Note that this can return
161163
# None.

0 commit comments

Comments
 (0)