Пример #1
0
def build_transpiler(args):
    cargo = get_cmd_or_die("cargo")
    build_flags = ["build", "--features", "llvm-static"]

    if not args.debug:
        build_flags.append("--release")

    llvm_config = os.path.join(c.LLVM_BLD, "bin/llvm-config")
    assert os.path.isfile(llvm_config), "missing binary: " + llvm_config

    if on_mac():
        llvm_system_libs = "-lz -lcurses -lm -lxml2"
    else:  # linux
        llvm_system_libs = "-lz -lrt -ltinfo -ldl -lpthread -lm"

    llvm_libdir = os.path.join(c.LLVM_BLD, "lib")

    # log how we run `cargo build` to aid troubleshooting, IDE setup, etc.
    msg = "invoking cargo build as\ncd {} && \\\n".format(c.C2RUST_DIR)
    msg += "LLVM_CONFIG_PATH={} \\\n".format(llvm_config)
    msg += "LLVM_SYSTEM_LIBS='{}' \\\n".format(llvm_system_libs)
    msg += "C2RUST_AST_EXPORTER_LIB_DIR={} \\\n".format(llvm_libdir)
    msg += " cargo +{} ".format(c.CUSTOM_RUST_NAME)
    msg += " ".join(build_flags)
    logging.debug(msg)

    with pb.local.cwd(c.C2RUST_DIR):
        with pb.local.env(LLVM_CONFIG_PATH=llvm_config,
                          LLVM_SYSTEM_LIBS=llvm_system_libs,
                          C2RUST_AST_EXPORTER_LIB_DIR=llvm_libdir):
            # build with custom rust toolchain
            invoke(cargo, "+" + c.CUSTOM_RUST_NAME, *build_flags)
Пример #2
0
 def gen_cc_db(self):
     with pb.local.cwd(self.repo_dir):
         invoke(make, ['clean'])
         invoke(intercept_build, *self.ib_cmd)
         self.cc_db = build_path(self.repo_dir,
                                 'compile_commands.json',
                                 is_dir=False)
Пример #3
0
def build_clang_plugin(args: str) -> None:
    """
    run cmake as needed to generate ninja buildfiles. then run ninja.
    """
    ninja = get_cmd_or_die("ninja")
    # Possible values are Release, Debug, RelWithDebInfo and MinSizeRel
    build_type = "Debug" if args.debug else "RelWithDebInfo"
    ninja_build_file = os.path.join(c.CLANG_XCHECK_PLUGIN_BLD, "build.ninja")
    with pb.local.cwd(c.CLANG_XCHECK_PLUGIN_BLD):
        if os.path.isfile(ninja_build_file):
            prev_build_type = get_ninja_build_type(ninja_build_file)
            run_cmake = prev_build_type != build_type
        else:
            run_cmake = True

        if run_cmake:
            cmake = get_cmd_or_die("cmake")
            max_link_jobs = est_parallel_link_jobs()
            cargs = ["-G", "Ninja", c.CLANG_XCHECK_PLUGIN_SRC,
                     "-DLLVM_DIR={}/lib/cmake/llvm".format(c.LLVM_BLD),
                     "-DClang_DIR={}/lib/cmake/clang".format(c.LLVM_BLD),
                     "-DLLVM_EXTERNAL_LIT={}/bin/llvm-lit".format(c.LLVM_BLD),
                     "-DCMAKE_BUILD_TYPE=" + build_type,
                     "-DBUILD_SHARED_LIBS=1",
                     "-DLLVM_PARALLEL_LINK_JOBS={}".format(max_link_jobs)]
            invoke(cmake[cargs])
        else:
            logging.debug("found existing ninja.build, not running cmake")
        invoke(ninja)
Пример #4
0
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)
Пример #5
0
 def gen_cc_db(self):
     # Without --disable-static, libtool builds two copies of many source
     # files. We can't handle that, so we disable that behavior here.
     self.autotools(['--disable-static'])
     with pb.local.cwd(self.repo_dir):
         invoke(make, ['clean'])
         invoke(intercept_build, *self.ib_cmd)
