Consider search_path to locate avb_*_key_path files
avb_*_key_path are usually relative file paths. If these files cannot be
located from the current directory, try prepending OPTIONS.search_path.
Bug: 139836256
Test: python -m unittest test_common
Test: python -m unittest test_add_img_to_target_files
Change-Id: I020b257f458a1f5762691d0499feaf4027e37126
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 2401e46..8339cad 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -616,6 +616,10 @@
"""Append signing arguments for avbtool."""
# e.g., "--key path/to/signing_key --algorithm SHA256_RSA4096"
key_path = OPTIONS.info_dict.get("avb_" + partition + "_key_path")
+ if key_path and not os.path.exists(key_path) and OPTIONS.search_path:
+ new_key_path = os.path.join(OPTIONS.search_path, key_path)
+ if os.path.exists(new_key_path):
+ key_path = new_key_path
algorithm = OPTIONS.info_dict.get("avb_" + partition + "_algorithm")
if key_path and algorithm:
cmd.extend(["--key", key_path, "--algorithm", algorithm])
@@ -668,6 +672,10 @@
"""
if key is None:
key = info_dict["avb_" + partition + "_key_path"]
+ if key and not os.path.exists(key) and OPTIONS.search_path:
+ new_key_path = os.path.join(OPTIONS.search_path, key)
+ if os.path.exists(new_key_path):
+ key = new_key_path
pubkey_path = ExtractAvbPublicKey(info_dict["avb_avbtool"], key)
rollback_index_location = info_dict[
"avb_" + partition + "_rollback_index_location"]