Beispiel #1
0
def _parse_args():
    """
    define and parse command line arguments here.
    """
    desc = 'download dependencies for the AST exporter and built it.'
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument('-c', '--clean-all', default=False,
                        action='store_true', dest='clean_all',
                        help='clean everything before building')
    parser.add_argument('--with-clang', default=False,
                        action='store_true', dest='with_clang',
                        help='build clang with this tool')
    llvm_ver_help = 'fetch and build specified version of clang/LLVM (default: {})'.format(c.LLVM_VER)
    # FIXME: build this list by globbing for scripts/llvm-*.0.*-key.asc
    llvm_ver_choices = ["6.0.0", "6.0.1", "7.0.0", "7.0.1", "8.0.0"]
    parser.add_argument('--with-llvm-version', default=None,
                        action='store', dest='llvm_ver',
                        help=llvm_ver_help, choices=llvm_ver_choices)
    parser.add_argument('--without-assertions', default=True,
                        action='store_false', dest='assertions',
                        help='build the tool and clang without assertions')
    parser.add_argument('-x', '--xcode', default=False,
                        action='store_true', dest='xcode',
                        help='generate Xcode project files (macOS only)')
    parser.add_argument('-v', '--verbose', default=False,
                        action='store_true', dest='verbose',
                        help='emit verbose information during build')
    c.add_args(parser)
    args = parser.parse_args()

    if not on_mac() and args.xcode:
        die("-x/--xcode option requires macOS host.")

    c.update_args(args)
    return args
Beispiel #2
0
def _parse_args():
    """
    define and parse command line arguments here.
    """
    desc = 'download dependencies for the AST exporter and built it.'
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument('-c',
                        '--clean-all',
                        default=False,
                        action='store_true',
                        dest='clean_all',
                        help='clean everything before building')
    thelp = 'sanity test ast exporter using tinycbor (linux only)'
    parser.add_argument('-t',
                        '--test',
                        default=False,
                        action='store_true',
                        dest='sanity_test',
                        help=thelp)
    parser.add_argument('--with-clang',
                        default=False,
                        action='store_true',
                        dest='with_clang',
                        help='build clang with this tool')
    parser.add_argument('--without-assertions',
                        default=True,
                        action='store_false',
                        dest='assertions',
                        help='build the tool and clang without assertions')
    c.add_args(parser)
    args = parser.parse_args()
    c.update_args(args)
    return args
Beispiel #3
0
def build_arg_parser() -> argparse.ArgumentParser:
    common = argparse.ArgumentParser(add_help=False)
    common.add_argument('--project-dir',
                        default='.',
                        help='path to the project directory')
    config.add_args(common)

    ap = argparse.ArgumentParser(
        description='Process literate refactoring scripts.')

    subparsers = ap.add_subparsers(dest='cmd')

    sp = subparsers.add_parser(
        'extract',
        help='extract refactoring script from a Markdown file and print it',
        parents=[common])
    sp.add_argument('input', metavar='INPUT.md')

    sp = subparsers.add_parser(
        'exec',
        help='extract refactoring script and run it on the project directory',
        parents=[common])
    sp.add_argument('input', metavar='INPUT.md')
    sp.add_argument(
        '--work-dir',
        help='copy the project into a work directory before refactoring'),
    sp.add_argument('-f',
                    '--force',
                    default=False,
                    action='store_true',
                    help='remove the work directory if it already exists'),

    sp = subparsers.add_parser(
        'render',
        help='generate rendered Markdown, including a diff for every '
        'refactoring step',
        parents=[common])
    sp.add_argument(
        '--playground-js',
        help='if set, the generated markdown will include this javascript '
        'URL and call `initRefactorPlaygroundButtons` to set up '
        'playground integration')
    sp.add_argument('input', metavar='INPUT.md')
    sp.add_argument('output', metavar='OUTPUT.md')

    sp = subparsers.add_parser(
        'playground',
        help='run a refactoring script on some code, and render a diff',
        parents=[common])
    sp.add_argument('code', metavar='CODE.rs')
    sp.add_argument('script', metavar='SCRIPT.txt')
    sp.add_argument('output', metavar='OUTPUT.html')

    sp = subparsers.add_parser(
        'playground-styles',
        help='print CSS styles for rendering playground diffs')

    return ap
