def _ZipResources(resource_dirs, zip_path, ignore_pattern): # Python zipfile does not provide a way to replace a file (it just writes # another file with the same name). So, first collect all the files to put # in the zip (with proper overriding), and then zip them. # ignore_pattern is a string of ':' delimited list of globs used to ignore # files that should not be part of the final resource zip. files_to_zip = dict() files_to_zip_without_generated = dict() globs = _GenerateGlobs(ignore_pattern) for d in resource_dirs: for root, _, files in os.walk(d): for f in files: archive_path = f parent_dir = os.path.relpath(root, d) if parent_dir != '.': archive_path = os.path.join(parent_dir, f) path = os.path.join(root, f) if build_utils.MatchesGlob(archive_path, globs): continue # We want the original resource dirs in the .info file rather than the # generated overridden path. if not path.startswith('/tmp'): files_to_zip_without_generated[archive_path] = path files_to_zip[archive_path] = path resource_utils.CreateResourceInfoFile(files_to_zip_without_generated, zip_path) build_utils.DoZip(files_to_zip.iteritems(), zip_path)
def _ZipResources(resource_dirs, zip_path, ignore_pattern): # Python zipfile does not provide a way to replace a file (it just writes # another file with the same name). So, first collect all the files to put # in the zip (with proper overriding), and then zip them. # ignore_pattern is a string of ':' delimited list of globs used to ignore # files that should not be part of the final resource zip. files_to_zip = dict() files_to_zip_without_generated = dict() for index, resource_dir in enumerate(resource_dirs): for path, archive_path in resource_utils.IterResourceFilesInDirectories( [resource_dir], ignore_pattern): resource_dir_name = os.path.basename(resource_dir) archive_path = '{}_{}/{}'.format(index, resource_dir_name, archive_path) # We want the original resource dirs in the .info file rather than the # generated overridden path. if not path.startswith('/tmp'): files_to_zip_without_generated[archive_path] = path files_to_zip[archive_path] = path resource_utils.CreateResourceInfoFile(files_to_zip_without_generated, zip_path) with zipfile.ZipFile(zip_path, 'w') as z: # This magic comment signals to resource_utils.ExtractDeps that this zip is # not just the contents of a single res dir, without the encapsulating res/ # (like the outputs of android_generated_resources targets), but instead has # the contents of possibly multiple res/ dirs each within an encapsulating # directory within the zip. z.comment = resource_utils.MULTIPLE_RES_MAGIC_STRING build_utils.DoZip(files_to_zip.iteritems(), z)
def _ProcessFiles(processor, input_filenames, inputs_base_dir, outputs_zip): with build_utils.TempDir() as temp_dir: files_to_zip = dict() for input_filename in input_filenames: relpath = os.path.relpath(os.path.abspath(input_filename), os.path.abspath(inputs_base_dir)) if relpath.startswith(os.pardir): raise Exception('input file %s is not contained in inputs base dir %s' % (input_filename, inputs_base_dir)) output_filename = os.path.join(temp_dir, relpath) parent_dir = os.path.dirname(output_filename) build_utils.MakeDirectory(parent_dir) _ProcessFile(processor, input_filename, output_filename) files_to_zip[relpath] = input_filename resource_utils.CreateResourceInfoFile(files_to_zip, outputs_zip) build_utils.ZipDir(outputs_zip, temp_dir)
def _ZipResources(resource_dirs, zip_path, ignore_pattern): # Python zipfile does not provide a way to replace a file (it just writes # another file with the same name). So, first collect all the files to put # in the zip (with proper overriding), and then zip them. # ignore_pattern is a string of ':' delimited list of globs used to ignore # files that should not be part of the final resource zip. files_to_zip = dict() files_to_zip_without_generated = dict() for path, archive_path in resource_utils.IterResourceFilesInDirectories( resource_dirs, ignore_pattern): # We want the original resource dirs in the .info file rather than the # generated overridden path. if not path.startswith('/tmp'): files_to_zip_without_generated[archive_path] = path files_to_zip[archive_path] = path resource_utils.CreateResourceInfoFile(files_to_zip_without_generated, zip_path) build_utils.DoZip(files_to_zip.iteritems(), zip_path)