Exemple #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')
    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
Exemple #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')
    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
Exemple #3
0
def main():
    setup_logging()
    logging.debug("args: %s", " ".join(sys.argv))

    args = parse_args()
    c.update_args(args)
    transpile_files(args.commands_json, args.filter, args.extra_impo_args,
                    args.import_only, args.verbose, args.emit_build_files,
                    args.main, args.cross_checks, args.use_fakechecks,
                    args.cross_check_config, args.reloop_cfgs)

    logging.info("success")
Exemple #4
0
    def load(cls, model_path, ex_args=None, cuda=False):
        params = torch.load(model_path)
        vocab = params['vocab']
        transition_system = params['transition_system']
        saved_args = params['args']
        # update saved args
        saved_state = params['state_dict']
        saved_args.cuda = cuda
        if ex_args:
            update_args(saved_args, ex_args)
        parser = cls(saved_args, transition_system, vocab)
        parser.load_state_dict(saved_state)

        # setattr(saved_args, )
        if cuda: parser = parser.cuda()
        parser.eval()

        return parser
Exemple #5
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
Exemple #6
0
def main():
    setup_logging()
    logging.debug("args: %s", " ".join(sys.argv))

    args = parse_args()
    c.update_args(args)
    transpile_files(cc_db=args.commands_json,
                    filter=lambda f: args.filter in f,
                    extra_impo_args=args.extra_impo_args,
                    import_only=args.import_only,
                    verbose=args.verbose,
                    emit_build_files=args.emit_build_files,
                    main_module_for_build_files=args.main,
                    cross_checks=args.cross_checks,
                    use_fakechecks=args.use_fakechecks,
                    cross_check_config=args.cross_check_config,
                    reloop_cfgs=args.reloop_cfgs,
                    reorganize_definitions=args.reorganize_definitions)

    logging.info("success")
Exemple #7
0
def main(argv: List[str]):
    ap = build_arg_parser()
    args = ap.parse_args(argv)
    config.update_args(args)

    if args.cmd == 'extract':
        do_extract(args)
    elif args.cmd == 'exec':
        do_exec(args)
    elif args.cmd == 'render':
        do_render(args)
    elif args.cmd == 'playground':
        do_playground(args)
    elif args.cmd == 'playground-styles':
        do_playground_styles(args)
    else:
        if args.cmd is not None:
            print('unknown subcommand `%s`' % args.cmd)
        ap.print_usage()
        sys.exit(1)
Exemple #8
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
Exemple #9
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)