11
11
import platform
12
12
import stat
13
13
import sys
14
- import tempfile
15
14
import urllib .request
16
15
17
16
from dataclasses import dataclass
@@ -85,6 +84,12 @@ class BuckInfo:
85
84
archive_name = "buck2-x86_64-apple-darwin.zst" ,
86
85
target_versions = ["3eb1ae97ea963086866b4d2d9ffa966d" ],
87
86
),
87
+ ("windows" , "x86_64" ): BuckInfo (
88
+ archive_name = "buck2-x86_64-pc-windows-msvc.exe.zst" ,
89
+ target_versions = [
90
+ "bf1685c4c4ddd9de4592b5a955cb7326fd01e6c4d5f561643422bed961a17401"
91
+ ],
92
+ ),
88
93
}
89
94
90
95
@@ -135,6 +140,8 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
135
140
os_family = "linux"
136
141
elif sys .platform .startswith ("darwin" ):
137
142
os_family = "darwin"
143
+ elif sys .platform .startswith ("win" ):
144
+ os_family = "windows"
138
145
139
146
platform_key = (os_family , arch )
140
147
if platform_key not in BUCK_PLATFORM_MAP :
@@ -193,12 +200,12 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
193
200
194
201
buck2_archive_url = f"https://github.com/facebook/buck2/releases/download/{ target_buck_version } /{ buck_info .archive_name } "
195
202
196
- with tempfile . NamedTemporaryFile () as archive_file :
203
+ try :
197
204
print (f"Downloading buck2 from { buck2_archive_url } ..." , file = sys .stderr )
198
- urllib .request .urlretrieve (buck2_archive_url , archive_file . name )
205
+ archive_file , _ = urllib .request .urlretrieve (buck2_archive_url )
199
206
200
207
# Extract and chmod.
201
- with open (archive_file . name , "rb" ) as f :
208
+ with open (archive_file , "rb" ) as f :
202
209
data = f .read ()
203
210
decompressed_bytes = zstd .decompress (data )
204
211
@@ -207,6 +214,8 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
207
214
208
215
file_stat = os .stat (buck2_local_path )
209
216
os .chmod (buck2_local_path , file_stat .st_mode | stat .S_IEXEC )
217
+ finally :
218
+ os .remove (archive_file )
210
219
211
220
return buck2_local_path
212
221
0 commit comments