From 20c5bb797bea7d3b9e9b3969a16b721ba5beee3a Mon Sep 17 00:00:00 2001 From: David Greenberg Date: Thu, 7 Apr 2022 08:36:02 -0700 Subject: [PATCH] Add patchfile support to getdeps Summary: This adds the ability to specify a patch file to be applied on top of any library in getdeps. For example, zlib doesn't support static linking with CMake, but there's a small patch that can be applied to support static linking. This is the specific use case this diff is intended to support. Reviewed By: bigfootjon Differential Revision: D35410512 fbshipit-source-id: d1af0ddf9ec45ef28aa902c06735af86817ac194 --- build/fbcode_builder/getdeps/builder.py | 28 ++++++++++++++++++++++++ build/fbcode_builder/getdeps/manifest.py | 2 ++ 2 files changed, 30 insertions(+) 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}},