def ComputeAllPropertyFiles(input_file, needed_property_files): # Write the current metadata entry with placeholders. with zipfile.ZipFile(input_file, allowZip64=True) as input_zip: for property_files in needed_property_files: metadata.property_files[ property_files.name] = property_files.Compute(input_zip) namelist = input_zip.namelist() if METADATA_NAME in namelist or METADATA_PROTO_NAME in namelist: ZipDelete(input_file, [METADATA_NAME, METADATA_PROTO_NAME]) output_zip = zipfile.ZipFile(input_file, 'a', allowZip64=True) WriteMetadata(metadata, output_zip) ZipClose(output_zip) if OPTIONS.no_signing: return input_file prelim_signing = MakeTempFile(suffix='.zip') SignOutput(input_file, prelim_signing) return prelim_signing
def GetApexInfoFromTargetFiles(input_file, partition, compressed_only=True): """ Get information about system APEX stored in the input_file zip Args: input_file: The filename of the target build target-files zip or directory. Return: A list of ota_metadata_pb2.ApexInfo() populated using the APEX stored in /system partition of the input_file """ # Extract the apex files so that we can run checks on them if not isinstance(input_file, str): raise RuntimeError("must pass filepath to target-files zip or directory") apex_subdir = os.path.join(partition.upper(), 'apex') if os.path.isdir(input_file): tmp_dir = input_file else: tmp_dir = UnzipTemp(input_file, [os.path.join(apex_subdir, '*')]) target_dir = os.path.join(tmp_dir, apex_subdir) # Partial target-files packages for vendor-only builds may not contain # a system apex directory. if not os.path.exists(target_dir): logger.info('No APEX directory at path: %s', target_dir) return [] apex_infos = [] debugfs_path = "debugfs" if OPTIONS.search_path: debugfs_path = os.path.join(OPTIONS.search_path, "bin", "debugfs_static") deapexer = 'deapexer' if OPTIONS.search_path: deapexer_path = os.path.join(OPTIONS.search_path, "bin", "deapexer") if os.path.isfile(deapexer_path): deapexer = deapexer_path for apex_filename in os.listdir(target_dir): apex_filepath = os.path.join(target_dir, apex_filename) if not os.path.isfile(apex_filepath) or \ not zipfile.is_zipfile(apex_filepath): logger.info("Skipping %s because it's not a zipfile", apex_filepath) continue apex_info = ota_metadata_pb2.ApexInfo() # Open the apex file to retrieve information manifest = apex_manifest.fromApex(apex_filepath) apex_info.package_name = manifest.name apex_info.version = manifest.version # Check if the file is compressed or not apex_type = RunAndCheckOutput([ deapexer, "--debugfs_path", debugfs_path, 'info', '--print-type', apex_filepath]).rstrip() if apex_type == 'COMPRESSED': apex_info.is_compressed = True elif apex_type == 'UNCOMPRESSED': apex_info.is_compressed = False else: raise RuntimeError('Not an APEX file: ' + apex_type) # Decompress compressed APEX to determine its size if apex_info.is_compressed: decompressed_file_path = MakeTempFile(prefix="decompressed-", suffix=".apex") # Decompression target path should not exist os.remove(decompressed_file_path) RunAndCheckOutput([deapexer, 'decompress', '--input', apex_filepath, '--output', decompressed_file_path]) apex_info.decompressed_size = os.path.getsize(decompressed_file_path) if not compressed_only or apex_info.is_compressed: apex_infos.append(apex_info) return apex_infos