def _run(ctx, inputs, out_ext, tool, args, entry = None):
    """A helper to run a shell script and capture the output.

    ctx:  The blaze context.
    inputs: A list of files used by the shell.
    out_ext: An extension to add to the current label for the output file.
    tool: What tool to run.
    args: A list of arguments to pass to the tool.
    entry: If specified, it points to a file contianing the entry point; that
           information is extracted and provided as value to the --top
           command-line switch.

    Returns:
      The File output.
    """
    library_name = ctx.attr.library_name or ctx.label.name
    out = ctx.actions.declare_file("%s%s" % (library_name, out_ext))
    arguments = " ".join(args)
    if entry != None:
        arguments += " --top $(cat {})".format(entry.path)
    ctx.actions.run_shell(
        inputs = inputs,
        outputs = [out],
        tools = [tool],
        command = "%s %s > %s" % (tool.path, arguments, out.path),
    )
    return out