Exemple #1
0
def main():
    root_folder = pathlib.Path(__file__).resolve().parent

    args = parse_parameters(root_folder)

    build_folder = pathlib.Path(args.build_folder)
    if not build_folder.is_absolute():
        build_folder = root_folder.joinpath(build_folder)

    install_folder = pathlib.Path(args.install_folder)
    if not install_folder.is_absolute():
        install_folder = root_folder.joinpath(install_folder)

    targets = ["all"]
    if args.targets is not None:
        targets = args.targets

    utils.download_binutils(root_folder)

    build_targets(build_folder, install_folder, root_folder,
                  create_targets(targets), args.march)
Exemple #2
0
def fetch_llvm_binutils(root_folder, update, shallow, ref):
    """
    Download llvm and binutils or update them if they exist
    :param root_folder: Working directory
    :param update: Boolean indicating whether sources need to be updated or not
    :param ref: The ref to checkout the monorepo to
    """
    p = root_folder.joinpath("llvm-project")
    cwd = p.as_posix()
    if p.is_dir():
        if update:
            utils.print_header("Updating LLVM")

            # Make sure repo is up to date before trying to see if checkout is possible
            subprocess.run(["git", "fetch", "origin"], check=True, cwd=cwd)

            # Explain to the user how to avoid issues if their ref does not exist with
            # a shallow clone.
            if repo_is_shallow(p) and not ref_exists(p, ref):
                utils.print_error(
                    "\nSupplied ref (%s) does not exist, cannot checkout." %
                    ref)
                utils.print_error("To proceed, either:")
                utils.print_error(
                    "\t1. Manage the repo yourself and pass '--no-update' to the script."
                )
                utils.print_error(
                    "\t2. Run 'git -C %s fetch --unshallow origin' to get a complete repository."
                    % cwd)
                utils.print_error(
                    "\t3. Delete '%s' and re-run the script with '-s' + '-b <ref>' to get a full set of refs."
                    % cwd)
                exit(1)

            # Do the update
            subprocess.run(["git", "checkout", ref], check=True, cwd=cwd)
            local_ref = None
            try:
                local_ref = subprocess.check_output(
                    ["git", "symbolic-ref", "-q", "HEAD"],
                    cwd=cwd).decode("utf-8")
            except subprocess.CalledProcessError:
                # This is thrown when we're on a revision that cannot be mapped to a symbolic reference, like a tag
                # or a git hash. Swallow and move on with the rest of our business.
                pass
            if local_ref and local_ref.startswith("refs/heads/"):
                # This is a branch, pull from remote
                subprocess.run([
                    "git", "pull", "--rebase", "origin",
                    local_ref.strip().replace("refs/heads/", "")
                ],
                               check=True,
                               cwd=cwd)
    else:
        utils.print_header("Downloading LLVM")

        extra_args = ()
        if shallow:
            extra_args = ("--depth", "1")
            if ref != "master":
                extra_args += ("--no-single-branch", )
        subprocess.run([
            "git", "clone", *extra_args,
            "https://github.com/llvm/llvm-project",
            p.as_posix()
        ],
                       check=True)
        subprocess.run(["git", "checkout", ref], check=True, cwd=cwd)

    # One might wonder why we are downloading binutils in an LLVM build script :)
    # We need it for the LLVMgold plugin, which can be used for LTO with ld.gold,
    # which at the time of writing this, is how the Google Pixel 3 kernel is built
    # and linked.
    utils.download_binutils(root_folder)