def fetch_llvm_binutils(root_folder, update, ref, shallow=False): """ 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") subprocess.run(["git", "fetch", "origin"], check=True, cwd=cwd) 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: extra_args = ("--depth", "1") if shallow else () utils.print_header("Downloading LLVM") subprocess.run([ "git", "clone", *extra_args, "git://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.fetch_binutils(root_folder, update, shallow)
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.fetch_binutils(root_folder) build_targets(build_folder, install_folder, root_folder, create_targets(targets), args.march)
def fetch_llvm_binutils(args, dirs): """ Download llvm and binutils or update them if they exist :param args: The args variable generated by parse_parameters :param dirs: An instance of the Directories class with the paths to use """ if args.use_good_revision: ref = GOOD_REVISION else: ref = args.branch llvm_path = dirs.llvm_folder llvm_posix = llvm_path.as_posix() if llvm_path.is_dir(): if args.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=llvm_posix) # Explain to the user how to avoid issues if their ref does not exist with # a shallow clone. if repo_is_shallow(llvm_path) and not ref_exists(llvm_path, 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=llvm_posix) local_ref = None try: local_ref = subprocess.check_output( ["git", "symbolic-ref", "-q", "HEAD"], cwd=llvm_posix).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=llvm_posix) else: utils.print_header("Downloading LLVM") extra_args = () if args.shallow_clone: extra_args = ("--depth", "1") if ref != "master": extra_args += ("--no-single-branch", ) subprocess.run([ "git", "clone", *extra_args, "https://github.com/llvm/llvm-project", llvm_posix ], check=True) subprocess.run(["git", "checkout", ref], check=True, cwd=llvm_posix) # 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.fetch_binutils(dirs.root_folder, args.update)