2 #===- llvm/utils/docker/scripts/checkout.sh ---------------------===//
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-exception
8 #===-----------------------------------------------------------------------===//
12 function show_usage
() {
14 Usage: checkout.sh [options]
16 Checkout svn sources into /tmp/clang-build/src. Used inside a docker container.
19 -h|--help show this help message
20 -b|--branch svn branch to checkout, i.e. 'trunk',
23 -r|--revision svn revision to checkout
24 -c|--cherrypick revision to cherry-pick. Can be specified multiple times.
25 Cherry-picks are performed in the sorted order using the
27 'svn patch <(svn diff -c \$rev)'.
28 -p|--llvm-project name of an svn project to checkout.
29 For clang, please use 'clang', not 'cfe'.
30 Project 'llvm' is always included and ignored, if
32 Can be specified multiple times.
39 # We always checkout llvm
42 function contains_project
() {
43 local TARGET_PROJ
="$1"
45 for PROJ
in $LLVM_PROJECTS; do
46 if [ "$PROJ" == "$TARGET_PROJ" ]; then
53 while [[ $# -gt 0 ]]; do
62 CHERRYPICKS
="$CHERRYPICKS $1"
75 if [ "$PROJ" == "cfe" ]; then
79 if ! contains_project
"$PROJ" ; then
80 if [ "$PROJ" == "clang-tools-extra" ] && [ ! contains_project
"clang" ]; then
81 echo "Project 'clang-tools-extra' specified before 'clang'. Adding 'clang' to a list of projects first."
82 LLVM_PROJECTS
="$LLVM_PROJECTS clang"
84 LLVM_PROJECTS
="$LLVM_PROJECTS $PROJ"
86 echo "Project '$PROJ' is already enabled, ignoring extra occurrences."
94 echo "Unknown option: $1"
99 if [ "$LLVM_BRANCH" == "" ]; then
103 if [ "$LLVM_SVN_REV" != "" ]; then
104 SVN_REV_ARG
="-r$LLVM_SVN_REV"
105 echo "Checking out svn revision r$LLVM_SVN_REV."
108 echo "Checking out latest svn revision."
111 # Sort cherrypicks and remove duplicates.
112 CHERRYPICKS
="$(echo "$CHERRYPICKS" | xargs -n1 | sort | uniq | xargs)"
114 function apply_cherrypicks
() {
115 local CHECKOUT_DIR
="$1"
117 [ "$CHERRYPICKS" == "" ] ||
echo "Applying cherrypicks"
118 pushd "$CHECKOUT_DIR"
120 # This function is always called on a sorted list of cherrypicks.
121 for CHERRY_REV
in $CHERRYPICKS; do
122 echo "Cherry-picking r$CHERRY_REV into $CHECKOUT_DIR"
124 local PATCH_FILE
="$(mktemp)"
125 svn
diff -c $CHERRY_REV > "$PATCH_FILE"
126 svn
patch "$PATCH_FILE"
133 CLANG_BUILD_DIR
=/tmp
/clang-build
135 # Get the sources from svn.
136 echo "Checking out sources from svn"
137 mkdir
-p "$CLANG_BUILD_DIR/src"
138 for LLVM_PROJECT
in $LLVM_PROJECTS; do
139 if [ "$LLVM_PROJECT" == "clang" ]; then
142 SVN_PROJECT
="$LLVM_PROJECT"
145 if [ "$SVN_PROJECT" != "clang-tools-extra" ]; then
146 CHECKOUT_DIR
="$CLANG_BUILD_DIR/src/$LLVM_PROJECT"
148 CHECKOUT_DIR
="$CLANG_BUILD_DIR/src/clang/tools/extra"
151 echo "Checking out https://llvm.org/svn/llvm-project/$SVN_PROJECT to $CHECKOUT_DIR"
152 svn co
-q $SVN_REV_ARG \
153 "https://llvm.org/svn/llvm-project/$SVN_PROJECT/$LLVM_BRANCH" \
156 # We apply cherrypicks to all repositories regardless of whether the revision
157 # changes this repository or not. For repositories not affected by the
158 # cherrypick, applying the cherrypick is a no-op.
159 apply_cherrypicks
"$CHECKOUT_DIR"
162 CHECKSUMS_FILE
="/tmp/checksums/checksums.txt"
164 if [ -f "$CHECKSUMS_FILE" ]; then
165 echo "Validating checksums for LLVM checkout..."
166 python
"$(dirname $0)/llvm_checksum/llvm_checksum.py" -c "$CHECKSUMS_FILE" \
167 --partial --multi_dir "$CLANG_BUILD_DIR/src"
169 echo "Skipping checksumming checks..."