aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2022-07-13 12:53:15 +0000
committerPaul Duffin <paulduffin@google.com>2022-07-18 13:31:31 +0000
commitf4042ebd8546b286956d747c66c772ce33eb5764 (patch)
tree06fd12c802022d0e92b5bff7367dcc25a70be69e
parent46d228aad25254ec2c15623a2f6eda583cf457c9 (diff)
downloadcommon-f4042ebd8546b286956d747c66c772ce33eb5764.tar.gz
Used fixed timestamps for the zip contents
Previously, while the snapshot zip files generated by Soong had entries with fixed timestamps the zip files produced by this script did not which meant that the contents of the zip files depended on when the zip file was created. That meant that in order to compare a change affected the zip file contents it was necessary to unpack the before and after zip files in order to compare them. This change causes all zip files created by the script to use the same fixed timestamp for each of its entries as soong_zip and ziptime do so it is now possible to check that the contents of sdk snapshot zip files are the same without unpacking them. Bug: 232401814 Test: BUILD_NUMBER=fixed packages/modules/common/build/mainline_modules_sdks.sh # Remove api diff files as they contain file stamps of generated files so # differ every time they are generated. find out/dist/mainline-sdks -name \*txt | xargs rm # Save the snapshots away. mv out/dist/mainline-sdks before-changes # Repeat the first two steps above and then run the following to verify # that simply running the script twice results in different sdk contents. meld before-changes out/dist/mainline-sdks # Apply this change and then run the above again but this time the sdks # will be identical. Change-Id: I28bf78783c827abffa6b715c62ca5948b3ee19b5
-rwxr-xr-xbuild/mainline_modules_sdks.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/build/mainline_modules_sdks.py b/build/mainline_modules_sdks.py
index cbc5e8f7..b1ff75a2 100755
--- a/build/mainline_modules_sdks.py
+++ b/build/mainline_modules_sdks.py
@@ -20,6 +20,7 @@ the APEXes in it are built, otherwise all configured SDKs are built.
"""
import argparse
import dataclasses
+import datetime
import functools
import io
import json
@@ -255,6 +256,22 @@ def sdk_snapshot_api_diff_file(snapshots_dir, sdk_name, sdk_version):
return os.path.join(snapshots_dir, f"{sdk_name}-{sdk_version}-api-diff.txt")
+# The default time to use in zip entries. Ideally, this should be the same as is
+# used by soong_zip and ziptime but there is no strict need for that to be the
+# case. What matters is this is a fixed time so that the contents of zip files
+# created by this script do not depend on when it is run, only the inputs.
+default_zip_time = datetime.datetime(2008, 1, 1, 0, 0, 0, 0,
+ datetime.timezone.utc)
+
+
+# set the timestamps of the paths to the default_zip_time.
+def set_default_timestamp(base_dir, paths):
+ for path in paths:
+ timestamp = default_zip_time.timestamp()
+ p = os.path.join(base_dir, path)
+ os.utime(p, (timestamp, timestamp))
+
+
@dataclasses.dataclass()
class SnapshotBuilder:
"""Builds sdk snapshots"""
@@ -409,6 +426,13 @@ java_sdk_library_import {{
dest_dir, "snapshot-creation-build-number.txt")
shutil.copy(build_number_file, snapshot_build_number_file)
+ # Make sure that all the paths being added to the zip file have a
+ # fixed timestamp so that the contents of the zip file do not depend
+ # on when this script is run, only the inputs.
+ for root, dirs, files in os.walk(dest_dir):
+ set_default_timestamp(root, dirs)
+ set_default_timestamp(root, files)
+
# Now zip up the files into a snapshot zip file.
base_file = os.path.join(r_snapshot_dir, sdk_name + "-current")
shutil.make_archive(base_file, "zip", dest_dir)
@@ -1201,6 +1225,12 @@ def copy_zip_and_replace(producer, src_zip_path, dest_zip_path, src_dir, paths):
# not affected by a change of directory.
abs_src_zip_path = os.path.abspath(src_zip_path)
abs_dest_zip_path = os.path.abspath(dest_zip_path)
+
+ # Make sure that all the paths being added to the zip file have a fixed
+ # timestamp so that the contents of the zip file do not depend on when this
+ # script is run, only the inputs.
+ set_default_timestamp(src_dir, paths)
+
producer.subprocess_runner.run(
["zip", "-q", abs_src_zip_path, "--out", abs_dest_zip_path] + paths,
# Change into the source directory before running zip.