From 7edc62ad85ef0bedfe700e6aed5e3dd5d8bbee84 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 3 May 2019 15:52:39 -0700 Subject: [PATCH] fbcode_builder: getdeps: add NopBuilder Summary: this could do with a better name; the NopBuilder doesn't actually build anything, but instead copies some files to the destination location. This is used together with eg: cmake to install pre-built binaries downloaded from a tarball. Reviewed By: simpkins Differential Revision: D14691015 fbshipit-source-id: a938e977aa4ec5a664bdb8085ff708319a204594 --- build/fbcode_builder/getdeps/builder.py | 43 ++++++++++++++++++++++++ build/fbcode_builder/getdeps/manifest.py | 4 +++ 2 files changed, 47 insertions(+) diff --git a/build/fbcode_builder/getdeps/builder.py b/build/fbcode_builder/getdeps/builder.py index 17c34a4f8..bf7c18cfc 100644 --- a/build/fbcode_builder/getdeps/builder.py +++ b/build/fbcode_builder/getdeps/builder.py @@ -11,6 +11,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera import glob import os import shutil +import stat import sys from .envfuncs import Env, add_path_entry, path_search @@ -335,3 +336,45 @@ class Boost(BuilderBase): ], cwd=self.src_dir, ) + + +class NopBuilder(BuilderBase): + def __init__(self, build_opts, ctx, manifest, src_dir, inst_dir): + super(NopBuilder, self).__init__( + build_opts, ctx, manifest, src_dir, None, inst_dir + ) + + def build(self, install_dirs, reconfigure): + print("Installing %s -> %s" % (self.src_dir, self.inst_dir)) + parent = os.path.dirname(self.inst_dir) + if not os.path.exists(parent): + os.makedirs(parent) + + install_files = self.manifest.get_section_as_ordered_pairs( + "install.files", self.ctx + ) + if install_files: + for src_name, dest_name in self.manifest.get_section_as_ordered_pairs( + "install.files", self.ctx + ): + full_dest = os.path.join(self.inst_dir, dest_name) + full_src = os.path.join(self.src_dir, src_name) + + dest_parent = os.path.dirname(full_dest) + if not os.path.exists(dest_parent): + os.makedirs(dest_parent) + if os.path.isdir(full_src): + if not os.path.exists(full_dest): + shutil.copytree(full_src, full_dest) + else: + shutil.copyfile(full_src, full_dest) + shutil.copymode(full_src, full_dest) + # This is a bit gross, but the mac ninja.zip doesn't + # give ninja execute permissions, so force them on + # for things that look like they live in a bin dir + if os.path.dirname(dest_name) == "bin": + st = os.lstat(full_dest) + os.chmod(full_dest, st.st_mode | stat.S_IXUSR) + else: + if not os.path.exists(self.inst_dir): + shutil.copytree(self.src_dir, self.inst_dir) diff --git a/build/fbcode_builder/getdeps/manifest.py b/build/fbcode_builder/getdeps/manifest.py index 68b08a8c2..494dee253 100644 --- a/build/fbcode_builder/getdeps/manifest.py +++ b/build/fbcode_builder/getdeps/manifest.py @@ -16,6 +16,7 @@ from .builder import ( CMakeBuilder, MakeBuilder, NinjaBootstrap, + NopBuilder, OpenSSLBuilder, ) from .expr import parse_expr @@ -333,6 +334,9 @@ class ManifestParser(object): build_options, ctx, self, build_dir, src_dir, inst_dir ) + if builder == "nop": + return NopBuilder(build_options, ctx, self, src_dir, inst_dir) + if builder == "openssl": return OpenSSLBuilder( build_options, ctx, self, build_dir, src_dir, inst_dir