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