From dc2b82a801fec3ba17350a4fc6ab60b2a24215e5 Mon Sep 17 00:00:00 2001 From: "Zeyi (Rice) Fan" Date: Mon, 6 Jun 2022 14:11:44 -0700 Subject: [PATCH] support patchfile on all platforms Summary: Adding patching support for all platforms using `git apply` Reviewed By: xavierd Differential Revision: D36939728 fbshipit-source-id: ccf6e4ccd30257c6928ba804a76882d4d2f71700 --- build/fbcode_builder/getdeps/builder.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/build/fbcode_builder/getdeps/builder.py b/build/fbcode_builder/getdeps/builder.py index 483a0513c..09fdeb193 100644 --- a/build/fbcode_builder/getdeps/builder.py +++ b/build/fbcode_builder/getdeps/builder.py @@ -102,8 +102,7 @@ class BuilderBase(object): 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: + if self.patchfile is None: return patched_sentinel_file = pathlib.Path(self.src_dir + "/.getdeps_patched") if patched_sentinel_file.exists(): @@ -111,15 +110,15 @@ class BuilderBase(object): 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 + patchfile = os.path.join( + self.build_opts.fbcode_builder_dir, "patches", self.patchfile ) - if retval != 0: + patchcmd = ["git", "apply"] + if self.patchfile_opts: + patchcmd.append(self.patchfile_opts) + try: + subprocess.check_call(patchcmd + [patchfile]) + except subprocess.CalledProcessError: raise ValueError(f"Failed to apply patch to {self.manifest.name}") os.chdir(old_wd) patched_sentinel_file.touch()