releasetools: Refactor ota_from_target_files.py.
Factor out some common lines between generating incremental and full OTAs. Remove the outer while loop for cleaner logic. Change-Id: I0a4d44a4a59b488748222c2031bd63f67d45e0b5
This commit is contained in:
@@ -1618,8 +1618,14 @@ def main(argv):
|
|||||||
raise common.ExternalError(
|
raise common.ExternalError(
|
||||||
"--- target build has specified no recovery ---")
|
"--- target build has specified no recovery ---")
|
||||||
|
|
||||||
while True:
|
# Use the default key to sign the package if not specified with package_key.
|
||||||
|
if not OPTIONS.no_signing:
|
||||||
|
if OPTIONS.package_key is None:
|
||||||
|
OPTIONS.package_key = OPTIONS.info_dict.get(
|
||||||
|
"default_system_dev_certificate",
|
||||||
|
"build/target/product/security/testkey")
|
||||||
|
|
||||||
|
# Set up the output zip. Create a temporary zip file if signing is needed.
|
||||||
if OPTIONS.no_signing:
|
if OPTIONS.no_signing:
|
||||||
if os.path.exists(args[1]):
|
if os.path.exists(args[1]):
|
||||||
os.unlink(args[1])
|
os.unlink(args[1])
|
||||||
@@ -1635,15 +1641,12 @@ def main(argv):
|
|||||||
print "--- can't determine the cache partition size ---"
|
print "--- can't determine the cache partition size ---"
|
||||||
OPTIONS.cache_size = cache_size
|
OPTIONS.cache_size = cache_size
|
||||||
|
|
||||||
|
# Generate a full OTA.
|
||||||
if OPTIONS.incremental_source is None:
|
if OPTIONS.incremental_source is None:
|
||||||
WriteFullOTAPackage(input_zip, output_zip)
|
WriteFullOTAPackage(input_zip, output_zip)
|
||||||
if OPTIONS.package_key is None:
|
|
||||||
OPTIONS.package_key = OPTIONS.info_dict.get(
|
|
||||||
"default_system_dev_certificate",
|
|
||||||
"build/target/product/security/testkey")
|
|
||||||
common.ZipClose(output_zip)
|
|
||||||
break
|
|
||||||
|
|
||||||
|
# Generate an incremental OTA. It will fall back to generate a full OTA on
|
||||||
|
# failure unless no_fallback_to_full is specified.
|
||||||
else:
|
else:
|
||||||
print "unzipping source target-files..."
|
print "unzipping source target-files..."
|
||||||
OPTIONS.source_tmp, source_zip = common.UnzipTemp(
|
OPTIONS.source_tmp, source_zip = common.UnzipTemp(
|
||||||
@@ -1651,24 +1654,21 @@ def main(argv):
|
|||||||
OPTIONS.target_info_dict = OPTIONS.info_dict
|
OPTIONS.target_info_dict = OPTIONS.info_dict
|
||||||
OPTIONS.source_info_dict = common.LoadInfoDict(source_zip,
|
OPTIONS.source_info_dict = common.LoadInfoDict(source_zip,
|
||||||
OPTIONS.source_tmp)
|
OPTIONS.source_tmp)
|
||||||
if OPTIONS.package_key is None:
|
|
||||||
OPTIONS.package_key = OPTIONS.source_info_dict.get(
|
|
||||||
"default_system_dev_certificate",
|
|
||||||
"build/target/product/security/testkey")
|
|
||||||
if OPTIONS.verbose:
|
if OPTIONS.verbose:
|
||||||
print "--- source info ---"
|
print "--- source info ---"
|
||||||
common.DumpInfoDict(OPTIONS.source_info_dict)
|
common.DumpInfoDict(OPTIONS.source_info_dict)
|
||||||
try:
|
try:
|
||||||
WriteIncrementalOTAPackage(input_zip, source_zip, output_zip)
|
WriteIncrementalOTAPackage(input_zip, source_zip, output_zip)
|
||||||
common.ZipClose(output_zip)
|
|
||||||
break
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if not OPTIONS.fallback_to_full:
|
if not OPTIONS.fallback_to_full:
|
||||||
raise
|
raise
|
||||||
print "--- failed to build incremental; falling back to full ---"
|
print "--- failed to build incremental; falling back to full ---"
|
||||||
OPTIONS.incremental_source = None
|
OPTIONS.incremental_source = None
|
||||||
|
WriteFullOTAPackage(input_zip, output_zip)
|
||||||
|
|
||||||
common.ZipClose(output_zip)
|
common.ZipClose(output_zip)
|
||||||
|
|
||||||
|
# Sign the generated zip package unless no_signing is specified.
|
||||||
if not OPTIONS.no_signing:
|
if not OPTIONS.no_signing:
|
||||||
SignOutput(temp_zip_file.name, args[1])
|
SignOutput(temp_zip_file.name, args[1])
|
||||||
temp_zip_file.close()
|
temp_zip_file.close()
|
||||||
|
Reference in New Issue
Block a user