Skip to content

Commit 58d72fd

Browse files
authored
Properly kill the buck2 daemon (#5863)
Summary: Fix the `buck2 kill` command. Because of scoping issues, in some cases we only ran "` kill`" because the local value of `$BUCK2` was empty. This should help avoid failures like ``` Error validating working directory Caused by: 0: Failed to stat `/home/ubuntu/cmodi/executorch/buck-out/v2` 1: ENOENT: No such file or directory ``` which are typically fixed by running `buck2 kill`. Add "COMMAND_ECHO" to the kill command to show what we're running. Also, make the function consistently use `executorch_root` as the working directory. We should always run buck2 from the ET repo. Reviewed By: byjlw Differential Revision: D62676219 fbshipit-source-id: 28f032a05d2c66dc21b30c783617eb1a77e28e64
1 parent cf56ba7 commit 58d72fd

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

build/Utils.cmake

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,14 @@ function(resolve_buck2)
235235
OUTPUT_VARIABLE resolve_buck2_output
236236
ERROR_VARIABLE resolve_buck2_error
237237
RESULT_VARIABLE resolve_buck2_exit_code
238-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
238+
WORKING_DIRECTORY ${executorch_root}
239239
OUTPUT_STRIP_TRAILING_WHITESPACE
240240
)
241241

242+
# $BUCK2 is a copy of the var from the parent scope. This block will set
243+
# $buck2 to the value we want to return.
242244
if(resolve_buck2_exit_code EQUAL 0)
243-
set(BUCK2
244-
${resolve_buck2_output}
245-
PARENT_SCOPE
246-
)
245+
set(buck2 ${resolve_buck2_output})
247246
message(STATUS "Resolved buck2 as ${resolve_buck2_output}.")
248247
elseif(resolve_buck2_exit_code EQUAL 2)
249248
# Wrong buck version used. Stop here to ensure that the user sees the error.
@@ -254,17 +253,22 @@ function(resolve_buck2)
254253
message(WARNING "${resolve_buck2_error}")
255254

256255
if("${BUCK2}" STREQUAL "")
257-
set(BUCK2
258-
"buck2"
259-
PARENT_SCOPE
260-
)
256+
set(buck2 "buck2")
261257
endif()
262258
endif()
263259

260+
# Update the var in the parent scope. Note that this does not modify our
261+
# local $BUCK2 value.
262+
set(BUCK2 "${buck2}" PARENT_SCOPE)
263+
264264
# The buck2 daemon can get stuck. Killing it can help.
265265
message(STATUS "Killing buck2 daemon")
266266
execute_process(
267-
COMMAND "${BUCK2} kill" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
267+
# Note that we need to use the local buck2 variable. BUCK2 is only set in
268+
# the parent scope, and can still be empty in this scope.
269+
COMMAND "${buck2} kill"
270+
WORKING_DIRECTORY ${executorch_root}
271+
COMMAND_ECHO STDOUT
268272
)
269273
endfunction()
270274

0 commit comments

Comments
 (0)