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 _CheckAllFilesListed(resource_files, resource_dirs):
  resource_files = set(resource_files)
  missing_files = []
  for path, _ in resource_utils.IterResourceFilesInDirectories(resource_dirs):
    if path not in resource_files:
      missing_files.append(path)

  if missing_files:
    sys.stderr.write('Error: Found files not listed in the sources list of '
                     'the BUILD.gn target:\n')
    for path in missing_files:
      sys.stderr.write('{}\n'.format(path))
    sys.exit(1)
Exemple #3
0
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)
def _ZipResources(resource_dirs, zip_path, ignore_pattern):
    # 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 = []
    path_info = resource_utils.ResourceInfoFile()
    for index, resource_dir in enumerate(resource_dirs):
        attributed_aar = None
        if not resource_dir.startswith('..'):
            aar_source_info_path = os.path.join(os.path.dirname(resource_dir),
                                                'source.info')
            if os.path.exists(aar_source_info_path):
                attributed_aar = jar_info_utils.ReadAarSourceInfo(
                    aar_source_info_path)

        for path, archive_path in resource_utils.IterResourceFilesInDirectories(
            [resource_dir], ignore_pattern):
            attributed_path = path
            if attributed_aar:
                attributed_path = os.path.join(attributed_aar, 'res',
                                               path[len(resource_dir) + 1:])
            # Use the non-prefixed archive_path in the .info file.
            path_info.AddMapping(archive_path, attributed_path)

            resource_dir_name = os.path.basename(resource_dir)
            archive_path = '{}_{}/{}'.format(index, resource_dir_name,
                                             archive_path)
            files_to_zip.append((archive_path, path))

    path_info.Write(zip_path + '.info')

    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, z)