Пример #6
0
def _test_minimal(code_snippet: str) -> bool:
    ast_expo = get_cmd_or_die(c.AST_EXPO)
    ast_impo = get_cmd_or_die(c.AST_IMPO)

    tempdir = tempfile.gettempdir()
    cfile = os.path.join(tempdir, "test.c")
    with open(cfile, 'w') as fh:
        fh.write(code_snippet)

    # avoid warnings about missing compiler flags, not strictly required
    cc_json = os.path.join(tempdir, "compile_commands.json")
    with open(cc_json, 'w') as fh:
        fh.write(minimal_cc_db)

    cborfile = cfile + '.cbor'

    invoke(ast_expo[cfile])

    ld_lib_path = get_rust_toolchain_libpath()

    # don't overwrite existing ld lib path if any...
    if 'LD_LIBRARY_PATH' in pb.local.env:
        ld_lib_path += ':' + pb.local.env['LD_LIBRARY_PATH']

    args = []
    args += ['--ddump-untyped-clang-ast']
    args += [cborfile]

    # import ast
    with pb.local.env(RUST_BACKTRACE='1', LD_LIBRARY_PATH=ld_lib_path):
        invoke(ast_impo, args)

    return True  # if we get this far, test passed
Пример #7
0
    def test(self):
        # testname -> input_file
        tests = {
            "xmllint": ['test/bigname.xml'],
            "runtest": [],
            "testapi": [],
            "testSAX": [],
            "testURI": ['test/bigname.xml'],
            "testdict": [],
            "testHTML": ['test/HTML/html5_enc.html'],
            "testC14N":
            ['--', '--with-comments', 'test/c14n/with-comments/example-7.xml'],
            "testchar": [],
            "testRelax": ['test/bigname.xml'],
            "testXPath": ['test/bigname.xml'],
            "testModule": [],
            "testlimits": [],
            # "testReader", Not working at the moment
            "testRegexp": ['test/regexp'],
            "testrecurse": [],
            "testSchemas": ['test/schemas/all_0.xsd'],
            "testThreads": [],
            "testAutomata": ['test/automata/po'],
        }

        for test, input_file in tests.items():
            with pb.local.cwd(self.rust_src):
                example_args = ['run', '--example', test]
                example_args.extend(input_file)
                invoke(cargo, *example_args)
Пример #8
0
def _main():
    setup_logging()
    logging.debug("args: %s", " ".join(sys.argv))

    # FIXME: allow env/cli override of LLVM_SRC and LLVM_BLD
    # FIXME: check that cmake and ninja are installed
    # FIXME: option to build LLVM/Clang from master?

    args = _parse_args()

    if args.clean_all:
        logging.info("cleaning all dependencies and previous built files")
        shutil.rmtree(c.LLVM_SRC, ignore_errors=True)
        shutil.rmtree(c.LLVM_BLD, ignore_errors=True)
        shutil.rmtree(c.BUILD_DIR, ignore_errors=True)
        shutil.rmtree(c.AST_EXPO_PRJ_DIR, ignore_errors=True)
        cargo = get_cmd_or_die("cargo")
        with pb.local.cwd(c.ROOT_DIR):
            invoke(cargo, "clean")

    ensure_dir(c.LLVM_BLD)
    ensure_dir(c.BUILD_DIR)
    git_ignore_dir(c.BUILD_DIR)

    download_llvm_sources()
    configure_and_build_llvm(args)
    build_transpiler(args)
    print_success_msg(args)
Пример #9
0
def test_clang_cross_checks():
    ninja = get_cmd_or_die("ninja")
    logging.info("entering %s", c.CLANG_XCHECK_PLUGIN_BLD)
    with pb.local.cwd(c.CLANG_XCHECK_PLUGIN_BLD):
        # FIXME: do we really need to clean before every test run???
        invoke(ninja, ["clean"])
        invoke(ninja, ["check-cross-checks"])
