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 = WrapperUtils.ResolveRspLinks(args.inputs) WrapperUtils.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(WrapperUtils.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('--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 = WrapperUtils.ResolveRspLinks(args.command) WrapperUtils.CombineResourceWhitelists(whitelist_candidates, args.resource_whitelist) # First, run the actual link. result = subprocess.call(WrapperUtils.CommandToRun(args.command), env=fast_env) 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( WrapperUtils.CommandToRun([ args.strip, '--strip-unneeded', '-o', args.output, args.sofile ])) return result