tools/binary_size/libsupersize/archive.py
def CreateMetadata(args, linker_name, build_config):
  """Creates metadata dict while updating |build_config|.

  Args:
    args: Resolved command-line args.
    linker_name: A coded linker name (see linker_map_parser.py).
    build_config: Common build configurations to update or to undergo
        consistency checks.

  Returns:
    A dict of models.METADATA_* -> values. Performs "best effort" extraction
    using available data.
  """
  logging.debug('Constructing metadata')

  def update_build_config(key, value):
    if key in build_config:
      old_value = build_config[key]
      if value != old_value:
        raise ValueError('Inconsistent {}: {} (was {})'.format(
            key, value, old_value))
    else:
      build_config[key] = value

  metadata = {}

  # Ensure all paths are relative to output directory to make them hermetic.
  if args.output_directory:
    shorten_path = lambda path: os.path.relpath(path, args.output_directory)
    gn_args = _ParseGnArgs(os.path.join(args.output_directory, 'args.gn'))
    update_build_config(models.BUILD_CONFIG_GN_ARGS, gn_args)
  else:
    # If output directory is unavailable, just store basenames.
    shorten_path = os.path.basename

  if args.tool_prefix:
    relative_tool_prefix = path_util.ToToolsSrcRootRelative(args.tool_prefix)
    update_build_config(models.BUILD_CONFIG_TOOL_PREFIX, relative_tool_prefix)

  if linker_name:
    update_build_config(models.BUILD_CONFIG_LINKER_NAME, linker_name)

  # Deduce GIT revision (cached via @lru_cache).
  git_rev = _DetectGitRevision(args.source_directory)
  if git_rev:
    update_build_config(models.BUILD_CONFIG_GIT_REVISION, git_rev)

  if args.elf_file:
    metadata[models.METADATA_ELF_FILENAME] = shorten_path(args.elf_file)
    architecture = readelf.ArchFromElf(args.elf_file, args.tool_prefix)
    metadata[models.METADATA_ELF_ARCHITECTURE] = architecture
    timestamp_obj = datetime.datetime.utcfromtimestamp(
        os.path.getmtime(args.elf_file))
    timestamp = calendar.timegm(timestamp_obj.timetuple())
    metadata[models.METADATA_ELF_MTIME] = timestamp
    build_id = readelf.BuildIdFromElf(args.elf_file, args.tool_prefix)
    metadata[models.METADATA_ELF_BUILD_ID] = build_id
    relocations_count = _CountRelocationsFromElf(args.elf_file,
                                                 args.tool_prefix)
    metadata[models.METADATA_ELF_RELOCATIONS_COUNT] = relocations_count

  if args.map_file:
    metadata[models.METADATA_MAP_FILENAME] = shorten_path(args.map_file)

  if args.minimal_apks_file:
    metadata[models.METADATA_APK_FILENAME] = shorten_path(
        args.minimal_apks_file)
    if args.split_name and args.split_name != 'base':
      metadata[models.METADATA_APK_SIZE] = os.path.getsize(args.apk_file)
      metadata[models.METADATA_APK_SPLIT_NAME] = args.split_name
    else:
      sizes_by_module = _CollectModuleSizes(args.minimal_apks_file)
      for name, size in sizes_by_module.items():
        key = models.METADATA_APK_SIZE
        if name != 'base':
          key += '-' + name
        metadata[key] = size
  elif args.apk_file:
    metadata[models.METADATA_APK_FILENAME] = shorten_path(args.apk_file)
    metadata[models.METADATA_APK_SIZE] = os.path.getsize(args.apk_file)

  return metadata
Creates metadata dict while updating |build_config|.

  Args:
    args: Resolved command-line args.
    linker_name: A coded linker name (see linker_map_parser.py).
    build_config: Common build configurations to update or to undergo
        consistency checks.

  Returns:
    A dict of models.METADATA_* -> values. Performs "best effort" extraction
    using available data.
  
Creates metadata dict while updating |build_config|.
Creates metadata dict while updating |build_config| .
def CreateMetadata(args, linker_name, build_config):
  logging.debug('Constructing metadata')
  def update_build_config(key, value):
    if key in build_config:
      old_value = build_config[key]
      if value != old_value:
        raise ValueError('Inconsistent {}: {} (was {})'.format(
            key, value, old_value))
    else:
      build_config[key] = value
  metadata = {}
  if args.output_directory:
    shorten_path = lambda path: os.path.relpath(path, args.output_directory)
    gn_args = _ParseGnArgs(os.path.join(args.output_directory, 'args.gn'))
    update_build_config(models.BUILD_CONFIG_GN_ARGS, gn_args)
  else:
    shorten_path = os.path.basename
  if args.tool_prefix:
    relative_tool_prefix = path_util.ToToolsSrcRootRelative(args.tool_prefix)
    update_build_config(models.BUILD_CONFIG_TOOL_PREFIX, relative_tool_prefix)
  if linker_name:
    update_build_config(models.BUILD_CONFIG_LINKER_NAME, linker_name)
  git_rev = _DetectGitRevision(args.source_directory)
  if git_rev:
    update_build_config(models.BUILD_CONFIG_GIT_REVISION, git_rev)
  if args.elf_file:
    metadata[models.METADATA_ELF_FILENAME] = shorten_path(args.elf_file)
    architecture = readelf.ArchFromElf(args.elf_file, args.tool_prefix)
    metadata[models.METADATA_ELF_ARCHITECTURE] = architecture
    timestamp_obj = datetime.datetime.utcfromtimestamp(
        os.path.getmtime(args.elf_file))
    timestamp = calendar.timegm(timestamp_obj.timetuple())
    metadata[models.METADATA_ELF_MTIME] = timestamp
    build_id = readelf.BuildIdFromElf(args.elf_file, args.tool_prefix)
    metadata[models.METADATA_ELF_BUILD_ID] = build_id
    relocations_count = _CountRelocationsFromElf(args.elf_file,
                                                 args.tool_prefix)
    metadata[models.METADATA_ELF_RELOCATIONS_COUNT] = relocations_count
  if args.map_file:
    metadata[models.METADATA_MAP_FILENAME] = shorten_path(args.map_file)
  if args.minimal_apks_file:
    metadata[models.METADATA_APK_FILENAME] = shorten_path(
        args.minimal_apks_file)
    if args.split_name and args.split_name != 'base':
      metadata[models.METADATA_APK_SIZE] = os.path.getsize(args.apk_file)
      metadata[models.METADATA_APK_SPLIT_NAME] = args.split_name
    else:
      sizes_by_module = _CollectModuleSizes(args.minimal_apks_file)
      for name, size in sizes_by_module.items():
        key = models.METADATA_APK_SIZE
        if name != 'base':
          key += '-' + name
        metadata[key] = size
  elif args.apk_file:
    metadata[models.METADATA_APK_FILENAME] = shorten_path(args.apk_file)
    metadata[models.METADATA_APK_SIZE] = os.path.getsize(args.apk_file)
  return metadata
