Make fsverity_manifest_generator deterministic
Apparently python protobufs are not deterministic by default.
fsverity_manifest_generator generates artifacts that end up on the
device, so it's important for reproducible builds and build caching
that it's deterministic.
The python protobuf implementation has a method to configure it to
be deterministic by default globally, but that's more work, so start
with this for now.
Bug: 394404628
Test: Presubmits
Change-Id: Ie63237fa1279d6e4f068c9a34a6e1c0ff8d24cea
diff --git a/fsverity/fsverity_manifest_generator.py b/fsverity/fsverity_manifest_generator.py
index 1a2fba2..d232450 100644
--- a/fsverity/fsverity_manifest_generator.py
+++ b/fsverity/fsverity_manifest_generator.py
@@ -87,7 +87,9 @@
real_digest = digests.digests[real_rel]
link_digest.CopyFrom(real_digest)
- manifest = digests.SerializeToString()
+ # Serialize with deterministic=True for reproducible builds and build caching.
+ # The serialized contents will still change across different versions of protobuf.
+ manifest = digests.SerializeToString(deterministic=True)
with open(args.output, "wb") as f:
f.write(manifest)