Пример #10
0
def _main():
    setup_logging()
    logging.debug("args: %s", " ".join(sys.argv))

    # FIXME: allow env/cli override of LLVM_SRC, LLVM_VER, and LLVM_BLD
    # FIXME: check that cmake and ninja are installed
    # FIXME: option to build LLVM/Clang from master?

    # earlier plumbum versions are missing features such as TEE
    if pb.__version__ < c.MIN_PLUMBUM_VERSION:
        err = "locally installed version {} of plumbum is too old.\n" \
            .format(pb.__version__)
        err += "please upgrade plumbum to version {} or later." \
            .format(c.MIN_PLUMBUM_VERSION)
        die(err)

    args = _parse_args()

    # prerequisites
    if not have_rust_toolchain(c.CUSTOM_RUST_NAME):
        die("missing rust toolchain: " + c.CUSTOM_RUST_NAME, errno.ENOENT)

    # clang 3.6.0 is known to work; 3.4.0 known to not work.
    ensure_clang_version([3, 6, 0])

    if args.clean_all:
        logging.info("cleaning all dependencies and previous built files")
        shutil.rmtree(c.LLVM_SRC, ignore_errors=True)
        shutil.rmtree(c.LLVM_BLD, ignore_errors=True)
        shutil.rmtree(c.DEPS_DIR, ignore_errors=True)
        shutil.rmtree(c.AST_EXPO_PRJ_DIR, ignore_errors=True)
        cargo = get_cmd_or_die("cargo")
        with pb.local.cwd(c.ROOT_DIR):
            invoke(cargo, "clean")

    ensure_dir(c.LLVM_BLD)
    ensure_dir(c.DEPS_DIR)
    git_ignore_dir(c.DEPS_DIR)

    download_llvm_sources()

    update_cmakelists()

    configure_and_build_llvm(args)

    build_transpiler(args)

    # print a helpful message on how to run c2rust bin directly
    c2rust_bin_path = 'target/debug/c2rust' if args.debug \
                      else 'target/release/c2rust'
    c2rust_bin_path = os.path.join(c.ROOT_DIR, c2rust_bin_path)
    # if os.path.curdir
    abs_curdir = os.path.abspath(os.path.curdir)
    common_path = os.path.commonpath([abs_curdir, c2rust_bin_path])
    if common_path != "/":
        c2rust_bin_path = "." + c2rust_bin_path[len(common_path):]
    print("success! you may now run", c2rust_bin_path)
Пример #11
0
def test_rust_cross_checks():
    rustup = get_cmd_or_die("rustup")

    rust_proj_path = os.path.join(c.CROSS_CHECKS_DIR, "rust-checks")
    logging.info("entering %s", rust_proj_path)
    with pb.local.cwd(rust_proj_path):
        invoke(rustup, ["run", c.CUSTOM_RUST_NAME, "cargo", "clean"])
        args = ["run", c.CUSTOM_RUST_NAME, "cargo", "test"]
        invoke(rustup, *args)
Пример #12
0
def build_transpiler(args):
    nice = get_cmd_or_die("nice")
    cargo = get_cmd_or_die("cargo")

    if need_cargo_clean(args):
        invoke(cargo, "clean")

    build_flags = [
        "-n", "19",
        str(cargo), "build", "--features", "llvm-static"
    ]

    if not args.debug:
        build_flags.append("--release")

    if args.verbose:
        build_flags.append("-vv")

    llvm_config = os.path.join(c.LLVM_BLD, "bin/llvm-config")
    assert os.path.isfile(llvm_config), "missing binary: " + llvm_config

    if on_mac():
        llvm_system_libs = "-lz -lcurses -lm -lxml2"
    else:  # linux
        llvm_system_libs = "-lz -lrt -ltinfo -ldl -lpthread -lm"

    llvm_libdir = os.path.join(c.LLVM_BLD, "lib")

    # log how we run `cargo build` to aid troubleshooting, IDE setup, etc.
    msg = "invoking cargo build as\ncd {} && \\\n".format(c.C2RUST_DIR)
    msg += "LIBCURL_NO_PKG_CONFIG=1\\\n"
    msg += "ZLIB_NO_PKG_CONFIG=1\\\n"
    msg += "LLVM_CONFIG_PATH={} \\\n".format(llvm_config)
    msg += "LLVM_SYSTEM_LIBS='{}' \\\n".format(llvm_system_libs)
    msg += "C2RUST_AST_EXPORTER_LIB_DIR={} \\\n".format(llvm_libdir)
    msg += " cargo"
    msg += " ".join(build_flags)
    logging.debug(msg)

    # NOTE: the `curl-rust` and `libz-sys` crates use the `pkg_config`
    # crate to locate the system libraries they wrap. This causes
    # `pkg_config` to add `/usr/lib` to `rustc`s library search path
    # which means that our `cargo` invocation picks up the system
    # libraries even when we're trying to link against libs we built.
    # https://docs.rs/pkg-config/0.3.14/pkg_config/
    with pb.local.cwd(c.C2RUST_DIR):
        with pb.local.env(LIBCURL_NO_PKG_CONFIG=1,
                          ZLIB_NO_PKG_CONFIG=1,
                          LLVM_CONFIG_PATH=llvm_config,
                          LLVM_SYSTEM_LIBS=llvm_system_libs,
                          C2RUST_AST_EXPORTER_LIB_DIR=llvm_libdir):
            invoke(nice, *build_flags)
