@@ -40,11 +40,22 @@ def patch_preset(path: Path) -> None:
4040
4141def patch_workspace (path : Path ) -> None :
4242 text = path .read_text (encoding = "utf-8" )
43- if "android_ndk_repository(" in text or "android_sdk_repository(" in text :
44- return
45- old = 'bazel_version_repository(name = "bazel_version")\n '
46- new = """bazel_version_repository(name = "bazel_version")\n \n android_sdk_repository(\n name = "androidsdk",\n api_level = 29,\n build_tools_version = "29.0.3",\n )\n \n android_ndk_repository(\n name = "androidndk",\n api_level = 21,\n )\n """
47- text = replace_once (text , old , new , path )
43+ if ':tensorflow-android-absl.patch",' not in text :
44+ old = ' ":tensorflow-proto.patch",\n '
45+ new = """ ":tensorflow-proto.patch",\n ":tensorflow-android-absl.patch",\n """
46+ text = replace_once (text , old , new , path )
47+ if "android_ndk_repository(" not in text and "android_sdk_repository(" not in text :
48+ old = 'bazel_version_repository(name = "bazel_version")\n '
49+ new = """bazel_version_repository(name = "bazel_version")\n \n android_sdk_repository(\n name = "androidsdk",\n api_level = 29,\n build_tools_version = "29.0.3",\n )\n \n android_ndk_repository(\n name = "androidndk",\n api_level = 21,\n )\n """
50+ text = replace_once (text , old , new , path )
51+ path .write_text (text , encoding = "utf-8" )
52+
53+
54+ def write_tensorflow_android_absl_patch (path : Path ) -> None :
55+ text = """diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl
56+ --- a/tensorflow/workspace.bzl
57+ +++ b/tensorflow/workspace.bzl
58+ @@ -186,7 +186,8 @@ def tf_workspace(path_prefix = \" \" , tf_repo_name = \" \" ):\n tf_http_archive(\n name = \" com_google_absl\" ,\n build_file = clean_dep(\" //third_party:com_google_absl.BUILD\" ),\n # TODO: Remove the patch when https://github.com/abseil/abseil-cpp/issues/326 is resolved\n # and when TensorFlow is build against CUDA 10.2\n - patch_file = clean_dep(\" //third_party:com_google_absl_fix_mac_and_nvcc_build.patch\" ),\n + patch_file = clean_dep(\" //third_party:com_google_absl_fix_mac_and_nvcc_build.patch\" ),\n + patch_cmds = [\" grep -q '^#include <limits>$' absl/synchronization/internal/graphcycles.cc || sed -i '/#include <algorithm>/a #include <limits>' absl/synchronization/internal/graphcycles.cc\" ],\n sha256 = \" acd93f6baaedc4414ebd08b33bebca7c7a46888916101d8c0b8083573526d070\" , # SHARED_ABSL_SHA\n strip_prefix = \" abseil-cpp-43ef2148c0936ebf7cb4be6b19927a9d9d145b8f\" ,\n urls = [\n """
4859 path .write_text (text , encoding = "utf-8" )
4960
5061
@@ -55,6 +66,9 @@ def main() -> None:
5566 patch_module_pom (root / "tensorflow-core" / "tensorflow-core-api" / "pom.xml" )
5667 patch_build_sh (root / "tensorflow-core" / "tensorflow-core-api" / "build.sh" )
5768 patch_workspace (root / "tensorflow-core" / "tensorflow-core-api" / "WORKSPACE" )
69+ write_tensorflow_android_absl_patch (
70+ root / "tensorflow-core" / "tensorflow-core-api" / "tensorflow-android-absl.patch"
71+ )
5872 patch_preset (
5973 root
6074 / "tensorflow-core"
0 commit comments