Beispiel #4
0
def parse_args() -> argparse.Namespace:
    """
    define and parse command line arguments here.
    """
    desc = 'transpile files in compiler_commands.json.'
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument('commands_json', type=argparse.FileType('r'))
    parser.add_argument('-i', '--import-only', default=False,
                        action='store_true', dest='import_only',
                        help='skip ast export step')
    parser.add_argument('-f', '--filter', default="",
                        help='only process files matching filter')
    parser.add_argument('-v', '--verbose', default=False,
                        action='store_true', dest="verbose",
                        help='enable verbose output')
    # parser.add_argument('-j', '--jobs', type=int, dest="jobs",
    #                     default=multiprocessing.cpu_count(),
    #                     help='max number of concurrent jobs')
    parser.add_argument('-a', '--importer-arg', dest="extra_impo_args",
                        default=[], action='append',
                        help='extra arguments for ast-importer')
    parser.add_argument('-e', '--emit-build-files',
                        default=False, action='store_true',
                        help='emit Rust build files, i.e., Cargo.toml '
                             'for a library (or a binary if -m/--main '
                             'is given)')
    parser.add_argument('-m', '--main',
                        default=None, action='store',
                        help='emit Rust build files for a binary using '
                             'the main method in the specified translation '
                             'unit (implies -e/--emit-build-files)')
    parser.add_argument('-x', '--cross-checks',
                        default=False, action='store_true',
                        help='enable cross-checks')
    parser.add_argument('-u', '--use-fakechecks',
                        default=False, action='store_true',
                        help='use log-based cross checking '
                             '(implies -x/--cross-checks)')
    parser.add_argument('-X', '--cross-check-config',
                        default=[], action='append',
                        help='cross-check configuration file(s)')
    parser.add_argument('--reloop-cfgs', '--no-reloop-cfgs', nargs=0,
                        default=True, dest="reloop_cfgs",
                        action=NegateAction,
                        help='enable (disable) relooper; enabled by '
                             'default')
    c.add_args(parser)

    args = parser.parse_args()
    # -m/--main implies -e/--emit-build-files
    args.emit_build_files = True if args.main else args.emit_build_files
    # -u/--use-fakechecks implies -x/--cross-checks
    args.cross_checks = True if args.use_fakechecks else args.cross_checks
    return args
Beispiel #5
0
def parse_args() -> argparse.Namespace:
    """
    define and parse command line arguments here.
    """
    desc = 'transpile files in compiler_commands.json.'
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument('commands_json', type=argparse.FileType('r'))
    parser.add_argument('-i',
                        '--import-only',
                        default=False,
                        action='store_true',
                        dest='import_only',
                        help='skip ast export step')
    parser.add_argument('-f',
                        '--filter',
                        default="",
                        help='only process files matching filter')
    parser.add_argument('-v',
                        '--verbose',
                        default=False,
                        dest="verbose",
                        help='enable verbose output')
    parser.add_argument('-j',
                        '--jobs',
                        type=int,
                        dest="jobs",
                        default=multiprocessing.cpu_count(),
                        help='max number of concurrent jobs')
    parser.add_argument('-a',
                        '--importer-arg',
                        dest="extra_impo_args",
                        default=[],
                        action='append',
                        help='extra arguments for ast-importer')
    parser.add_argument('-e',
                        '--emit-build-files',
                        default=False,
                        action='store_true',
                        help='emit Rust build files, i.e., Cargo.toml '
                        'and lib.rs')
    parser.add_argument('-x',
                        '--cross-checks',
                        default=False,
                        action='store_true',
                        help='enable cross-checks')
    parser.add_argument('-X',
                        '--cross-check-config',
                        default=[],
                        action='append',
                        help='cross-check configuration file(s)')
    c.add_args(parser)
    return parser.parse_args()
