Skip to content

Commit 70aee72

Browse files
dbortfacebook-github-bot
authored andcommitted
Properly kill the buck2 daemon
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 98c5efa commit 70aee72

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
@@ -247,15 +247,14 @@ function(resolve_buck2)
247247
OUTPUT_VARIABLE resolve_buck2_output
248248
ERROR_VARIABLE resolve_buck2_error
249249
RESULT_VARIABLE resolve_buck2_exit_code
250-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
250+
WORKING_DIRECTORY ${executorch_root}
251251
OUTPUT_STRIP_TRAILING_WHITESPACE
252252
)
253253

254+
# $BUCK2 is a copy of the var from the parent scope. This block will set
255+
# $buck2 to the value we want to return.
254256
if(resolve_buck2_exit_code EQUAL 0)
255-
set(BUCK2
256-
${resolve_buck2_output}
257-
PARENT_SCOPE
258-
)
257+
set(buck2 ${resolve_buck2_output})
259258
message(STATUS "Resolved buck2 as ${resolve_buck2_output}.")
260259
elseif(resolve_buck2_exit_code EQUAL 2)
261260
# Wrong buck version used. Stop here to ensure that the user sees the error.
@@ -266,17 +265,22 @@ function(resolve_buck2)
266265
message(WARNING "${resolve_buck2_error}")
267266

268267
if("${BUCK2}" STREQUAL "")
269-
set(BUCK2
270-
"buck2"
271-
PARENT_SCOPE
272-
)
268+
set(buck2 "buck2")
273269
endif()
274270
endif()
275271

272+
# Update the var in the parent scope. Note that this does not modify our
273+
# local $BUCK2 value.
274+
set(BUCK2 "${buck2}" PARENT_SCOPE)
275+
276276
# The buck2 daemon can get stuck. Killing it can help.
277277
message(STATUS "Killing buck2 daemon")
278278
execute_process(
279-
COMMAND "${BUCK2} kill" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
279+
# Note that we need to use the local buck2 variable. BUCK2 is only set in
280+
# the parent scope, and can still be empty in this scope.
281+
COMMAND "${buck2} kill"
282+
WORKING_DIRECTORY ${executorch_root}
283+
COMMAND_ECHO STDOUT
280284
)
281285
endfunction()
282286

0 commit comments

Comments
 (0)