Пример #13
0
def build_ast_importer(debug: bool):
    cargo = get_cmd_or_die("cargo")
    build_flags = ["build"]

    if not debug:
        build_flags.append("--release")

    with pb.local.cwd(os.path.join(c.ROOT_DIR, "ast-importer")):
        # use different target dirs for different hosts
        target_dir = "target." + platform.node()
        with pb.local.env(CARGO_TARGET_DIR=target_dir):
            # build with custom rust toolchain
            invoke(cargo, "+" + c.CUSTOM_RUST_NAME, *build_flags)
Пример #14
0
def checkout_and_build_libclevrbuf():
    """
    NOTE: we don't need libclevrbuf if we simply pass
    `--features "xcheck-with-dlsym"` in the `runtime/` dir.
    """
    make = get_cmd_or_die("make")

    if not os.path.isdir(c.LIBCLEVRBUF_DIR):
        update_or_init_submodule(c.REMON_SUBMOD_DIR)

    if not os.path.isfile(os.path.join(c.LIBCLEVRBUF_DIR, "libclevrbuf.so")):
        with pb.local.cwd(c.LIBCLEVRBUF_DIR):
            invoke(make, "lib")
Пример #15
0
def _main():
    setup_logging()
    logging.debug("args: %s", " ".join(sys.argv))

    # FIXME: allow env/cli override of LLVM_SRC and LLVM_BLD
    # FIXME: check that cmake and ninja are installed
    # FIXME: option to build LLVM/Clang from master?

    # earlier plumbum versions are missing features such as TEE
    if pb.__version__ < c.MIN_PLUMBUM_VERSION:
        err = "locally installed version {} of plumbum is too old.\n" \
            .format(pb.__version__)
        err += "please upgrade plumbum to version {} or later." \
            .format(c.MIN_PLUMBUM_VERSION)
        die(err)

    args = _parse_args()

    # prerequisites
    if not have_rust_toolchain(c.CUSTOM_RUST_NAME):
        die("missing rust toolchain: " + c.CUSTOM_RUST_NAME, errno.ENOENT)

    # clang 3.6.0 is known to work; 3.4.0 known to not work.
    ensure_clang_version([3, 6, 0])

    if args.clean_all:
        logging.info("cleaning all dependencies and previous built files")
        shutil.rmtree(c.LLVM_SRC, ignore_errors=True)
        shutil.rmtree(c.LLVM_BLD, ignore_errors=True)
        shutil.rmtree(c.BUILD_DIR, ignore_errors=True)
        shutil.rmtree(c.AST_EXPO_PRJ_DIR, ignore_errors=True)
        cargo = get_cmd_or_die("cargo")
        with pb.local.cwd(c.ROOT_DIR):
            invoke(cargo, "clean")

    ensure_dir(c.LLVM_BLD)
    ensure_dir(c.BUILD_DIR)
    git_ignore_dir(c.BUILD_DIR)

    download_llvm_sources()
    update_cmakelists()
    configure_and_build_llvm(args)
    build_transpiler(args)
    print_success_msg(args)
Пример #16
0
    def _invoke(self, cmd, dry_run=None):
        if dry_run is None:
            dry_run = self.dry_run

        print(cmd)
        result = True
        if not dry_run:
            result = invoke(cmd)
        print()
        return result
