diff --git a/build/fbcode_builder/getdeps/builder.py b/build/fbcode_builder/getdeps/builder.py index c05686215..6bb6af7b8 100644 --- a/build/fbcode_builder/getdeps/builder.py +++ b/build/fbcode_builder/getdeps/builder.py @@ -7,6 +7,7 @@ import glob import json import os +import pathlib import shutil import stat import subprocess @@ -38,6 +39,8 @@ class BuilderBase(object): if subdir: src_dir = os.path.join(src_dir, subdir) + self.patchfile = manifest.get("build", "patchfile", ctx=ctx) + self.patchfile_opts = manifest.get("build", "patchfile_opts", ctx=ctx) or "" self.ctx = ctx self.src_dir = src_dir self.build_dir = build_dir or src_dir @@ -93,14 +96,39 @@ class BuilderBase(object): reconfigure = True return reconfigure + def _apply_patchfile(self) -> None: + # Only implemented patch support for linux + if not self.build_opts.is_linux() or self.patchfile is None: + return + patched_sentinel_file = pathlib.Path(self.src_dir + "/.getdeps_patched") + if patched_sentinel_file.exists(): + return + old_wd = os.getcwd() + os.chdir(self.src_dir) + print(f"Patching {self.manifest.name} with {self.patchfile} in {self.src_dir}") + retval = os.system( + "patch " + + self.patchfile_opts + + " < " + + self.build_opts.fbcode_builder_dir + + "/patches/" + + self.patchfile + ) + if retval != 0: + raise ValueError(f"Failed to apply patch to {self.manifest.name}") + os.chdir(old_wd) + patched_sentinel_file.touch() + def prepare(self, install_dirs, reconfigure: bool) -> None: print("Preparing %s..." % self.manifest.name) reconfigure = self._reconfigure(reconfigure) + self._apply_patchfile() self._prepare(install_dirs=install_dirs, reconfigure=reconfigure) def build(self, install_dirs, reconfigure: bool) -> None: print("Building %s..." % self.manifest.name) reconfigure = self._reconfigure(reconfigure) + self._apply_patchfile() self._prepare(install_dirs=install_dirs, reconfigure=reconfigure) self._build(install_dirs=install_dirs, reconfigure=reconfigure) diff --git a/build/fbcode_builder/getdeps/manifest.py b/build/fbcode_builder/getdeps/manifest.py index 830284307..0b4d2fc21 100644 --- a/build/fbcode_builder/getdeps/manifest.py +++ b/build/fbcode_builder/getdeps/manifest.py @@ -65,6 +65,8 @@ SCHEMA = { "make_binary": OPTIONAL, "build_in_src_dir": OPTIONAL, "job_weight_mib": OPTIONAL, + "patchfile": OPTIONAL, + "patchfile_opts": OPTIONAL, }, }, "msbuild": {"optional_section": True, "fields": {"project": REQUIRED}},