def CreateMetadata ( args , linker_name , build_config ) : logging . debug ( 'Constructing metadata' ) def update_build_config ( key , value ) : if key in build_config : old_value = build_config [ key ] if value != old_value : raise ValueError ( 'Inconsistent {}: {} (was {})' . format ( key , value , old_value ) ) else : build_config [ key ] = value metadata = { } if args . output_directory : shorten_path = lambda path : os . path . relpath ( path , args . output_directory ) gn_args = _ParseGnArgs ( os . path . join ( args . output_directory , 'args.gn' ) ) update_build_config ( models . BUILD_CONFIG_GN_ARGS , gn_args ) else : shorten_path = os . path . basename if args . tool_prefix : relative_tool_prefix = path_util . ToToolsSrcRootRelative ( args . tool_prefix ) update_build_config ( models . BUILD_CONFIG_TOOL_PREFIX , relative_tool_prefix ) if linker_name : update_build_config ( models . BUILD_CONFIG_LINKER_NAME , linker_name ) git_rev = _DetectGitRevision ( args . source_directory ) if git_rev : update_build_config ( models . BUILD_CONFIG_GIT_REVISION , git_rev ) if args . elf_file : metadata [ models . METADATA_ELF_FILENAME ] = shorten_path ( args . elf_file ) architecture = readelf . ArchFromElf ( args . elf_file , args . tool_prefix ) metadata [ models . METADATA_ELF_ARCHITECTURE ] = architecture timestamp_obj = datetime . datetime . utcfromtimestamp ( os . path . getmtime ( args . elf_file ) ) timestamp = calendar . timegm ( timestamp_obj . timetuple ( ) ) metadata [ models . METADATA_ELF_MTIME ] = timestamp build_id = readelf . BuildIdFromElf ( args . elf_file , args . tool_prefix ) metadata [ models . METADATA_ELF_BUILD_ID ] = build_id relocations_count = _CountRelocationsFromElf ( args . elf_file , args . tool_prefix ) metadata [ models . METADATA_ELF_RELOCATIONS_COUNT ] = relocations_count if args . map_file : metadata [ models . METADATA_MAP_FILENAME ] = shorten_path ( args . map_file ) if args . minimal_apks_file : metadata [ models . METADATA_APK_FILENAME ] = shorten_path ( args . minimal_apks_file ) if args . split_name and args . split_name != 'base' : metadata [ models . METADATA_APK_SIZE ] = os . path . getsize ( args . apk_file ) metadata [ models . METADATA_APK_SPLIT_NAME ] = args . split_name else : sizes_by_module = _CollectModuleSizes ( args . minimal_apks_file ) for name , size in sizes_by_module . items ( ) : key = models . METADATA_APK_SIZE if name != 'base' : key += '-' + name metadata [ key ] = size elif args . apk_file : metadata [ models . METADATA_APK_FILENAME ] = shorten_path ( args . apk_file ) metadata [ models . METADATA_APK_SIZE ] = os . path . getsize ( args . apk_file ) return metadata
Creates metadata dict while updating |build_config|.
Creates metadata dict while updating |build_config| .
"""Creates metadata dict while updating |build_config|.

  Args:
    args: Resolved command-line args.
    linker_name: A coded linker name (see linker_map_parser.py).
    build_config: Common build configurations to update or to undergo
        consistency checks.

  Returns:
    A dict of models.METADATA_* -> values. Performs "best effort" extraction
    using available data.
  """ # Ensure all paths are relative to output directory to make them hermetic. # If output directory is unavailable, just store basenames. # Deduce GIT revision (cached via @lru_cache).
A dict of models.METADATA_* -> values. Performs "best effort" extraction
using available data.
A dict of models . METADATA_ * - > values . Performs " best effort " extraction using available data .
args
Resolved command-line args.
Resolved command - line args .
linker_name
A coded linker name .
A coded linker name .
build_config
Common build configurations to update or to undergo
consistency checks.
Common build configurations to update or to undergo consistency checks .