Пример #17
0
def build_transpiler(args):
    nice = get_cmd_or_die("nice")
    cargo = get_cmd_or_die("cargo")

    if need_cargo_clean(args):
        invoke(cargo, "clean")

    build_flags = [
        "-n", "19",
        str(cargo), "build", "--features", "llvm-static"
    ]

    if not args.debug:
        build_flags.append("--release")

    if args.verbose:
        build_flags.append("-vv")

    llvm_config = os.path.join(c.LLVM_BLD, "bin/llvm-config")
    assert os.path.isfile(llvm_config), \
        "expected llvm_config at " + llvm_config

    if on_mac():
        llvm_system_libs = "-lz -lcurses -lm -lxml2"
    else:  # linux
        llvm_system_libs = "-lz -lrt -ltinfo -ldl -lpthread -lm"

    llvm_libdir = os.path.join(c.LLVM_BLD, "lib")

    # NOTE: the `curl-rust` and `libz-sys` crates use the `pkg_config`
    # crate to locate the system libraries they wrap. This causes
    # `pkg_config` to add `/usr/lib` to `rustc`s library search path
    # which means that our `cargo` invocation picks up the system
    # libraries even when we're trying to link against libs we built.
    # https://docs.rs/pkg-config/0.3.14/pkg_config/
    with pb.local.cwd(c.C2RUST_DIR):
        with pb.local.env(LIBCURL_NO_PKG_CONFIG=1,
                          ZLIB_NO_PKG_CONFIG=1,
                          LLVM_CONFIG_PATH=llvm_config,
                          LLVM_LIB_DIR=llvm_libdir,
                          LLVM_SYSTEM_LIBS=llvm_system_libs):
            invoke(nice, *build_flags)
Пример #18
0
def configure_and_build_llvm(args: str) -> None:
    """
    run cmake as needed to generate ninja buildfiles. then run ninja.
    """
    ninja = get_cmd_or_die("ninja")
    # Possible values are Release, Debug, RelWithDebInfo and MinSizeRel
    build_type = "Debug" if args.debug else "RelWithDebInfo"
    ninja_build_file = os.path.join(c.LLVM_BLD, "build.ninja")
    with pb.local.cwd(c.LLVM_BLD):
        if os.path.isfile(ninja_build_file):
            prev_build_type = get_ninja_build_type(ninja_build_file)
            run_cmake = prev_build_type != build_type
        else:
            run_cmake = True

        if run_cmake:
            cmake = get_cmd_or_die("cmake")
            max_link_jobs = est_parallel_link_jobs()
            assertions = "1" if args.assertions else "0"
            cargs = ["-G", "Ninja", c.LLVM_SRC,
                     "-Wno-dev",
                     "-DCMAKE_C_COMPILER=clang",
                     "-DCMAKE_CXX_COMPILER=clang++",
                     "-DCMAKE_BUILD_TYPE=" + build_type,
                     "-DLLVM_ENABLE_ASSERTIONS=" + assertions,
                     "-DCMAKE_EXPORT_COMPILE_COMMANDS=1",
                     "-DLLVM_TARGETS_TO_BUILD=X86",
                     "-DLLVM_INCLUDE_UTILS=1",
                     "-DLLVM_BUILD_UTILS=1",
                     "-DBUILD_SHARED_LIBS=1",
                     "-DLLVM_PARALLEL_LINK_JOBS={}".format(max_link_jobs),
                     "-DTINYCBOR_PREFIX={}".format(c.CBOR_PREFIX)]
            invoke(cmake[cargs])
        else:
            logging.debug("found existing ninja.build, not running cmake")

        ninja_args = ['ast-exporter']
        ninja_args += ['FileCheck', 'count', 'not']
        if args.with_clang:
            ninja_args.append('clang')
        invoke(ninja, *ninja_args)
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)
Пример #20
0
def build_clang_plugin(args: str) -> None:
    """
    run cmake as needed to generate ninja buildfiles. then run ninja.
    """
    cargo = get_cmd_or_die("cargo")
    config_capi_src_dir = os.path.join(c.CROSS_CHECKS_DIR, "rust-checks",
                                       "config-capi")
    cargo_target_dir = os.path.join(c.CLANG_XCHECK_PLUGIN_BLD,
                                    "config-capi-target")
    config_lib_path = os.path.join(cargo_target_dir,
                                   "debug" if args.debug else "release",
                                   "libc2rust_xcheck_config_capi.a")
    with pb.local.cwd(config_capi_src_dir):
        cargo_args = ["build", "--package", "c2rust-xcheck-config-capi"]
        if not args.debug:
            cargo_args.append("--release")
        with pb.local.env(CARGO_TARGET_DIR=cargo_target_dir):
            invoke(cargo[cargo_args])

    ninja = get_cmd_or_die("ninja")
    # Possible values are Release, Debug, RelWithDebInfo and MinSizeRel
    build_type = "Debug" if args.debug else "RelWithDebInfo"
    ninja_build_file = os.path.join(c.CLANG_XCHECK_PLUGIN_BLD, "build.ninja")
    with pb.local.cwd(c.CLANG_XCHECK_PLUGIN_BLD):
        if os.path.isfile(ninja_build_file):
            prev_build_type = get_ninja_build_type(ninja_build_file)
            run_cmake = prev_build_type != build_type
        else:
            run_cmake = True

        if run_cmake:
            cmake = get_cmd_or_die("cmake")
            max_link_jobs = est_parallel_link_jobs()
            cargs = [
                "-G", "Ninja", c.CLANG_XCHECK_PLUGIN_SRC,
                "-DXCHECK_CONFIG_LIB={}".format(config_lib_path),
                "-DCMAKE_BUILD_TYPE=" + build_type, "-DBUILD_SHARED_LIBS=1",
                "-DLLVM_PARALLEL_LINK_JOBS={}".format(max_link_jobs)
            ]
            if args.with_c2rust_clang:
                cargs.extend([
                    "-DLLVM_DIR={}/lib/cmake/llvm".format(c.LLVM_BLD),
                    "-DClang_DIR={}/lib/cmake/clang".format(c.LLVM_BLD),
                    "-DLLVM_EXTERNAL_LIT={}/bin/llvm-lit".format(c.LLVM_BLD)
                ])
            else:
                # Some distros, e.g., Arch, Ubuntu, ship llvm-lit as /usr/bin/lit
                cargs.append("-DLLVM_EXTERNAL_LIT={}".format(pb.local['lit']))
            invoke(cmake[cargs])
        else:
            logging.debug("found existing ninja.build, not running cmake")
        invoke(ninja)
