• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  -r|--revision       svn revision to checkout
25  -c|--cherrypick     revision to cherry-pick. Can be specified multiple times.
26                      Cherry-picks are performed in the sorted order using the
27                      following command:
28                      'svn patch <(svn diff -c \$rev)'.
29  -p|--llvm-project   name of an svn project to checkout.
30                      For clang, please use 'clang', not 'cfe'.
31                      Project 'llvm' is always included and ignored, if
32                      specified.
33                      Can be specified multiple times.
34EOF
35}
36
37LLVM_SVN_REV=""
38CHERRYPICKS=""
39LLVM_BRANCH=""
40# We always checkout llvm
41LLVM_PROJECTS="llvm"
42
43function contains_project() {
44  local TARGET_PROJ="$1"
45  local PROJ
46  for PROJ in $LLVM_PROJECTS; do
47    if [ "$PROJ" == "$TARGET_PROJ" ]; then
48      return 0
49    fi
50  done
51  return 1
52}
53
54while [[ $# -gt 0 ]]; do
55  case "$1" in
56    -r|--revision)
57      shift
58      LLVM_SVN_REV="$1"
59      shift
60      ;;
61    -c|--cherrypick)
62      shift
63      CHERRYPICKS="$CHERRYPICKS $1"
64      shift
65      ;;
66    -b|--branch)
67      shift
68      LLVM_BRANCH="$1"
69      shift
70      ;;
71    -p|--llvm-project)
72      shift
73      PROJ="$1"
74      shift
75
76      if [ "$PROJ" == "cfe" ]; then
77        PROJ="clang"
78      fi
79
80      if ! contains_project "$PROJ" ; then
81        if [ "$PROJ" == "clang-tools-extra" ] && [ ! contains_project "clang" ]; then
82          echo "Project 'clang-tools-extra' specified before 'clang'. Adding 'clang' to a list of projects first."
83          LLVM_PROJECTS="$LLVM_PROJECTS clang"
84        fi
85        LLVM_PROJECTS="$LLVM_PROJECTS $PROJ"
86      else
87        echo "Project '$PROJ' is already enabled, ignoring extra occurrences."
88      fi
89      ;;
90    -h|--help)
91      show_usage
92      exit 0
93      ;;
94    *)
95      echo "Unknown option: $1"
96      exit 1
97  esac
98done
99
100if [ "$LLVM_BRANCH" == "" ]; then
101  LLVM_BRANCH="trunk"
102fi
103
104if [ "$LLVM_SVN_REV" != "" ]; then
105  SVN_REV_ARG="-r$LLVM_SVN_REV"
106  echo "Checking out svn revision r$LLVM_SVN_REV."
107else
108  SVN_REV_ARG=""
109  echo "Checking out latest svn revision."
110fi
111
112# Sort cherrypicks and remove duplicates.
113CHERRYPICKS="$(echo "$CHERRYPICKS" | xargs -n1 | sort | uniq | xargs)"
114
115function apply_cherrypicks() {
116  local CHECKOUT_DIR="$1"
117
118  [ "$CHERRYPICKS" == "" ] || echo "Applying cherrypicks"
119  pushd "$CHECKOUT_DIR"
120
121  # This function is always called on a sorted list of cherrypicks.
122  for CHERRY_REV in $CHERRYPICKS; do
123    echo "Cherry-picking r$CHERRY_REV into $CHECKOUT_DIR"
124
125    local PATCH_FILE="$(mktemp)"
126    svn diff -c $CHERRY_REV > "$PATCH_FILE"
127    svn patch "$PATCH_FILE"
128    rm "$PATCH_FILE"
129  done
130
131  popd
132}
133
134CLANG_BUILD_DIR=/tmp/clang-build
135
136# Get the sources from svn.
137echo "Checking out sources from svn"
138mkdir -p "$CLANG_BUILD_DIR/src"
139for LLVM_PROJECT in $LLVM_PROJECTS; do
140  if [ "$LLVM_PROJECT" == "clang" ]; then
141    SVN_PROJECT="cfe"
142  else
143    SVN_PROJECT="$LLVM_PROJECT"
144  fi
145
146  if [ "$SVN_PROJECT" != "clang-tools-extra" ]; then
147    CHECKOUT_DIR="$CLANG_BUILD_DIR/src/$LLVM_PROJECT"
148  else
149    CHECKOUT_DIR="$CLANG_BUILD_DIR/src/clang/tools/extra"
150  fi
151
152  echo "Checking out https://llvm.org/svn/llvm-project/$SVN_PROJECT to $CHECKOUT_DIR"
153  svn co -q $SVN_REV_ARG \
154    "https://llvm.org/svn/llvm-project/$SVN_PROJECT/$LLVM_BRANCH" \
155    "$CHECKOUT_DIR"
156
157  # We apply cherrypicks to all repositories regardless of whether the revision
158  # changes this repository or not. For repositories not affected by the
159  # cherrypick, applying the cherrypick is a no-op.
160  apply_cherrypicks "$CHECKOUT_DIR"
161done
162
163CHECKSUMS_FILE="/tmp/checksums/checksums.txt"
164
165if [ -f "$CHECKSUMS_FILE" ]; then
166  echo "Validating checksums for LLVM checkout..."
167  python "$(dirname $0)/llvm_checksum/llvm_checksum.py" -c "$CHECKSUMS_FILE" \
168    --partial --multi_dir "$CLANG_BUILD_DIR/src"
169else
170  echo "Skipping checksumming checks..."
171fi
172
173echo "Done"
174