Skip to content

Commit b088b84

Browse files
committed
build: patch eager kernel android deps
1 parent 216990f commit b088b84

1 file changed

Lines changed: 50 additions & 18 deletions

File tree

scripts/patch_tfjava.py

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -345,32 +345,64 @@ def patch_build_sh(path: Path) -> None:
345345
346346
path = Path(os.environ["EAGER_BUILD_FILE"])
347347
text = path.read_text(encoding="utf-8")
348-
rule_name = 'name = "tensor_handle_data"'
349-
rule_start = text.find(rule_name)
350-
if rule_start == -1:
351-
raise SystemExit(f"tensor_handle_data rule not found in {path}")
352-
rule_end = text.find('\\n)\\n', rule_start)
353-
if rule_end == -1:
354-
raise SystemExit(f"tensor_handle_data rule end not found in {path}")
355-
rule_end += 3
356-
rule = text[rule_start:rule_end]
357-
old = ''' "//tensorflow:android": [
348+
349+
350+
def patch_rule(rule_name: str, old: str, new: str) -> None:
351+
global text
352+
marker = f'name = "{rule_name}"'
353+
rule_start = text.find(marker)
354+
if rule_start == -1:
355+
raise SystemExit(f"{rule_name} rule not found in {path}")
356+
rule_end = text.find('\\n)\\n', rule_start)
357+
if rule_end == -1:
358+
raise SystemExit(f"{rule_name} rule end not found in {path}")
359+
rule_end += 3
360+
rule = text[rule_start:rule_end]
361+
if old in rule:
362+
rule = rule.replace(old, new, 1)
363+
elif new not in rule:
364+
raise SystemExit(f"{rule_name} android deps not found in {path}")
365+
text = text[:rule_start] + rule + text[rule_end:]
366+
367+
368+
patch_rule(
369+
"tensor_handle_data",
370+
''' "//tensorflow:android": [
358371
"//tensorflow/core:android_tensorflow_lib_lite",
359-
],'''
360-
new = ''' "//tensorflow:android": [
372+
],''',
373+
''' "//tensorflow:android": [
361374
"@com_google_absl//absl/types:variant",
362375
"//tensorflow/core:framework",
363376
"//tensorflow/core:lib",
364377
"//tensorflow/core/profiler/lib:traceme",
365-
],'''
366-
if old in rule:
367-
rule = rule.replace(old, new, 1)
368-
elif new not in rule:
369-
raise SystemExit(f"tensor_handle_data android deps not found in {path}")
370-
text = text[:rule_start] + rule + text[rule_end:]
378+
],''',
379+
)
380+
381+
patch_rule(
382+
"kernel_and_device",
383+
''' "//tensorflow:android": [
384+
"//tensorflow/core:android_tensorflow_lib_lite",
385+
],''',
386+
''' "//tensorflow:android": [
387+
"//tensorflow/core:core_cpu_lib",
388+
"//tensorflow/core:framework",
389+
"//tensorflow/core:framework_internal",
390+
"//tensorflow/core:lib",
391+
"//tensorflow/core:lib_internal",
392+
"//tensorflow/core:protos_all_cc",
393+
"//tensorflow/core/profiler/lib:annotated_traceme",
394+
"//tensorflow/core/profiler/lib:traceme",
395+
],''',
396+
)
397+
371398
path.write_text(text, encoding="utf-8")
372399
PY
373400
401+
sed -n '/name = "tensor_handle_data"/,/^)/p' "$EAGER_BUILD_FILE"
402+
echo '---'
403+
sed -n '/name = "kernel_and_device"/,/^)/p' "$EAGER_BUILD_FILE"
404+
echo '---'
405+
374406
TENSOR_HANDLE_DATA_CC="$BAZEL_OUTPUT_BASE/external/org_tensorflow/tensorflow/core/common_runtime/eager/tensor_handle_data.cc"
375407
TENSOR_HANDLE_DATA_CC="$TENSOR_HANDLE_DATA_CC" python3 - <<'PY'
376408
import os

0 commit comments

Comments
 (0)