Merge "releasetools: Keep the original RangeSet for 'uses_shared_blocks' case."

am: 70edcab678

Change-Id: I58d4bc2fb3b18dd8bc41b7f46a1e4c63672f0385
This commit is contained in:
Tao Bao
2018-12-06 15:41:26 -08:00
committed by android-build-merger
3 changed files with 28 additions and 15 deletions

View File

@@ -827,10 +827,10 @@ def GetSparseImage(which, tmpdir, input_zip, allow_shared_blocks,
ranges = image.file_map[entry] ranges = image.file_map[entry]
# If a RangeSet has been tagged as using shared blocks while loading the # If a RangeSet has been tagged as using shared blocks while loading the
# image, its block list must be already incomplete due to that reason. Don't # image, check the original block list to determine its completeness. Note
# give it 'incomplete' tag to avoid messing up the imgdiff stats. # that the 'incomplete' flag would be tagged to the original RangeSet only.
if ranges.extra.get('uses_shared_blocks'): if ranges.extra.get('uses_shared_blocks'):
continue ranges = ranges.extra['uses_shared_blocks']
if RoundUpTo4K(info.file_size) > ranges.size() * 4096: if RoundUpTo4K(info.file_size) > ranges.size() * 4096:
ranges.extra['incomplete'] = True ranges.extra['incomplete'] = True

View File

@@ -248,15 +248,21 @@ class SparseImage(object):
ranges = rangelib.RangeSet.parse(ranges) ranges = rangelib.RangeSet.parse(ranges)
if allow_shared_blocks: if allow_shared_blocks:
# Find the shared blocks that have been claimed by others. # Find the shared blocks that have been claimed by others. If so, tag
# the entry so that we can skip applying imgdiff on this file.
shared_blocks = ranges.subtract(remaining) shared_blocks = ranges.subtract(remaining)
if shared_blocks: if shared_blocks:
ranges = ranges.subtract(shared_blocks) non_shared = ranges.subtract(shared_blocks)
if not ranges: if not non_shared:
continue continue
# Tag the entry so that we can skip applying imgdiff on this file. # There shouldn't anything in the extra dict yet.
ranges.extra['uses_shared_blocks'] = True assert not ranges.extra, "Non-empty RangeSet.extra"
# Put the non-shared RangeSet as the value in the block map, which
# has a copy of the original RangeSet.
non_shared.extra['uses_shared_blocks'] = ranges
ranges = non_shared
out[fn] = ranges out[fn] = ranges
assert ranges.size() == ranges.intersect(remaining).size() assert ranges.size() == ranges.intersect(remaining).size()

View File

@@ -89,13 +89,20 @@ def ValidateFileConsistency(input_zip, input_tmp, info_dict):
logging.warning('Skipping %s that has incomplete block list', entry) logging.warning('Skipping %s that has incomplete block list', entry)
continue continue
# Use the original RangeSet if applicable, which includes the shared
# blocks. And this needs to happen before checking the monotonicity flag.
if ranges.extra.get('uses_shared_blocks'):
file_ranges = ranges.extra['uses_shared_blocks']
else:
file_ranges = ranges
# TODO(b/79951650): Handle files with non-monotonic ranges. # TODO(b/79951650): Handle files with non-monotonic ranges.
if not ranges.monotonic: if not file_ranges.monotonic:
logging.warning( logging.warning(
'Skipping %s that has non-monotonic ranges: %s', entry, ranges) 'Skipping %s that has non-monotonic ranges: %s', entry, file_ranges)
continue continue
blocks_sha1 = image.RangeSha1(ranges) blocks_sha1 = image.RangeSha1(file_ranges)
# The filename under unpacked directory, such as SYSTEM/bin/sh. # The filename under unpacked directory, such as SYSTEM/bin/sh.
unpacked_name = os.path.join( unpacked_name = os.path.join(
@@ -104,7 +111,7 @@ def ValidateFileConsistency(input_zip, input_tmp, info_dict):
file_sha1 = unpacked_file.sha1 file_sha1 = unpacked_file.sha1
assert blocks_sha1 == file_sha1, \ assert blocks_sha1 == file_sha1, \
'file: %s, range: %s, blocks_sha1: %s, file_sha1: %s' % ( 'file: %s, range: %s, blocks_sha1: %s, file_sha1: %s' % (
entry, ranges, blocks_sha1, file_sha1) entry, file_ranges, blocks_sha1, file_sha1)
logging.info('Validating file consistency.') logging.info('Validating file consistency.')
@@ -311,9 +318,9 @@ def ValidateVerifiedBootImages(input_tmp, info_dict, options):
if info_dict.get("avb_enable") == "true": if info_dict.get("avb_enable") == "true":
logging.info('Verifying Verified Boot 2.0 (AVB) images...') logging.info('Verifying Verified Boot 2.0 (AVB) images...')
# Temporarily disable the verification for AVB-signed images, due to the # TODO(b/120517892): Temporarily disable the verification for AVB-signed
# dependency on PyCrypto in `avbtool verify_image` (Bug: 119624011). # images. Needing supporting changes in caller to pass in the desired keys.
logging.info('Temporarily disabled due to b/119624011') logging.info('Temporarily disabled due to b/120517892')
def main(): def main():