Allow specifying relative paths in fsverity_manifest_generator
Right now, all files guarded by fsv_meta files have to be in a directory
with the same structure as they will have on-device. We'd like to
remove that restriction to make the build faster. Allow specifying
the on-device relative path for each input file to the fsverity manifest
manually, so that the script doesn't have to infer it from the file's
path on the host.
Bug: 394404628
Test: Manually
Change-Id: I5dd59cf2c224e2b3718b0fe4b495f37b0d17ff6d
diff --git a/fsverity/fsverity_manifest_generator.py b/fsverity/fsverity_manifest_generator.py
index 99e66c6..1a2fba2 100644
--- a/fsverity/fsverity_manifest_generator.py
+++ b/fsverity/fsverity_manifest_generator.py
@@ -31,7 +31,7 @@
cmd = [fsverity_path, 'digest', input_file]
cmd.extend(['--compact'])
cmd.extend(['--hash-alg', HASH_ALGORITHM])
- out = subprocess.check_output(cmd, universal_newlines=True).strip()
+ out = subprocess.check_output(cmd, text=True).strip()
return bytes(bytearray.fromhex(out))
if __name__ == '__main__':
@@ -46,19 +46,28 @@
required=True)
p.add_argument(
'--base-dir',
- help='directory to use as a relative root for the inputs',
- required=True)
+ help='directory to use as a relative root for the inputs. Also see the documentation of '
+ 'inputs')
p.add_argument(
'inputs',
nargs='*',
- help='input file for the build manifest')
+ help='input file for the build manifest. It can be in either of two forms: <file> or '
+ '<file>,<path_on_device>. If the first form is used, --base-dir must be provided, and the '
+ 'path on device will be the filepath relative to the base dir')
args = p.parse_args()
links = {}
digests = FSVerityDigests()
for f in sorted(args.inputs):
- # f is a full path for now; make it relative so it starts with {mount_point}/
- rel = os.path.relpath(f, args.base_dir)
+ if args.base_dir:
+ # f is a full path for now; make it relative so it starts with {mount_point}/
+ rel = os.path.relpath(f, args.base_dir)
+ else:
+ parts = f.split(',')
+ if len(parts) != 2 or not parts[0] or not parts[1]:
+ sys.exit("Since --base-path wasn't provided, all inputs must be pairs separated by commas "
+ "but this input wasn't: " + f)
+ f, rel = parts
# Some fsv_meta files are links to other ones. Don't read through the link, because the
# layout of files in the build system may not match the layout of files on the device.