Пример #21
0
    def test(self):
        rm = get_cmd_or_die('rm')
        ln = get_cmd_or_die('ln')
        for N in (1, 4):
            test = 'example{}'.format(N)
            with pb.local.cwd(self.repo_dir):
                invoke(rm, ['-rf', self.rust_src])

            self._transpile_example(test)
            with pb.local.cwd(self.rust_src):
                # Create a link to the example data files
                invoke(ln, ['-sf', build_path(self.repo_dir, 'example', True)])
                invoke(cargo, ['run'])
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)
Пример #23
0
def configure_and_build_llvm(args) -> None:
    """
    run cmake as needed to generate ninja buildfiles. then run ninja.
    """
    # Possible values are Release, Debug, RelWithDebInfo and MinSizeRel
    build_type = "Debug" if args.debug else "RelWithDebInfo"
    ninja_build_file = os.path.join(c.LLVM_BLD, "build.ninja")
    with pb.local.cwd(c.LLVM_BLD):
        if os.path.isfile(ninja_build_file) and not args.xcode:
            prev_build_type = get_ninja_build_type(ninja_build_file)
            run_cmake = prev_build_type != build_type
        else:
            run_cmake = True

        if run_cmake:
            cmake = get_cmd_or_die("cmake")
            max_link_jobs = est_parallel_link_jobs()
            assertions = "1" if args.assertions else "0"
            cargs = ["-G", "Ninja", c.LLVM_SRC,
                     "-Wno-dev",
                     "-DCMAKE_INSTALL_PREFIX=" + c.LLVM_INSTALL,
                     "-DCMAKE_BUILD_TYPE=" + build_type,
                     "-DLLVM_PARALLEL_LINK_JOBS={}".format(max_link_jobs),
                     "-DLLVM_ENABLE_ASSERTIONS=" + assertions,
                     "-DCMAKE_EXPORT_COMPILE_COMMANDS=1",
                     "-DLLVM_TARGETS_TO_BUILD=host"]

            invoke(cmake[cargs])

            # NOTE: we only generate Xcode project files for IDE support
            # and don't build with them since the cargo build.rs files
            # rely on cmake to build native code.
            if args.xcode:
                cargs[1] = "Xcode"
                # output Xcode project files in a separate dir
                ensure_dir(c.AST_EXPO_PRJ_DIR)
                with pb.local.cwd(c.AST_EXPO_PRJ_DIR):
                    invoke(cmake[cargs])
        else:
            logging.debug("found existing ninja.build, not running cmake")

        # if args.xcode:
        #     xcodebuild = get_cmd_or_die("xcodebuild")
        #     xc_conf_args = ['-configuration', build_type]
        #     xc_args = xc_conf_args + ['-target', 'llvm-config']
        #     invoke(xcodebuild, *xc_args)
        #     xc_args = xc_conf_args + ['-target', 'c2rust-ast-exporter']
        #     invoke(xcodebuild, *xc_args)

        # We must install headers here so our clang tool can reference
        # compiler-internal headers such as stddef.h. This reference is
        # relative to LLVM_INSTALL/bin, which MUST exist for the relative
        # reference to be valid. To force this, we also install llvm-config,
        # since we are building and using it for other purposes.
        nice = get_cmd_or_die("nice")
        ninja = get_cmd_or_die("ninja")
        nice_args = [
            '-n', '19', str(ninja),
            'clangAST',
            'clangFrontend',
            'clangTooling',
            'clangBasic',
            'clangASTMatchers',
            'clangParse',
            'clangSerialization',
            'clangSema',
            'clangEdit',
            'clangAnalysis',
            'clangDriver',
            'clangFormat',
            'clangToolingCore',
            'clangRewrite',
            'clangLex',
            'LLVMMC',
            'LLVMMCParser',
            'LLVMDemangle',
            'LLVMSupport',
            'LLVMOption',
            'LLVMBinaryFormat',
            'LLVMCore',
            'LLVMBitReader',
            'LLVMProfileData',
            'llvm-config',
            'install-clang-headers', 'install-compiler-rt-headers',
            'FileCheck', 'count', 'not']
        (major, _minor, _point) = c.LLVM_VER.split(".")
        major = int(major)
        if major >= 7 and major < 10:
            nice_args += [
                'LLVMDebugInfoMSF',
                'LLVMDebugInfoCodeView']
        if major > 8:
            nice_args.append("install-clang-resource-headers")
        if major == 9:
            nice_args += [
                'LLVMBitstreamReader',
                'LLVMRemarks']
        if major >= 10:
            nice_args.append("LLVMFrontendOpenMP")
        if args.with_clang:
            nice_args.append('clang')
        invoke(nice, *nice_args)

        # Make sure install/bin exists so that we can create a relative path
        # using it in AstExporter.cpp
        os.makedirs(os.path.join(c.LLVM_INSTALL, 'bin'), exist_ok=True)
