1#!/usr/bin/env bash 2#===- llvm/utils/docker/scripts/checkout.sh ---------------------===// 3# 4# The LLVM Compiler Infrastructure 5# 6# This file is distributed under the University of Illinois Open Source 7# License. See LICENSE.TXT for details. 8# 9#===-----------------------------------------------------------------------===// 10 11set -e 12 13function show_usage() { 14 cat << EOF 15Usage: checkout.sh [options] 16 17Checkout svn sources into /tmp/clang-build/src. Used inside a docker container. 18 19Available options: 20 -h|--help show this help message 21 -b|--branch svn branch to checkout, i.e. 'trunk', 22 'branches/release_40' 23 (default: 'trunk') 24 -p|--llvm-project name of an svn project to checkout. 25 For clang, please use 'clang', not 'cfe'. 26 Project 'llvm' is always included and ignored, if 27 specified. 28 Can be specified multiple times. 29EOF 30} 31 32LLVM_BRANCH="" 33# We always checkout llvm 34LLVM_PROJECTS="llvm" 35SOURCE_DIR="" 36 37function contains_project() { 38 local TARGET_PROJ="$1" 39 local PROJ 40 for PROJ in $LLVM_PROJECTS; do 41 if [ "$PROJ" == "$TARGET_PROJ" ]; then 42 return 0 43 fi 44 done 45 return 1 46} 47 48while [[ $# -gt 0 ]]; do 49 case "$1" in 50 --to) 51 shift 52 SOURCE_DIR="$1" 53 shift 54 ;; 55 -b|--branch) 56 shift 57 LLVM_BRANCH="$1" 58 shift 59 ;; 60 -p|--llvm-project) 61 shift 62 PROJ="$1" 63 shift 64 65 if [ "$PROJ" == "cfe" ]; then 66 PROJ="clang" 67 fi 68 69 if ! contains_project "$PROJ" ; then 70 if [ "$PROJ" == "clang-tools-extra" ] && [ ! contains_project "clang" ]; then 71 echo "Project 'clang-tools-extra' specified before 'clang'. Adding 'clang' to a list of projects first." 72 LLVM_PROJECTS="$LLVM_PROJECTS clang" 73 fi 74 LLVM_PROJECTS="$LLVM_PROJECTS $PROJ" 75 else 76 echo "Project '$PROJ' is already enabled, ignoring extra occurrences." 77 fi 78 ;; 79 -h|--help) 80 show_usage 81 exit 0 82 ;; 83 *) 84 echo "Unknown option: $1" 85 exit 1 86 esac 87done 88 89if [ "$SOURCE_DIR" == "" ]; then 90 echo "Must specify checkout directory using --to" 91 exit 1 92fi 93 94if [ "$LLVM_BRANCH" == "" ]; then 95 GIT_BRANCH_ARG="" 96else 97 GIT_BRANCH_ARG="--branch $LLVM_BRANCH" 98fi 99 100if [ "$LLVM_SVN_REV" != "" ]; then 101 SVN_REV_ARG="-r$LLVM_SVN_REV" 102 echo "Checking out svn revision r$LLVM_SVN_REV." 103else 104 SVN_REV_ARG="" 105 echo "Checking out latest svn revision." 106fi 107 108# Get the sources from svn. 109echo "Checking out sources from git" 110 111for LLVM_PROJECT in $LLVM_PROJECTS; do 112 if [ "$LLVM_PROJECT" == "llvm" ]; then 113 CHECKOUT_DIR="$SOURCE_DIR" 114 elif [ "$LLVM_PROJECT" == "libcxx" ] || [ "$LLVM_PROJECT" == "libcxxabi" ] || [ "$LLVM_PROJECT" == "compiler-rt" ]; then 115 CHECKOUT_DIR="$SOURCE_DIR/projects/$LLVM_PROJECT" 116 elif [ "$LLVM_PROJECT" == "clang" ]; then 117 CHECKOUT_DIR="$SOURCE_DIR/tools/clang" 118 elif [ "$LLVM_PROJECT" == "clang-tools-extra" ]; then 119 CHECKOUT_DIR="$SOURCE_DIR/tools/clang/tools/extra" 120 else 121 CHECKOUT_DIR="$SOURCE_DIR/$LLVM_PROJECT" 122 fi 123 124 echo "Checking out https://git.llvm.org/git/$LLVM_PROJECT to $CHECKOUT_DIR" 125 git clone --depth=1 $GIT_BRANCH_ARG \ 126 "https://git.llvm.org/git/$LLVM_PROJECT.git" \ 127 "$CHECKOUT_DIR" 128done 129 130echo "Done" 131