Esempio n. 1
0
    def check(self):
        # Make sure any changed crates have updated versions
        ok = self._in_crates(self._check_version)

        # Check that the repository is clean
        git_status = git('status', '--porcelain').strip()
        if git_status:
            print_error(
                'Repository is not in a clean state. Commit any changes and resolve any untracked files.'
            )
            ok = False

        # Make sure the project builds
        print('Building and testing...')
        with pb.local.cwd(c.ROOT_DIR):
            invoke_quietly(cargo['clean'])
            if not invoke_quietly(cargo['build', '--release']):
                print_error('cargo build failed in root workspace')
                ok = False
            test_translator = python3['scripts/test_translator.py', 'tests']
            if not invoke_quietly(test_translator):
                print_error('scripts/test_translator.py failed')
                ok = False
        # with pb.local.cwd(c.RUST_CHECKS_DIR):
        #     invoke_quietly(cargo['clean'])
        #     if not invoke_quietly(cargo['test', '--release']):
        #         print_error('cargo test failed in rust-checks workspace')
        #         ok = False

        return ok
def test_lua(args: argparse.Namespace) -> bool:
    """
    download lua, compile lua with bear to create
    a compiler command database, and use it to
    drive the transpiler.
    """

    if not os.path.isfile(os.path.join(c.DEPS_DIR, LUA_ARCHIVE)):
        with pb.local.cwd(c.DEPS_DIR):
            download_archive(LUA_URL, LUA_ARCHIVE)
    if not os.path.isdir(LUA_SRC):
        with pb.local.cwd(c.DEPS_DIR):
            invoke_quietly(TAR, "xf", LUA_ARCHIVE)

    # unconditionally compile lua since we don't know if
    # cc_db was generated from the environment we're in.
    build_dir = os.path.join(LUA_SRC, "build")
    rmtree(build_dir, ignore_errors=True)
    os.mkdir(build_dir)
    with pb.local.cwd(build_dir), pb.local.env(CC="clang"):
        invoke(CMAKE['-DCMAKE_EXPORT_COMPILE_COMMANDS=1', LUA_SRC])
        invoke(MAKE[JOBS])

    cc_db_file = os.path.join(LUA_SRC, "build", c.CC_DB_JSON)
    if not os.path.isfile(cc_db_file):
        die("missing " + cc_db_file, errno.ENOENT)

    with open(cc_db_file) as cc_db:
        return transpile_files(cc_db, args.jobs, None, False, args.verbose)
def test_json_c(args: argparse.Namespace) -> bool:
    if not os.path.isfile(os.path.join(c.DEPS_DIR, JSON_C_ARCHIVE)):
        with pb.local.cwd(c.DEPS_DIR):
            download_archive(JSON_C_URL, JSON_C_ARCHIVE)
            invoke_quietly(TAR, "xf", JSON_C_ARCHIVE)

    cc_db_file = os.path.join(JSON_C_SRC, c.CC_DB_JSON)
    # unconditionally compile json-c since we don't know if
    # cc_db was generated from the environment we're in.
    with pb.local.cwd(JSON_C_SRC), pb.local.env(CC="clang"):
        if os.path.isfile('Makefile'):
            invoke(MAKE['clean'])
        configure = pb.local.get("./configure")
        invoke(configure)
        invoke(BEAR[MAKE[JOBS]])

    if not os.path.isfile(cc_db_file):
        die("missing " + cc_db_file, errno.ENOENT)

    return transpile(cc_db_file)
def test_ruby(args: argparse.Namespace) -> bool:
    if on_mac():
        die("transpiling ruby on mac is not supported.")

    if not os.path.isfile(os.path.join(c.DEPS_DIR, RUBY_ARCHIVE)):
        with pb.local.cwd(c.DEPS_DIR):
            download_archive(RUBY_URL, RUBY_ARCHIVE)
            invoke_quietly(TAR, "xf", RUBY_ARCHIVE)

    cc_db_file = os.path.join(RUBY_SRC, c.CC_DB_JSON)

    # unconditionally compile ruby since we don't know if
    # cc_db was generated from the environment we're in.
    with pb.local.cwd(RUBY_SRC), pb.local.env(CC="clang", cflags="-w"):
        configure = pb.local.get("./configure")
        invoke(configure)
        invoke(BEAR[MAKE[JOBS]])

    if not os.path.isfile(cc_db_file):
        die("missing " + cc_db_file, errno.ENOENT)

    with open(cc_db_file) as cc_db:
        return transpile_files(cc_db, args.jobs, None, False, args.verbose)
Esempio n. 5
0
def need_cargo_clean(args) -> bool:
    """
    Cargo may not pick up changes in c.BUILD_DIR that would require
    a rebuild. This function tries to detect when we need to clean.
    """
    c2rust = c2rust_bin_path(args)
    if not os.path.isfile(c2rust):
        logging.debug("need_cargo_clean:False:no-c2rust-bin")
        return False

    find = get_cmd_or_die("find")
    _retcode, stdout, _ = invoke_quietly(find, c.BUILD_DIR, "-cnewer", c2rust)
    include_pattern = "install/lib/clang/{ver}/include".format(ver=c.LLVM_VER)
    for line in stdout.split("\n")[:-1]:  # skip empty last line
        if line.endswith("install_manifest_clang-headers.txt") or \
                line.endswith("ninja_log") or \
                include_pattern in line:
            continue
        else:
            logging.debug("need_cargo_clean:True:%s", line)
            return True
    logging.debug("need_cargo_clean:False")
    return False