This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
buck_ext.py
48 lines (40 loc) · 1.52 KB
/
buck_ext.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# Copyright 2004-present Facebook. All Rights Reserved.
import os
import platform
import shutil
import subprocess
from setuptools import Extension
from setuptools.command.build_ext import build_ext
CONFIG_FILE = {
"Windows": "win.buckconfig",
}.get(platform.system(), "unix.buckconfig")
if platform.system() == 'Linux' and platform.linux_distribution()[0] == 'CentOS Linux':
CONFIG_FILE = "manylinux.buckconfig"
class BuckExtension(Extension):
def __init__(self, name: str, target: str) -> None:
# don't invoke the original build_ext
super().__init__(name, sources=[])
self.target = target
class buck_build_ext(build_ext):
def build_extensions(self) -> None:
if "DF_SKIP_BUCK_BUILD" in os.environ:
return
assert shutil.which("buck") is not None, (
"Could not find buck on the PATH\n"
"To install Buck please see https://buck.build/setup/getting_started.html"
)
exts_by_target = {
ext.target: ext for ext in self.extensions if isinstance(ext, BuckExtension)
}
result = (
subprocess.check_output(
["buck", "build", "--show-output", "--config-file", CONFIG_FILE]
+ list(exts_by_target.keys())
)
.decode("utf-8")
.strip()
)
for line in result.split("\n"):
target, output_path = line.split(" ")
shutil.copy(output_path, self.get_ext_fullpath(exts_by_target[target].name))