From 573aa3b6a121429c0729c456f597813da8c01f65 Mon Sep 17 00:00:00 2001 From: Jacob Bower Date: Fri, 1 Aug 2025 01:53:45 -0700 Subject: [PATCH] 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 --- build/fbcode_builder/getdeps/builder.py | 40 +++++++++++++++++++ build/fbcode_builder/getdeps/manifest.py | 14 +++++++ build/fbcode_builder/manifests/cinderx-3.12mp | 24 +++++++++++ 3 files changed, 78 insertions(+) create mode 100644 build/fbcode_builder/manifests/cinderx-3.12mp diff --git a/build/fbcode_builder/getdeps/builder.py b/build/fbcode_builder/getdeps/builder.py index 030dd63f0..ec5c68e7c 100644 --- a/build/fbcode_builder/getdeps/builder.py +++ b/build/fbcode_builder/getdeps/builder.py @@ -1368,6 +1368,46 @@ class NopBuilder(BuilderBase): simple_copytree(self.src_dir, self.inst_dir) +class SetupPyBuilder(BuilderBase): + def _build(self, reconfigure) -> None: + env = self._compute_env() + + setup_py_path = os.path.join(self.src_dir, "setup.py") + + if not os.path.exists(setup_py_path): + raise RuntimeError(f"setup.py script not found at {setup_py_path}") + + self._check_cmd( + [path_search(env, "python3"), setup_py_path, "install"], + cwd=self.src_dir, + env=env, + ) + + # Create the installation directory if it doesn't exist + os.makedirs(self.inst_dir, exist_ok=True) + + # Mark the project as built + with open(os.path.join(self.inst_dir, ".built-by-getdeps"), "w") as f: + f.write("built") + + def run_tests(self, schedule_type, owner, test_filter, retry, no_testpilot) -> None: + # setup.py actually no longer has a standard command for running tests. + # Instead we let manifest files specify an arbitrary Python file to run + # as a test. + + # Get the test command from the manifest + python_script = self.manifest.get( + "setup-py.test", "python_script", ctx=self.ctx + ) + if not python_script: + print(f"No test script specified for {self.manifest.name}") + return + + # Run the command + env = self._compute_env() + self._check_cmd(["python3", python_script], cwd=self.src_dir, env=env) + + class SqliteBuilder(BuilderBase): def __init__( self, diff --git a/build/fbcode_builder/getdeps/manifest.py b/build/fbcode_builder/getdeps/manifest.py index b1b25cd37..90fb27186 100644 --- a/build/fbcode_builder/getdeps/manifest.py +++ b/build/fbcode_builder/getdeps/manifest.py @@ -21,6 +21,7 @@ from .builder import ( NinjaBootstrap, NopBuilder, OpenSSLBuilder, + SetupPyBuilder, SqliteBuilder, SystemdBuilder, ) @@ -114,6 +115,7 @@ SCHEMA = { "subprojects": {"optional_section": True}, # fb-only "sandcastle": {"optional_section": True, "fields": {"run_tests": OPTIONAL}}, + "setup-py.test": {"optional_section": True, "fields": {"python_script": REQUIRED}}, } # These sections are allowed to vary for different platforms @@ -684,6 +686,18 @@ class ManifestParser(object): inst_dir, ) + if builder == "setup-py": + return SetupPyBuilder( + loader, + dep_manifests, + build_options, + ctx, + self, + src_dir, + build_dir, + inst_dir, + ) + if builder == "cargo": return self.create_cargo_builder( loader, diff --git a/build/fbcode_builder/manifests/cinderx-3.12mp b/build/fbcode_builder/manifests/cinderx-3.12mp new file mode 100644 index 000000000..a9348c6ae --- /dev/null +++ b/build/fbcode_builder/manifests/cinderx-3.12mp @@ -0,0 +1,24 @@ +[manifest] +name = cinderx-3.12mp +fbsource_path = fbcode/cinderx +shipit_project = facebookincubator/cinderx + +[git] +repo_url = https://github.com/facebookincubator/cinderx.git + +[build.os=linux] +builder = setup-py + +[build.not(os=linux)] +builder = nop + +[dependencies] +python-setuptools +meta-python-3.12 + +[shipit.pathmap] +fbcode/cinderx = cinderx +fbcode/cinderx/oss_toplevel = . + +[setup-py.test] +python_script = cinderx/PythonLib/test_cinderx/test_oss_quick.py