Beispiel #6
0
def _parser_args():
    desc = 'Build and test examples.'
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument(
        '--only-examples',
        dest='regex_examples',
        type=regex,
        default='.*',
        help="Regular Expression to filter which example to build and run")
    parser.add_argument('--deinit',
                        default=False,
                        action='store_true',
                        dest='deinit',
                        help='Deinitialize the submodules, this will remove\
                        all unstaged changes')
    c.add_args(parser)
    args = parser.parse_args()
    c.update_args(args)
    return args
Beispiel #7
0
def _parse_args():
    """
    define and parse command line arguments here.
    """
    desc = 'download dependencies for the AST exporter and built it.'
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument('-c',
                        '--clean-all',
                        default=False,
                        action='store_true',
                        dest='clean_all',
                        help='clean everything before building')
    parser.add_argument('--with-clang',
                        default=False,
                        action='store_true',
                        dest='with_clang',
                        help='build clang with this tool')
    parser.add_argument('--without-assertions',
                        default=True,
                        action='store_false',
                        dest='assertions',
                        help='build the tool and clang without assertions')
    parser.add_argument('-x',
                        '--xcode',
                        default=False,
                        action='store_true',
                        dest='xcode',
                        help='generate Xcode project files (macOS only)')
    c.add_args(parser)
    args = parser.parse_args()

    if not on_mac() and args.xcode:
        die("-x/--xcode option requires macOS host.")

    c.update_args(args)
    return args
Beispiel #8
0
def main() -> None:
    desc = 'run regression / unit / feature tests.'
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument('directory', type=readable_directory)
    parser.add_argument('--only-files',
                        dest='regex_files',
                        type=regex,
                        default='.*',
                        help="Regular expression to filter which tests to run")
    parser.add_argument('--only-directories',
                        dest='regex_directories',
                        type=regex,
                        default='.*',
                        help="Regular expression to filter which tests to run")
    parser.add_argument(
        '--log',
        dest='logLevel',
        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
        default='CRITICAL',
        help="Set the logging level")
    parser.add_argument('--keep',
                        dest='keep',
                        action='append',
                        choices=intermediate_files + ['all'],
                        default=[],
                        help="Which intermediate files to not clear")
    parser.add_argument(
        '--test-longdoubles',
        dest='test_longdoubles',
        default=False,
        action="store_true",
        help=
        "Enables testing of long double translation which requires gcc headers",
    )
    c.add_args(parser)

    args = parser.parse_args()
    c.update_args(args)
    test_directories = get_testdirectories(args.directory, args.regex_files,
                                           args.keep, args.test_longdoubles)
    setup_logging(args.logLevel)

    logging.debug("args: %s", " ".join(sys.argv))

    # check that the binaries have been built first
    bins = [c.TRANSPILER]
    for b in bins:
        if not os.path.isfile(b):
            msg = b + " not found; run cargo build --release first?"
            die(msg, errno.ENOENT)

    # NOTE: it seems safe to disable this check since we now
    # that we use a rust-toolchain file for rustc versioning.
    # ensure_rustc_version(c.CUSTOM_RUST_RUSTC_VERSION)

    if not test_directories:
        die("nothing to test")

    # Accumulate test case stats
    test_results = {
        "unexpected failures": 0,
        "unexpected successes": 0,
        "expected failures": 0,
        "successes": 0
    }

    for test_directory in test_directories:
        if args.regex_directories.fullmatch(test_directory.name):
            # Testdirectories are run one after another. Only test directories
            # that match the '--only-directories' or tests that match the
            # '--only-files' arguments are run.  We make a best effort to clean
            # up files we left behind.
            try:
                statuses = test_directory.run()
            except (KeyboardInterrupt, SystemExit):
                test_directory.cleanup()
                raise
            finally:
                test_directory.cleanup()

            for status in statuses:
                test_results[status.value] += 1

    # Print out test case stats
    sys.stdout.write("\nTest summary:\n")
    for variant, count in test_results.items():
        sys.stdout.write("  {}: {}\n".format(variant, count))

    # If anything unexpected happened, exit with error code 1
    unexpected = \
        test_results["unexpected failures"] + \
        test_results["unexpected successes"]
    if 0 < unexpected:
        quit(1)