From b3fe69cac2d60e11f00385897c84f4689fbf9082 Mon Sep 17 00:00:00 2001 From: Taras Tsugrii Date: Mon, 25 Jun 2018 11:01:18 -0700 Subject: [PATCH] Fix external cell reference in OSS build. Reviewed By: hramos Differential Revision: D8615578 fbshipit-source-id: 22a0382956adc3c2cb0d25f756cd5fad11564559 --- ReactAndroid/src/main/jni/first-party/fb/BUCK | 3 +- ReactNative/DEFS.bzl | 81 +++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/jni/first-party/fb/BUCK b/ReactAndroid/src/main/jni/first-party/fb/BUCK index f5f74a41c..c25f868d7 100644 --- a/ReactAndroid/src/main/jni/first-party/fb/BUCK +++ b/ReactAndroid/src/main/jni/first-party/fb/BUCK @@ -1,5 +1,4 @@ -load("@xplat//tools/build_defs:glob_defs.bzl", "subdir_glob") -load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "JNI_TARGET", "cxx_library") +load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "JNI_TARGET", "cxx_library", "subdir_glob") # This target is only used in open source if IS_OSS_BUILD: diff --git a/ReactNative/DEFS.bzl b/ReactNative/DEFS.bzl index d7f28dfc1..711688eb4 100644 --- a/ReactNative/DEFS.bzl +++ b/ReactNative/DEFS.bzl @@ -179,3 +179,84 @@ def cxx_library(allow_jni_merging=None, **kwargs): if not (k.startswith("fbandroid_") or k.startswith("fbobjc_")) } native.cxx_library(**args) + +def _paths_join(path, *others): + """Joins one or more path components.""" + result = path + + for p in others: + if p.startswith("/"): # absolute + result = p + elif not result or result.endswith("/"): + result += p + else: + result += "/" + p + + return result + +def subdir_glob(glob_specs, exclude = None, prefix = ""): + """Returns a dict of sub-directory relative paths to full paths. + + The subdir_glob() function is useful for defining header maps for C/C++ + libraries which should be relative the given sub-directory. + Given a list of tuples, the form of (relative-sub-directory, glob-pattern), + it returns a dict of sub-directory relative paths to full paths. + + Please refer to native.glob() for explanations and examples of the pattern. + + Args: + glob_specs: The array of tuples in form of + (relative-sub-directory, glob-pattern inside relative-sub-directory). + type: List[Tuple[str, str]] + exclude: A list of patterns to identify files that should be removed + from the set specified by the first argument. Defaults to []. + type: Optional[List[str]] + prefix: If is not None, prepends it to each key in the dictionary. + Defaults to None. + type: Optional[str] + + Returns: + A dict of sub-directory relative paths to full paths. + """ + if exclude == None: + exclude = [] + + results = [] + + for dirpath, glob_pattern in glob_specs: + results.append( + _single_subdir_glob(dirpath, glob_pattern, exclude, prefix), + ) + + return _merge_maps(*results) + +def _merge_maps(*file_maps): + result = {} + for file_map in file_maps: + for key in file_map: + if key in result and result[key] != file_map[key]: + fail( + "Conflicting files in file search paths. " + + "\"%s\" maps to both \"%s\" and \"%s\"." % + (key, result[key], file_map[key]), + ) + + result[key] = file_map[key] + + return result + +def _single_subdir_glob(dirpath, glob_pattern, exclude = None, prefix = None): + if exclude == None: + exclude = [] + results = {} + files = native.glob([_paths_join(dirpath, glob_pattern)], exclude = exclude) + for f in files: + if dirpath: + key = f[len(dirpath) + 1:] + else: + key = f + if prefix: + key = _paths_join(prefix, key) + results[key] = f + + return results