Skip to content

Commit 084d835

Browse files
authored
[build Folder Migration] Move buck scripts for cmake (#9336)
### Summary A series of diffs as a part of #9117. ### Test plan CI ``` $ rm -rf pip-out && python setup.py bdist_wheel ``` cc @larryliu0820 @lucylq
1 parent 31890cb commit 084d835

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

tools/__init__.py

Whitespace-only changes.

tools/cmake/Utils.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ function(extract_sources sources_file)
218218
endif()
219219
execute_process(
220220
COMMAND
221-
${PYTHON_EXECUTABLE} ${executorch_root}/build/extract_sources.py
222-
--config=${executorch_root}/build/cmake_deps.toml --out=${sources_file}
221+
${PYTHON_EXECUTABLE} ${executorch_root}/tools/cmake/extract_sources.py
222+
--config=${executorch_root}/tools/cmake/cmake_deps.toml --out=${sources_file}
223223
--buck2=${BUCK2} ${target_platforms_arg}
224224
OUTPUT_VARIABLE gen_srcs_output
225225
ERROR_VARIABLE gen_srcs_error
@@ -254,7 +254,7 @@ function(resolve_buck2)
254254
endif()
255255

256256
set(resolve_buck2_command
257-
${PYTHON_EXECUTABLE} ${executorch_root}/build/resolve_buck.py
257+
${PYTHON_EXECUTABLE} ${executorch_root}/tools/cmake/resolve_buck.py
258258
--cache_dir=buck2-bin
259259
)
260260

tools/cmake/__init__.py

Whitespace-only changes.

build/buck_util.py renamed to tools/cmake/buck_util.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88
import os
99
import subprocess
1010
import sys
11+
from functools import cache
12+
from pathlib import Path
1113

1214
from typing import Optional, Sequence
1315

1416

15-
# Run buck2 from the same directory (and thus repo) as this script.
16-
BUCK_CWD: str = os.path.dirname(os.path.realpath(__file__))
17+
@cache
18+
def repo_root_dir() -> Path:
19+
git_root = subprocess.check_output(
20+
["git", "rev-parse", "--show-toplevel"],
21+
cwd=os.path.dirname(os.path.realpath(__file__)),
22+
text=True,
23+
).strip()
24+
return Path(git_root)
1725

1826

1927
class Buck2Runner:
@@ -26,7 +34,7 @@ def run(self, args: Sequence[str]) -> list[str]:
2634
cp: subprocess.CompletedProcess = subprocess.run(
2735
[self._path] + args, # type: ignore[operator]
2836
capture_output=True,
29-
cwd=BUCK_CWD,
37+
cwd=repo_root_dir(),
3038
check=True,
3139
)
3240
return [line.strip().decode("utf-8") for line in cp.stdout.splitlines()]
File renamed without changes.
File renamed without changes.

build/resolve_buck.py renamed to tools/cmake/resolve_buck.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
3838
"""
3939

40+
4041
# Path to the file containing BUCK2 version (build date) for ExecuTorch.
41-
# Note that this path is relative to this script file, not the working
42-
# directory.
43-
BUCK_VERSION_FILE = "../.ci/docker/ci_commit_pins/buck2.txt"
42+
def _buck_version_path() -> Path:
43+
return buck_util.repo_root_dir() / ".ci/docker/ci_commit_pins/buck2.txt"
4444

4545

4646
@dataclass
@@ -125,9 +125,7 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
125125

126126
# Read the target version (build date) from the CI pin file. Note that
127127
# this path is resolved relative to the directory containing this script.
128-
script_dir = os.path.dirname(__file__)
129-
version_file_path = Path(script_dir) / BUCK_VERSION_FILE
130-
with open(version_file_path.absolute().as_posix()) as f:
128+
with open(_buck_version_path().absolute().as_posix()) as f:
131129
target_buck_version = f.read().strip()
132130

133131
# Determine the target buck2 version string according to the current

0 commit comments

Comments
 (0)