121
|
1 #!/bin/bash
|
|
2 #===- llvm/utils/docker/build_docker_image.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 set -e
|
|
11
|
|
12 IMAGE_SOURCE=""
|
|
13 DOCKER_REPOSITORY=""
|
|
14 DOCKER_TAG=""
|
|
15 BUILDSCRIPT_ARGS=""
|
|
16
|
|
17 function show_usage() {
|
|
18 cat << EOF
|
|
19 Usage: build_docker_image.sh [options] [-- [cmake_args]...]
|
|
20
|
|
21 Available options:
|
|
22 General:
|
|
23 -h|--help show this help message
|
|
24 Docker-specific:
|
|
25 -s|--source image source dir (i.e. debian8, nvidia-cuda, etc)
|
|
26 -d|--docker-repository docker repository for the image
|
|
27 -t|--docker-tag docker tag for the image
|
|
28 LLVM-specific:
|
|
29 -b|--branch svn branch to checkout, i.e. 'trunk',
|
|
30 'branches/release_40'
|
|
31 (default: 'trunk')
|
|
32 -r|--revision svn revision to checkout
|
|
33 -p|--llvm-project name of an svn project to checkout. Will also add the
|
|
34 project to a list LLVM_ENABLE_PROJECTS, passed to CMake.
|
|
35 For clang, please use 'clang', not 'cfe'.
|
|
36 Project 'llvm' is always included and ignored, if
|
|
37 specified.
|
|
38 Can be specified multiple times.
|
|
39 -i|--install-target name of a cmake install target to build and include in
|
|
40 the resulting archive. Can be specified multiple times.
|
|
41 -c|--checksums name of a file, containing checksums of llvm checkout.
|
|
42 Script will fail if checksums of the checkout do not
|
|
43 match.
|
|
44
|
|
45 Required options: --source and --docker-repository, at least one
|
|
46 --install-target.
|
|
47
|
|
48 All options after '--' are passed to CMake invocation.
|
|
49
|
|
50 For example, running:
|
|
51 $ build_docker_image.sh -s debian8 -d mydocker/debian8-clang -t latest \
|
|
52 -p clang -i install-clang -i install-clang-headers
|
|
53 will produce two docker images:
|
|
54 mydocker/debian8-clang-build:latest - an intermediate image used to compile
|
|
55 clang.
|
|
56 mydocker/clang-debian8:latest - a small image with preinstalled clang.
|
|
57 Please note that this example produces a not very useful installation, since it
|
|
58 doesn't override CMake defaults, which produces a Debug and non-boostrapped
|
|
59 version of clang.
|
|
60
|
|
61 To get a 2-stage clang build, you could use this command:
|
|
62 $ ./build_docker_image.sh -s debian8 -d mydocker/clang-debian8 -t "latest" \
|
|
63 -p clang -i stage2-install-clang -i stage2-install-clang-headers \
|
|
64 -- \
|
|
65 -DLLVM_TARGETS_TO_BUILD=Native -DCMAKE_BUILD_TYPE=Release \
|
|
66 -DBOOTSTRAP_CMAKE_BUILD_TYPE=Release \
|
|
67 -DCLANG_ENABLE_BOOTSTRAP=ON \
|
|
68 -DCLANG_BOOTSTRAP_TARGETS="install-clang;install-clang-headers"
|
|
69 EOF
|
|
70 }
|
|
71
|
|
72 CHECKSUMS_FILE=""
|
|
73 SEEN_INSTALL_TARGET=0
|
|
74 while [[ $# -gt 0 ]]; do
|
|
75 case "$1" in
|
|
76 -h|--help)
|
|
77 show_usage
|
|
78 exit 0
|
|
79 ;;
|
|
80 -s|--source)
|
|
81 shift
|
|
82 IMAGE_SOURCE="$1"
|
|
83 shift
|
|
84 ;;
|
|
85 -d|--docker-repository)
|
|
86 shift
|
|
87 DOCKER_REPOSITORY="$1"
|
|
88 shift
|
|
89 ;;
|
|
90 -t|--docker-tag)
|
|
91 shift
|
|
92 DOCKER_TAG="$1"
|
|
93 shift
|
|
94 ;;
|
|
95 -i|--install-target|-r|--revision|-b|--branch|-p|--llvm-project)
|
|
96 if [ "$1" == "-i" ] || [ "$1" == "--install-target" ]; then
|
|
97 SEEN_INSTALL_TARGET=1
|
|
98 fi
|
|
99 BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS $1 $2"
|
|
100 shift 2
|
|
101 ;;
|
|
102 -c|--checksums)
|
|
103 shift
|
|
104 CHECKSUMS_FILE="$1"
|
|
105 shift
|
|
106 ;;
|
|
107 --)
|
|
108 shift
|
|
109 BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS -- $*"
|
|
110 shift $#
|
|
111 ;;
|
|
112 *)
|
|
113 echo "Unknown argument $1"
|
|
114 exit 1
|
|
115 ;;
|
|
116 esac
|
|
117 done
|
|
118
|
|
119 command -v docker >/dev/null ||
|
|
120 {
|
|
121 echo "Docker binary cannot be found. Please install Docker to use this script."
|
|
122 exit 1
|
|
123 }
|
|
124
|
|
125 if [ "$IMAGE_SOURCE" == "" ]; then
|
|
126 echo "Required argument missing: --source"
|
|
127 exit 1
|
|
128 fi
|
|
129
|
|
130 if [ "$DOCKER_REPOSITORY" == "" ]; then
|
|
131 echo "Required argument missing: --docker-repository"
|
|
132 exit 1
|
|
133 fi
|
|
134
|
|
135 if [ $SEEN_INSTALL_TARGET -eq 0 ]; then
|
|
136 echo "Please provide at least one --install-target"
|
|
137 exit 1
|
|
138 fi
|
|
139
|
|
140 SOURCE_DIR=$(dirname $0)
|
|
141 if [ ! -d "$SOURCE_DIR/$IMAGE_SOURCE" ]; then
|
|
142 echo "No sources for '$IMAGE_SOURCE' were found in $SOURCE_DIR"
|
|
143 exit 1
|
|
144 fi
|
|
145
|
|
146 BUILD_DIR=$(mktemp -d)
|
|
147 trap "rm -rf $BUILD_DIR" EXIT
|
|
148 echo "Using a temporary directory for the build: $BUILD_DIR"
|
|
149
|
|
150 cp -r "$SOURCE_DIR/$IMAGE_SOURCE" "$BUILD_DIR/$IMAGE_SOURCE"
|
|
151 cp -r "$SOURCE_DIR/scripts" "$BUILD_DIR/scripts"
|
|
152
|
|
153 mkdir "$BUILD_DIR/checksums"
|
|
154 if [ "$CHECKSUMS_FILE" != "" ]; then
|
|
155 cp "$CHECKSUMS_FILE" "$BUILD_DIR/checksums/checksums.txt"
|
|
156 fi
|
|
157
|
|
158 if [ "$DOCKER_TAG" != "" ]; then
|
|
159 DOCKER_TAG=":$DOCKER_TAG"
|
|
160 fi
|
|
161
|
|
162 echo "Building from $IMAGE_SOURCE"
|
|
163 echo "Building $DOCKER_REPOSITORY-build$DOCKER_TAG"
|
|
164 docker build -t "$DOCKER_REPOSITORY-build$DOCKER_TAG" \
|
|
165 --build-arg "buildscript_args=$BUILDSCRIPT_ARGS" \
|
|
166 -f "$BUILD_DIR/$IMAGE_SOURCE/build/Dockerfile" \
|
|
167 "$BUILD_DIR"
|
|
168
|
|
169 echo "Copying clang installation to release image sources"
|
|
170 docker run -v "$BUILD_DIR/$IMAGE_SOURCE:/workspace" "$DOCKER_REPOSITORY-build$DOCKER_TAG" \
|
|
171 cp /tmp/clang.tar.gz /workspace/release
|
|
172
|
|
173 echo "Building release image"
|
|
174 docker build -t "${DOCKER_REPOSITORY}${DOCKER_TAG}" \
|
|
175 "$BUILD_DIR/$IMAGE_SOURCE/release"
|
|
176
|
|
177 echo "Done"
|