Skip to content

Commit 5dfd40c

Browse files
jbower-fbfacebook-github-bot
authored andcommitted
Use getdeps.py to drive build of OSS CinderX
Summary: Add a "manifest" for CinderX allowing it and its dependencies to be built and tested with `getdeps.py`. There was no pre-existing "builder" that was appropriate for building a Python extension from source, but rather than adding one that's specific to Cinderx I've tried to write a general builder that uses `setup.py` to install the build into the Python install. Reviewed By: alexmalyshev Differential Revision: D79287319 fbshipit-source-id: d302bea10c6a79cdedc08cd93b0362259dea522b
1 parent 79fd174 commit 5dfd40c

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

build/fbcode_builder/getdeps/builder.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,46 @@ def build(self, reconfigure: bool) -> None:
13681368
simple_copytree(self.src_dir, self.inst_dir)
13691369

13701370

1371+
class SetupPyBuilder(BuilderBase):
1372+
def _build(self, reconfigure) -> None:
1373+
env = self._compute_env()
1374+
1375+
setup_py_path = os.path.join(self.src_dir, "setup.py")
1376+
1377+
if not os.path.exists(setup_py_path):
1378+
raise RuntimeError(f"setup.py script not found at {setup_py_path}")
1379+
1380+
self._check_cmd(
1381+
[path_search(env, "python3"), setup_py_path, "install"],
1382+
cwd=self.src_dir,
1383+
env=env,
1384+
)
1385+
1386+
# Create the installation directory if it doesn't exist
1387+
os.makedirs(self.inst_dir, exist_ok=True)
1388+
1389+
# Mark the project as built
1390+
with open(os.path.join(self.inst_dir, ".built-by-getdeps"), "w") as f:
1391+
f.write("built")
1392+
1393+
def run_tests(self, schedule_type, owner, test_filter, retry, no_testpilot) -> None:
1394+
# setup.py actually no longer has a standard command for running tests.
1395+
# Instead we let manifest files specify an arbitrary Python file to run
1396+
# as a test.
1397+
1398+
# Get the test command from the manifest
1399+
python_script = self.manifest.get(
1400+
"setup-py.test", "python_script", ctx=self.ctx
1401+
)
1402+
if not python_script:
1403+
print(f"No test script specified for {self.manifest.name}")
1404+
return
1405+
1406+
# Run the command
1407+
env = self._compute_env()
1408+
self._check_cmd(["python3", python_script], cwd=self.src_dir, env=env)
1409+
1410+
13711411
class SqliteBuilder(BuilderBase):
13721412
def __init__(
13731413
self,

build/fbcode_builder/getdeps/manifest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
NinjaBootstrap,
2222
NopBuilder,
2323
OpenSSLBuilder,
24+
SetupPyBuilder,
2425
SqliteBuilder,
2526
SystemdBuilder,
2627
)
@@ -114,6 +115,7 @@
114115
"subprojects": {"optional_section": True},
115116
# fb-only
116117
"sandcastle": {"optional_section": True, "fields": {"run_tests": OPTIONAL}},
118+
"setup-py.test": {"optional_section": True, "fields": {"python_script": REQUIRED}},
117119
}
118120

119121
# These sections are allowed to vary for different platforms
@@ -684,6 +686,18 @@ def create_builder( # noqa:C901
684686
inst_dir,
685687
)
686688

689+
if builder == "setup-py":
690+
return SetupPyBuilder(
691+
loader,
692+
dep_manifests,
693+
build_options,
694+
ctx,
695+
self,
696+
src_dir,
697+
build_dir,
698+
inst_dir,
699+
)
700+
687701
if builder == "cargo":
688702
return self.create_cargo_builder(
689703
loader,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[manifest]
2+
name = cinderx-3.12mp
3+
fbsource_path = fbcode/cinderx
4+
shipit_project = facebookincubator/cinderx
5+
6+
[git]
7+
repo_url = https://github.com/facebookincubator/cinderx.git
8+
9+
[build.os=linux]
10+
builder = setup-py
11+
12+
[build.not(os=linux)]
13+
builder = nop
14+
15+
[dependencies]
16+
python-setuptools
17+
meta-python-3.12
18+
19+
[shipit.pathmap]
20+
fbcode/cinderx = cinderx
21+
fbcode/cinderx/oss_toplevel = .
22+
23+
[setup-py.test]
24+
python_script = cinderx/PythonLib/test_cinderx/test_oss_quick.py

0 commit comments

Comments
 (0)