- 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"""
0 commit comments