Skip to content

Commit 525ecdf

Browse files
committed
build: tighten eager android dep patch check
1 parent 8b20384 commit 525ecdf

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

scripts/patch_tfjava.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def patch_build_sh(path: Path) -> None:
3636
new = """# Allows us to use ccache with Bazel on Mac, but Android needs Bazel's Android crosstool.\nif [[ \"${PLATFORM:-}\" != \"android-arm64\" ]]; then\n export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1\nfi\n\nexport BAZEL_VC=\"${VCINSTALLDIR:-}\"\nif [[ \"${PLATFORM:-}\" == \"android-arm64\" ]]; then\n export TF_ANDROID_COMPAT_LIB_DIR=\"$(pwd)/android-compat-libs\"\n mkdir -p \"${TF_ANDROID_COMPAT_LIB_DIR}\"\n printf 'INPUT(-lc)\\n' > \"${TF_ANDROID_COMPAT_LIB_DIR}/libpthread.so\"\n printf 'INPUT(-lc)\\n' > \"${TF_ANDROID_COMPAT_LIB_DIR}/librt.so\"\n # tfjava builds TensorFlow as an external Bazel repository, so TensorFlow's\n # own .bazelrc does not inject framework_shared_object=true for us.\n export BUILD_FLAGS=\"--config=android_arm64 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --define=framework_shared_object=true --copt=-DANDROID --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --cxxopt=-include --cxxopt=cstdint --host_cxxopt=-include --host_cxxopt=cstdint --copt=-Wno-error=array-parameter --host_copt=-Wno-error=array-parameter --copt=-Wno-error=array-bounds --host_copt=-Wno-error=array-bounds --linkopt=-L${TF_ANDROID_COMPAT_LIB_DIR} --linkopt=-llog\"\n export PYTHON_BIN_PATH=$(which python3)\nelif [[ -d $BAZEL_VC ]]; then\n # Work around compiler issues on Windows documented mainly in configure.py but also elsewhere\n export BUILD_FLAGS=\"--copt=//arch:AVX `#--copt=//arch:AVX2` --copt=-DWIN32_LEAN_AND_MEAN --host_copt=-DWIN32_LEAN_AND_MEAN --copt=-DNOGDI --host_copt=-DNOGDI --copt=-D_USE_MATH_DEFINES --host_copt=-D_USE_MATH_DEFINES --define=override_eigen_strong_inline=true\"\n # https://software.intel.com/en-us/articles/intel-optimization-for-tensorflow-installation-guide#wind_B_S\n export PATH=$PATH:$(pwd)/bazel-tensorflow-core-api/external/mkl_windows/lib/\n export PYTHON_BIN_PATH=$(which python.exe)\nelse\n export BUILD_FLAGS=\"--copt=-msse4.1 --copt=-msse4.2 --copt=-mavx `#--copt=-mavx2 --copt=-mfma` --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --linkopt=-lstdc++ --host_linkopt=-lstdc++\"\n export PYTHON_BIN_PATH=$(which python3)\nfi\n\nif [[ -n \"${BAZEL_REPOSITORY_CACHE:-}\" ]]; then\n export BUILD_FLAGS=\"$BUILD_FLAGS --repository_cache=${BAZEL_REPOSITORY_CACHE}\"\nfi\nif [[ -n \"${BAZEL_DISK_CACHE:-}\" ]]; then\n export BUILD_FLAGS=\"$BUILD_FLAGS --disk_cache=${BAZEL_DISK_CACHE}\"\nfi\n"""
3737
text = replace_once(text, old, new, path)
3838
old = """# Build C API of TensorFlow itself including a target to generate ops for Java\nbazel build $BUILD_FLAGS \\\n @org_tensorflow//tensorflow:tensorflow \\\n @org_tensorflow//tensorflow/tools/lib_package:jnilicenses_generate \\\n :java_proto_gen_sources \\\n :java_op_generator \\\n :java_api_import \\\n :custom_ops_test\n"""
39-
new = """# Build C API of TensorFlow itself. Android cross-builds reuse the checked-in\n# generated Java sources because the generator is a host tool that loads the\n# produced TensorFlow library at build time.\nBAZEL_TARGETS=(\n @org_tensorflow//tensorflow:tensorflow\n @org_tensorflow//tensorflow/tools/lib_package:jnilicenses_generate\n :custom_ops_test\n)\nif [[ \"${PLATFORM:-}\" != \"android-arm64\" ]]; then\n BAZEL_TARGETS+=(\n :java_proto_gen_sources\n :java_op_generator\n :java_api_import\n )\nelse\n bazel fetch \"${BAZEL_TARGETS[@]}\"\n BAZEL_OUTPUT_BASE=\"$(bazel info output_base)\"\n TF_C_BUILD_FILE=\"$BAZEL_OUTPUT_BASE/external/org_tensorflow/tensorflow/c/BUILD\"\n TF_C_BUILD_FILE=\"$TF_C_BUILD_FILE\" python3 - <<'PY'\nimport os\nfrom pathlib import Path\n\npath = Path(os.environ[\"TF_C_BUILD_FILE\"])\ntext = path.read_text(encoding=\"utf-8\")\nold = '''cc_library(\n name = \"tf_tensor\",\n srcs = [\"tf_tensor.cc\"],\n hdrs = [\"tf_tensor.h\"],\n visibility = [\"//visibility:public\"],\n deps = select({\n \"//tensorflow:android\": [\n \"//tensorflow/core:android_tensorflow_lib_lite\",\n ],\n \"//conditions:default\": [\n \":tf_datatype\",\n \":tf_status\",\n \":tf_status_helper\",\n \":tf_tensor_internal\",\n \"//tensorflow/core:framework\",\n \"//tensorflow/core:lib\",\n \"//tensorflow/core:protos_all_cc\",\n ],\n }),\n)'''\nnew = '''cc_library(\n name = \"tf_tensor\",\n srcs = [\"tf_tensor.cc\"],\n hdrs = [\n \"tf_tensor.h\",\n \"tf_datatype.h\",\n \"tf_status.h\",\n \"tf_status_helper.h\",\n \"tf_tensor_internal.h\",\n ],\n visibility = [\"//visibility:public\"],\n deps = select({\n \"//tensorflow:android\": [\n \":tf_datatype\",\n \":tf_status\",\n \":tf_status_helper\",\n \":tf_tensor_internal\",\n \"//tensorflow/core:framework\",\n \"//tensorflow/core:lib\",\n \"//tensorflow/core:protos_all_cc\",\n ],\n \"//conditions:default\": [\n \":tf_datatype\",\n \":tf_status\",\n \":tf_status_helper\",\n \":tf_tensor_internal\",\n \"//tensorflow/core:framework\",\n \"//tensorflow/core:lib\",\n \"//tensorflow/core:protos_all_cc\",\n ],\n }),\n)'''\nif old in text:\n text = text.replace(old, new, 1)\nelif '\"tf_status_helper.h\"' not in text:\n raise SystemExit(f\"tf_tensor rule not found in {path}\")\npath.write_text(text, encoding=\"utf-8\")\nPY\n EAGER_BUILD_FILE=\"$BAZEL_OUTPUT_BASE/external/org_tensorflow/tensorflow/core/common_runtime/eager/BUILD\"\n EAGER_BUILD_FILE=\"$EAGER_BUILD_FILE\" python3 - <<'PY'\nimport os\nfrom pathlib import Path\n\npath = Path(os.environ[\"EAGER_BUILD_FILE\"])\ntext = path.read_text(encoding=\"utf-8\")\nrule_name = 'name = \"tensor_handle_data\"'\nrule_start = text.find(rule_name)\nif rule_start == -1:\n raise SystemExit(f\"tensor_handle_data rule not found in {path}\")\nrule_end = text.find('\\n)\\n', rule_start)\nif rule_end == -1:\n raise SystemExit(f\"tensor_handle_data rule end not found in {path}\")\nrule_end += 3\nrule = text[rule_start:rule_end]\nold = ''' \"//tensorflow:android\": [\n \"//tensorflow/core:android_tensorflow_lib_lite\",\n ],'''\nnew = ''' \"//tensorflow:android\": [\n \"@com_google_absl//absl/types:variant\",\n \"//tensorflow/core:framework\",\n \"//tensorflow/core:lib\",\n \"//tensorflow/core/profiler/lib:traceme\",\n ],'''\nif old in rule:\n rule = rule.replace(old, new, 1)\nelif '\"//tensorflow/core/profiler/lib:traceme\"' not in rule:\n raise SystemExit(f\"tensor_handle_data android deps not found in {path}\")\ntext = text[:rule_start] + rule + text[rule_end:]\npath.write_text(text, encoding=\"utf-8\")\nPY\nfi\nbazel build $BUILD_FLAGS \"${BAZEL_TARGETS[@]}\"\n"""
39+
new = """# Build C API of TensorFlow itself. Android cross-builds reuse the checked-in\n# generated Java sources because the generator is a host tool that loads the\n# produced TensorFlow library at build time.\nBAZEL_TARGETS=(\n @org_tensorflow//tensorflow:tensorflow\n @org_tensorflow//tensorflow/tools/lib_package:jnilicenses_generate\n :custom_ops_test\n)\nif [[ \"${PLATFORM:-}\" != \"android-arm64\" ]]; then\n BAZEL_TARGETS+=(\n :java_proto_gen_sources\n :java_op_generator\n :java_api_import\n )\nelse\n bazel fetch \"${BAZEL_TARGETS[@]}\"\n BAZEL_OUTPUT_BASE=\"$(bazel info output_base)\"\n TF_C_BUILD_FILE=\"$BAZEL_OUTPUT_BASE/external/org_tensorflow/tensorflow/c/BUILD\"\n TF_C_BUILD_FILE=\"$TF_C_BUILD_FILE\" python3 - <<'PY'\nimport os\nfrom pathlib import Path\n\npath = Path(os.environ[\"TF_C_BUILD_FILE\"])\ntext = path.read_text(encoding=\"utf-8\")\nold = '''cc_library(\n name = \"tf_tensor\",\n srcs = [\"tf_tensor.cc\"],\n hdrs = [\"tf_tensor.h\"],\n visibility = [\"//visibility:public\"],\n deps = select({\n \"//tensorflow:android\": [\n \"//tensorflow/core:android_tensorflow_lib_lite\",\n ],\n \"//conditions:default\": [\n \":tf_datatype\",\n \":tf_status\",\n \":tf_status_helper\",\n \":tf_tensor_internal\",\n \"//tensorflow/core:framework\",\n \"//tensorflow/core:lib\",\n \"//tensorflow/core:protos_all_cc\",\n ],\n }),\n)'''\nnew = '''cc_library(\n name = \"tf_tensor\",\n srcs = [\"tf_tensor.cc\"],\n hdrs = [\n \"tf_tensor.h\",\n \"tf_datatype.h\",\n \"tf_status.h\",\n \"tf_status_helper.h\",\n \"tf_tensor_internal.h\",\n ],\n visibility = [\"//visibility:public\"],\n deps = select({\n \"//tensorflow:android\": [\n \":tf_datatype\",\n \":tf_status\",\n \":tf_status_helper\",\n \":tf_tensor_internal\",\n \"//tensorflow/core:framework\",\n \"//tensorflow/core:lib\",\n \"//tensorflow/core:protos_all_cc\",\n ],\n \"//conditions:default\": [\n \":tf_datatype\",\n \":tf_status\",\n \":tf_status_helper\",\n \":tf_tensor_internal\",\n \"//tensorflow/core:framework\",\n \"//tensorflow/core:lib\",\n \"//tensorflow/core:protos_all_cc\",\n ],\n }),\n)'''\nif old in text:\n text = text.replace(old, new, 1)\nelif '\"tf_status_helper.h\"' not in text:\n raise SystemExit(f\"tf_tensor rule not found in {path}\")\npath.write_text(text, encoding=\"utf-8\")\nPY\n EAGER_BUILD_FILE=\"$BAZEL_OUTPUT_BASE/external/org_tensorflow/tensorflow/core/common_runtime/eager/BUILD\"\n EAGER_BUILD_FILE=\"$EAGER_BUILD_FILE\" python3 - <<'PY'\nimport os\nfrom pathlib import Path\n\npath = Path(os.environ[\"EAGER_BUILD_FILE\"])\ntext = path.read_text(encoding=\"utf-8\")\nrule_name = 'name = \"tensor_handle_data\"'\nrule_start = text.find(rule_name)\nif rule_start == -1:\n raise SystemExit(f\"tensor_handle_data rule not found in {path}\")\nrule_end = text.find('\\n)\\n', rule_start)\nif rule_end == -1:\n raise SystemExit(f\"tensor_handle_data rule end not found in {path}\")\nrule_end += 3\nrule = text[rule_start:rule_end]\nold = ''' \"//tensorflow:android\": [\n \"//tensorflow/core:android_tensorflow_lib_lite\",\n ],'''\nnew = ''' \"//tensorflow:android\": [\n \"@com_google_absl//absl/types:variant\",\n \"//tensorflow/core:framework\",\n \"//tensorflow/core:lib\",\n \"//tensorflow/core/profiler/lib:traceme\",\n ],'''\nif old in rule:\n rule = rule.replace(old, new, 1)\nelif new not in rule:\n raise SystemExit(f\"tensor_handle_data android deps not found in {path}\")\ntext = text[:rule_start] + rule + text[rule_end:]\npath.write_text(text, encoding=\"utf-8\")\nPY\nfi\nbazel build $BUILD_FLAGS \"${BAZEL_TARGETS[@]}\"\n"""
4040
text = replace_once(text, old, new, path)
4141
old = """GEN_SRCS_DIR=src/gen/java\nmkdir -p $GEN_SRCS_DIR\n\n# Generate Java operator wrappers\n$BAZEL_BIN/java_op_generator \\\n --output_dir=$GEN_SRCS_DIR \\\n --api_dirs=$BAZEL_SRCS/external/org_tensorflow/tensorflow/core/api_def/base_api,src/bazel/api_def \\\n $TENSORFLOW_LIB\n\n# Copy generated Java protos from source jars\n"""
4242
new = """GEN_SRCS_DIR=src/gen/java\nmkdir -p $GEN_SRCS_DIR\n\nif [[ \"${PLATFORM:-}\" != \"android-arm64\" ]]; then\n # Generate Java operator wrappers\n $BAZEL_BIN/java_op_generator \\\n --output_dir=$GEN_SRCS_DIR \\\n --api_dirs=$BAZEL_SRCS/external/org_tensorflow/tensorflow/core/api_def/base_api,src/bazel/api_def \\\n $TENSORFLOW_LIB\nelse\n echo \"Skipping Java source generation for android-arm64; reusing checked-in generated sources.\"\nfi\n\n# Copy generated Java protos from source jars\n"""

0 commit comments

Comments
 (0)