Пример #24
0
def build_libfakechecks():
    make = get_cmd_or_die("make")
    if not os.path.isfile(os.path.join(c.LIBFAKECHECKS_DIR,
                                       "libfakechecks.so")):
        with pb.local.cwd(c.LIBFAKECHECKS_DIR):
            invoke(make, "all")
Пример #25
0
 def build(self):
     with pb.local.cwd(self.repo_dir):
         invoke(rustc, *self.build_flags)
Пример #26
0
 def init_submodule(self):
     if self.args.regex_examples.fullmatch(self.project_name):
         print_blue("Initializing {}...".format(self.project_name))
         with pb.local.cwd(self.example_dir):
             invoke(git, ['submodule', 'update', '--init', 'repo'])
Пример #27
0
 def deinit_submodule(self):
     if self.args.regex_examples.fullmatch(
             self.project_name) and self.args.deinit:
         print_blue("Deinitializing {}...".format(self.project_name))
         with pb.local.cwd(self.example_dir):
             invoke(git, ['submodule', 'deinit', 'repo', '-f'])
Пример #28
0
 def autotools(self, configure_args=[]):
     with pb.local.cwd(self.repo_dir):
         invoke(pb.local['./autogen.sh'])
         with pb.local.env(CFLAGS="-g -O0"):
             invoke(pb.local['./configure'], configure_args)
