Skip to content

Commit 1bac885

Browse files
python3kgaeXiang Li
andauthored
[Build] Support windows in resolve_buck.py (#4856)
* [Build] Support windows in resolve_buck.py Add Windows support to BUCK_PLATFORM_MAP. Also use urllib.request.urlretrieve directly to work around PermissionError on Windows. For #4661 * Update buck2 to2024-12-16 --------- Co-authored-by: Xiang Li <[email protected]>
1 parent 08770b7 commit 1bac885

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

build/resolve_buck.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import platform
1212
import stat
1313
import sys
14-
import tempfile
1514
import urllib.request
1615

1716
from dataclasses import dataclass
@@ -90,6 +89,12 @@ class BuckInfo:
9089
archive_name="buck2-x86_64-apple-darwin.zst",
9190
target_versions=["9c9a583658d43e82b41f3fc9d369a9b0"],
9291
),
92+
("windows", "x86_64"): BuckInfo(
93+
archive_name="buck2-x86_64-pc-windows-msvc.exe.zst",
94+
target_versions=[
95+
"c7d378f3f307e9590f0b29a5f7f1b21b8e784f4e4bd30a0160b2a69df50d2ee0"
96+
],
97+
),
9398
}
9499

95100

@@ -140,6 +145,8 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
140145
os_family = "linux"
141146
elif sys.platform.startswith("darwin"):
142147
os_family = "darwin"
148+
elif sys.platform.startswith("win"):
149+
os_family = "windows"
143150

144151
platform_key = (os_family, arch)
145152
if platform_key not in BUCK_PLATFORM_MAP:
@@ -198,12 +205,12 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
198205

199206
buck2_archive_url = f"https://github.com/facebook/buck2/releases/download/{target_buck_version}/{buck_info.archive_name}"
200207

201-
with tempfile.NamedTemporaryFile() as archive_file:
208+
try:
202209
print(f"Downloading buck2 from {buck2_archive_url}...", file=sys.stderr)
203-
urllib.request.urlretrieve(buck2_archive_url, archive_file.name)
210+
archive_file, _ = urllib.request.urlretrieve(buck2_archive_url)
204211

205212
# Extract and chmod.
206-
with open(archive_file.name, "rb") as f:
213+
with open(archive_file, "rb") as f:
207214
data = f.read()
208215
decompressed_bytes = zstd.decompress(data)
209216

@@ -212,6 +219,8 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
212219

213220
file_stat = os.stat(buck2_local_path)
214221
os.chmod(buck2_local_path, file_stat.st_mode | stat.S_IEXEC)
222+
finally:
223+
os.remove(archive_file)
215224

216225
return buck2_local_path
217226

0 commit comments

Comments
 (0)