brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 677fa61 Raw
124 lines · bash
1#!/usr/bin/env bash2#===- llvm/utils/docker/scripts/checkout.sh ---------------------===//3#4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5# See https://llvm.org/LICENSE.txt for license information.6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7#8#===-----------------------------------------------------------------------===//9 10set -e11 12function show_usage() {13  cat << EOF14Usage: checkout.sh [options]15 16Checkout git sources into /tmp/clang-build/src. Used inside a docker container.17 18Available options:19  -h|--help           show this help message20  -b|--branch         git branch to checkout, i.e. 'main',21                      'release/19.x'22                      (default: 'main')23  -r|--revision       git revision to checkout24  -c|--cherrypick     revision to cherry-pick. Can be specified multiple times.25                      Cherry-picks are performed in the sorted order using the26                      following command:27                      'git cherry-pick \$rev)'.28EOF29}30 31LLVM_GIT_REV=""32CHERRYPICKS=""33LLVM_BRANCH=""34 35while [[ $# -gt 0 ]]; do36  case "$1" in37    -r|--revision)38      shift39      LLVM_GIT_REV="$1"40      shift41      ;;42    -c|--cherrypick)43      shift44      CHERRYPICKS="$CHERRYPICKS $1"45      shift46      ;;47    -b|--branch)48      shift49      LLVM_BRANCH="$1"50      shift51      ;;52    -h|--help)53      show_usage54      exit 055      ;;56    *)57      echo "Unknown option: $1"58      exit 159  esac60done61 62if [ "$LLVM_BRANCH" == "" ]; then63  LLVM_BRANCH="main"64fi65 66if [ "$LLVM_GIT_REV" != "" ]; then67  GIT_REV_ARG="$LLVM_GIT_REV"68  echo "Checking out git revision $LLVM_GIT_REV."69else70  GIT_REV_ARG=""71  echo "Checking out latest git revision."72fi73 74# Sort cherrypicks and remove duplicates.75CHERRYPICKS="$(echo "$CHERRYPICKS" | xargs -n1 | sort | uniq | xargs)"76 77function apply_cherrypicks() {78  local CHECKOUT_DIR="$1"79 80  [ "$CHERRYPICKS" == "" ] || echo "Applying cherrypicks"81  pushd "$CHECKOUT_DIR"82 83  # This function is always called on a sorted list of cherrypicks.84  for CHERRY_REV in $CHERRYPICKS; do85    echo "Cherry-picking $CHERRY_REV into $CHECKOUT_DIR"86    EMAIL="someone@somewhere.net" git cherry-pick "$CHERRY_REV"87  done88 89  popd90}91 92CLANG_BUILD_DIR=/tmp/clang-build93 94# Get the sources from git.95echo "Checking out sources from git"96mkdir -p "$CLANG_BUILD_DIR/src"97CHECKOUT_DIR="$CLANG_BUILD_DIR/src"98 99echo "Checking out https://github.com/llvm/llvm-project.git to $CHECKOUT_DIR"100git clone -b "$LLVM_BRANCH" --single-branch \101  "https://github.com/llvm/llvm-project.git" \102  "$CHECKOUT_DIR"103 104pushd $CHECKOUT_DIR105git checkout -q $GIT_REV_ARG106popd107 108  # We apply cherrypicks to all repositories regardless of whether the revision109  # changes this repository or not. For repositories not affected by the110  # cherrypick, applying the cherrypick is a no-op.111  apply_cherrypicks "$CHECKOUT_DIR"112 113CHECKSUMS_FILE="/tmp/checksums/checksums.txt"114 115if [ -f "$CHECKSUMS_FILE" ]; then116  echo "Validating checksums for LLVM checkout..."117  python "$(dirname "$0")/llvm_checksum/llvm_checksum.py" -c "$CHECKSUMS_FILE" \118    --partial --multi_dir "$CLANG_BUILD_DIR/src"119else120  echo "Skipping checksumming checks..."121fi122 123echo "Done"124