Пример #29
0
def configure_and_build_llvm(args) -> None:
    """
    run cmake as needed to generate ninja buildfiles. then run ninja.
    """
    # Possible values are Release, Debug, RelWithDebInfo and MinSizeRel
    build_type = "Debug" if args.debug else "RelWithDebInfo"
    ninja_build_file = os.path.join(c.LLVM_BLD, "build.ninja")
    with pb.local.cwd(c.LLVM_BLD):
        if os.path.isfile(ninja_build_file) and not args.xcode:
            prev_build_type = get_ninja_build_type(ninja_build_file)
            run_cmake = prev_build_type != build_type
        else:
            run_cmake = True

        if run_cmake:
            cmake = get_cmd_or_die("cmake")
            clang = get_cmd_or_die("clang")
            clangpp = get_cmd_or_die("clang++")
            max_link_jobs = est_parallel_link_jobs()
            assertions = "1" if args.assertions else "0"
            ast_ext_dir = "-DLLVM_EXTERNAL_C2RUST_AST_EXPORTER_SOURCE_DIR={}"
            ast_ext_dir = ast_ext_dir.format(c.AST_EXPO_SRC_DIR)
            cargs = ["-G", "Ninja", c.LLVM_SRC,
                     "-Wno-dev",
                     "-DCMAKE_C_COMPILER={}".format(clang),
                     "-DCMAKE_CXX_COMPILER={}".format(clangpp),
                     "-DCMAKE_INSTALL_PREFIX=" + c.LLVM_INSTALL,
                     "-DCMAKE_BUILD_TYPE=" + build_type,
                     "-DLLVM_PARALLEL_LINK_JOBS={}".format(max_link_jobs),
                     "-DLLVM_ENABLE_ASSERTIONS=" + assertions,
                     "-DCMAKE_EXPORT_COMPILE_COMMANDS=1",
                     # required to build LLVM 8 on Debian Jessie
                     "-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=1",
                     ast_ext_dir]

            if on_x86():  # speed up builds on x86 hosts
                cargs.append("-DLLVM_TARGETS_TO_BUILD=X86")
            invoke(cmake[cargs])

            # NOTE: we only generate Xcode project files for IDE support
            # and don't build with them since the cargo build.rs files
            # rely on cmake to build native code.
            if args.xcode:
                cargs[1] = "Xcode"
                # output Xcode project files in a separate dir
                ensure_dir(c.AST_EXPO_PRJ_DIR)
                with pb.local.cwd(c.AST_EXPO_PRJ_DIR):
                    invoke(cmake[cargs])
        else:
            logging.debug("found existing ninja.build, not running cmake")

        # if args.xcode:
        #     xcodebuild = get_cmd_or_die("xcodebuild")
        #     xc_conf_args = ['-configuration', build_type]
        #     xc_args = xc_conf_args + ['-target', 'llvm-config']
        #     invoke(xcodebuild, *xc_args)
        #     xc_args = xc_conf_args + ['-target', 'c2rust-ast-exporter']
        #     invoke(xcodebuild, *xc_args)

        # We must install headers here so our clang tool can reference
        # compiler-internal headers such as stddef.h. This reference is
        # relative to LLVM_INSTALL/bin, which MUST exist for the relative
        # reference to be valid. To force this, we also install llvm-config,
        # since we are building and using it for other purposes.
        ninja = get_cmd_or_die("ninja")
        ninja_args = ['c2rust-ast-exporter', 'clangAstExporter',
                      'llvm-config',
                      'install-clang-headers',
                      'FileCheck', 'count', 'not']
        if args.with_clang:
            ninja_args.append('clang')
        invoke(ninja, *ninja_args)

        # Make sure install/bin exists so that we can create a relative path
        # using it in AstExporter.cpp
        os.makedirs(os.path.join(c.LLVM_INSTALL, 'bin'), exist_ok=True)
Пример #30
0
 def build(self):
     with pb.local.cwd(self.rust_src):
         invoke(cargo, ['build', '-j{}'.format(NUM_JOBS)])