예제 #1
0
def CreateMetadata(map_path, elf_path, apk_path, tool_prefix, output_directory):
  metadata = None
  if elf_path:
    logging.debug('Constructing metadata')
    git_rev = _DetectGitRevision(os.path.dirname(elf_path))
    architecture = _ArchFromElf(elf_path, tool_prefix)
    build_id = BuildIdFromElf(elf_path, tool_prefix)
    timestamp_obj = datetime.datetime.utcfromtimestamp(os.path.getmtime(
        elf_path))
    timestamp = calendar.timegm(timestamp_obj.timetuple())
    relative_tool_prefix = path_util.ToSrcRootRelative(tool_prefix)

    metadata = {
        models.METADATA_GIT_REVISION: git_rev,
        models.METADATA_ELF_ARCHITECTURE: architecture,
        models.METADATA_ELF_MTIME: timestamp,
        models.METADATA_ELF_BUILD_ID: build_id,
        models.METADATA_TOOL_PREFIX: relative_tool_prefix,
    }

    if output_directory:
      relative_to_out = lambda path: os.path.relpath(path, output_directory)
      gn_args = _ParseGnArgs(os.path.join(output_directory, 'args.gn'))
      metadata[models.METADATA_MAP_FILENAME] = relative_to_out(map_path)
      metadata[models.METADATA_ELF_FILENAME] = relative_to_out(elf_path)
      metadata[models.METADATA_GN_ARGS] = gn_args

      if apk_path:
        metadata[models.METADATA_APK_FILENAME] = relative_to_out(apk_path)
        metadata[models.METADATA_APK_SIZE] = os.path.getsize(apk_path)
  return metadata
예제 #2
0
def _ComputePakFileSymbols(
    file_name, file_size, contents, res_info, symbols_by_name):
  total = 12 + 6  # Header size plus extra offset
  id_map = {id(v): k
            for k, v in sorted(contents.resources.items(), reverse=True)}
  alias_map = {k: id_map[id(v)] for k, v in contents.resources.iteritems()
               if id_map[id(v)] != k}
  # Longest locale pak is es-419.pak
  if len(os.path.basename(file_name)) <= 9:
    section_name = models.SECTION_PAK_TRANSLATIONS
  else:
    section_name = models.SECTION_PAK_NONTRANSLATED
  object_path = path_util.ToSrcRootRelative(file_name)
  for resource_id in sorted(contents.resources):
    if resource_id in alias_map:
      # 4 extra bytes of metadata (2 16-bit ints)
      size = 4
      name = res_info[alias_map[resource_id]][0]
    else:
      # 6 extra bytes of metadata (1 32-bit int, 1 16-bit int)
      size = len(contents.resources[resource_id]) + 6
      name, source_path = res_info[resource_id]
      if name not in symbols_by_name:
        full_name = '{}: {}'.format(source_path, name)
        symbols_by_name[name] = models.Symbol(
            section_name, 0, address=resource_id, full_name=full_name,
            source_path=source_path, object_path=object_path)
    symbols_by_name[name].size += size
    total += size
  assert file_size == total, (
      '{} bytes in pak file not accounted for'.format(file_size - total))