Example #1
0
def main():
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument('--ar',
                      required=True,
                      help='The ar binary to run',
                      metavar='PATH')
  parser.add_argument('--output',
                      required=True,
                      help='Output archive file',
                      metavar='ARCHIVE')
  parser.add_argument('--plugin',
                      help='Load plugin')
  parser.add_argument('--resource-whitelist',
                      help='Merge all resource whitelists into a single file.',
                      metavar='PATH')
  parser.add_argument('operation',
                      help='Operation on the archive')
  parser.add_argument('inputs', nargs='+',
                      help='Input files')
  args = parser.parse_args()

  # Specifies the type of object file ar should examine.
  # The ar on linux ignores this option.
  object_mode = []
  if sys.platform.startswith('aix'):
    # The @file feature is not avaliable on ar for AIX.
    # For linux (and other posix like systems), the @file_name
    # option reads the contents of file_name as command line arguments.
    # For AIX we must parse these (rsp files) manually.
    # Read rspfile.
    args.inputs  = wrapper_utils.ResolveRspLinks(args.inputs)
    object_mode = ['-X64']
  else:
    if args.resource_whitelist:
      whitelist_candidates = wrapper_utils.ResolveRspLinks(args.inputs)
      wrapper_utils.CombineResourceWhitelists(
          whitelist_candidates, args.resource_whitelist)

  command = [args.ar] + object_mode + [args.operation]
  if args.plugin is not None:
    command += ['--plugin', args.plugin]
  command.append(args.output)
  command += args.inputs

  # Remove the output file first.
  try:
    os.remove(args.output)
  except OSError as e:
    if e.errno != os.errno.ENOENT:
      raise

  # Now just run the ar command.
  return subprocess.call(wrapper_utils.CommandToRun(command))
Example #2
0
def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--ar',
                        required=True,
                        help='The ar binary to run',
                        metavar='PATH')
    parser.add_argument('--output',
                        required=True,
                        help='Output archive file',
                        metavar='ARCHIVE')
    parser.add_argument('--plugin', help='Load plugin')
    parser.add_argument(
        '--resource-whitelist',
        help='Merge all resource whitelists into a single file.',
        metavar='PATH')
    parser.add_argument('operation', help='Operation on the archive')
    parser.add_argument('inputs', nargs='+', help='Input files')
    args = parser.parse_args()

    if args.resource_whitelist:
        whitelist_candidates = wrapper_utils.ResolveRspLinks(args.inputs)
        wrapper_utils.CombineResourceWhitelists(whitelist_candidates,
                                                args.resource_whitelist)

    command = [args.ar, args.operation]
    if args.plugin is not None:
        command += ['--plugin', args.plugin]
    command.append(args.output)
    command += args.inputs

    # Remove the output file first.
    try:
        os.remove(args.output)
    except OSError as e:
        if e.errno != os.errno.ENOENT:
            raise

    # Now just run the ar command.
    return subprocess.call(wrapper_utils.CommandToRun(command))
def main():
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument('--readelf',
                      required=True,
                      help='The readelf binary to run',
                      metavar='PATH')
  parser.add_argument('--nm',
                      required=True,
                      help='The nm binary to run',
                      metavar='PATH')
  parser.add_argument('--strip',
                      help='The strip binary to run',
                      metavar='PATH')
  parser.add_argument('--sofile',
                      required=True,
                      help='Shared object file produced by linking command',
                      metavar='FILE')
  parser.add_argument('--tocfile',
                      required=True,
                      help='Output table-of-contents file',
                      metavar='FILE')
  parser.add_argument('--map-file',
                      help=('Use --Wl,-Map to generate a map file. Will be '
                            'gzipped if extension ends with .gz'),
                      metavar='FILE')
  parser.add_argument('--output',
                      required=True,
                      help='Final output shared object file',
                      metavar='FILE')
  parser.add_argument('--resource-whitelist',
                      help='Merge all resource whitelists into a single file.',
                      metavar='PATH')
  parser.add_argument('command', nargs='+',
                      help='Linking command')
  args = parser.parse_args()

  # Work-around for gold being slow-by-default. http://crbug.com/632230
  fast_env = dict(os.environ)
  fast_env['LC_ALL'] = 'C'

  if args.resource_whitelist:
    whitelist_candidates = wrapper_utils.ResolveRspLinks(args.command)
    wrapper_utils.CombineResourceWhitelists(
        whitelist_candidates, args.resource_whitelist)

  # First, run the actual link.
  command = wrapper_utils.CommandToRun(args.command)
  result = wrapper_utils.RunLinkWithOptionalMapFile(command, env=fast_env,
                                                    map_file=args.map_file)

  if result != 0:
    return result

  # Next, generate the contents of the TOC file.
  result, toc = CollectTOC(args)
  if result != 0:
    return result

  # If there is an existing TOC file with identical contents, leave it alone.
  # Otherwise, write out the TOC file.
  UpdateTOC(args.tocfile, toc)

  # Finally, strip the linked shared object file (if desired).
  if args.strip:
    result = subprocess.call(wrapper_utils.CommandToRun(
        [args.strip, '--strip-unneeded', '-o', args.output, args.sofile]))

  return result