Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 50f681d

Browse files
committed
[Dockerfiles] Split checkout and build scripts into separate files.
Summary: This is a small refactoring to extract the svn checkout code from the build script used inside the docker image. This would give more flexibility if more than a single invocation of cmake is needed inside the docker image. User-facing interface (build_docker_image.sh) hasn't changed, only the internal scripts running inside the build container are affected. Reviewers: ioeric Reviewed By: ioeric Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D45868 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330412 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a2fbfc9 commit 50f681d

File tree

6 files changed

+245
-188
lines changed

6 files changed

+245
-188
lines changed

utils/docker/build_docker_image.sh

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ IMAGE_SOURCE=""
1313
DOCKER_REPOSITORY=""
1414
DOCKER_TAG=""
1515
BUILDSCRIPT_ARGS=""
16+
CHECKOUT_ARGS=""
17+
CMAKE_ENABLED_PROJECTS=""
1618

1719
function show_usage() {
1820
cat << EOF
@@ -25,7 +27,7 @@ Available options:
2527
-s|--source image source dir (i.e. debian8, nvidia-cuda, etc)
2628
-d|--docker-repository docker repository for the image
2729
-t|--docker-tag docker tag for the image
28-
LLVM-specific:
30+
Checkout arguments:
2931
-b|--branch svn branch to checkout, i.e. 'trunk',
3032
'branches/release_40'
3133
(default: 'trunk')
@@ -40,11 +42,12 @@ Available options:
4042
Project 'llvm' is always included and ignored, if
4143
specified.
4244
Can be specified multiple times.
43-
-i|--install-target name of a cmake install target to build and include in
44-
the resulting archive. Can be specified multiple times.
4545
-c|--checksums name of a file, containing checksums of llvm checkout.
4646
Script will fail if checksums of the checkout do not
4747
match.
48+
Build-specific:
49+
-i|--install-target name of a cmake install target to build and include in
50+
the resulting archive. Can be specified multiple times.
4851
4952
Required options: --source and --docker-repository, at least one
5053
--install-target.
@@ -75,6 +78,7 @@ EOF
7578

7679
CHECKSUMS_FILE=""
7780
SEEN_INSTALL_TARGET=0
81+
SEEN_CMAKE_ARGS=0
7882
while [[ $# -gt 0 ]]; do
7983
case "$1" in
8084
-h|--help)
@@ -96,11 +100,26 @@ while [[ $# -gt 0 ]]; do
96100
DOCKER_TAG="$1"
97101
shift
98102
;;
99-
-i|--install-target|-r|--revision|-c|-cherrypick|-b|--branch|-p|--llvm-project)
100-
if [ "$1" == "-i" ] || [ "$1" == "--install-target" ]; then
101-
SEEN_INSTALL_TARGET=1
102-
fi
103+
-r|--revision|-c|-cherrypick|-b|--branch)
104+
CHECKOUT_ARGS="$CHECKOUT_ARGS $1 $2"
105+
shift 2
106+
;;
107+
-i|--install-target)
108+
SEEN_INSTALL_TARGET=1
103109
BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS $1 $2"
110+
shift 2
111+
;;
112+
-p|--llvm-project)
113+
PROJ="$2"
114+
if [ "$PROJ" == "cfe" ]; then
115+
PROJ="clang"
116+
fi
117+
118+
CHECKOUT_ARGS="$CHECKOUT_ARGS $1 $PROJ"
119+
if [ "$PROJ" != "clang-tools-extra" ]; then
120+
CMAKE_ENABLED_PROJECTS="$CMAKE_ENABLED_PROJECTS:$PROJ"
121+
fi
122+
104123
shift 2
105124
;;
106125
-c|--checksums)
@@ -111,6 +130,7 @@ while [[ $# -gt 0 ]]; do
111130
--)
112131
shift
113132
BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS -- $*"
133+
SEEN_CMAKE_ARGS=1
114134
shift $#
115135
;;
116136
*)
@@ -120,6 +140,17 @@ while [[ $# -gt 0 ]]; do
120140
esac
121141
done
122142

143+
144+
if [ "$CMAKE_ENABLED_PROJECTS" != "" ]; then
145+
# Remove the leading ':' character.
146+
CMAKE_ENABLED_PROJECTS="${CMAKE_ENABLED_PROJECTS:1}"
147+
148+
if [[ $SEEN_CMAKE_ARGS -eq 0 ]]; then
149+
BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS --"
150+
fi
151+
BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS -DLLVM_ENABLE_PROJECTS=$CMAKE_ENABLED_PROJECTS"
152+
fi
153+
123154
command -v docker >/dev/null ||
124155
{
125156
echo "Docker binary cannot be found. Please install Docker to use this script."
@@ -165,6 +196,7 @@ fi
165196

166197
echo "Building ${DOCKER_REPOSITORY}${DOCKER_TAG} from $IMAGE_SOURCE"
167198
docker build -t "${DOCKER_REPOSITORY}${DOCKER_TAG}" \
199+
--build-arg "checkout_args=$CHECKOUT_ARGS" \
168200
--build-arg "buildscript_args=$BUILDSCRIPT_ARGS" \
169201
-f "$BUILD_DIR/$IMAGE_SOURCE/Dockerfile" \
170202
"$BUILD_DIR"

utils/docker/debian8/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ RUN mkdir /tmp/cmake-install && cd /tmp/cmake-install && \
4141

4242
ADD checksums /tmp/checksums
4343
ADD scripts /tmp/scripts
44-
# Arguments passed to build_install_clang.sh.
45-
ARG buildscript_args
44+
45+
# Checkout the source code.
46+
ARG checkout_args
47+
RUN /tmp/scripts/checkout.sh ${checkout_args}
4648
# Run the build. Results of the build will be available at /tmp/clang-install/.
47-
RUN /tmp/scripts/build_install_llvm.sh ${buildscript_args}
49+
ARG buildscript_args
50+
RUN /tmp/scripts/build_install_llvm.sh --to /tmp/clang-install ${buildscript_args}
4851

4952

5053
# Stage 2. Produce a minimal release image with build results.

utils/docker/example/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ LABEL maintainer "Maintainer <maintainer@email>"
1919

2020
ADD checksums /tmp/checksums
2121
ADD scripts /tmp/scripts
22-
# Arguments passed to build_install_clang.sh.
22+
23+
# Checkout the source code.
24+
ARG checkout_args
25+
RUN /tmp/scripts/checkout.sh ${checkout_args}
26+
# Run the build. Results of the build will be available at /tmp/clang-install/.
2327
ARG buildscript_args
24-
# Run the build. Results of the build will be available as /tmp/clang-install.
25-
RUN /tmp/scripts/build_install_llvm.sh ${buildscript_args}
28+
RUN /tmp/scripts/build_install_llvm.sh --to /tmp/clang-install ${buildscript_args}
2629

2730

2831
# Stage 2. Produce a minimal release image with build results.

utils/docker/nvidia-cuda/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ RUN apt-get update && \
1717

1818
ADD checksums /tmp/checksums
1919
ADD scripts /tmp/scripts
20-
# Arguments passed to build_install_clang.sh.
21-
ARG buildscript_args
20+
21+
# Checkout the source code.
22+
ARG checkout_args
23+
RUN /tmp/scripts/checkout.sh ${checkout_args}
2224
# Run the build. Results of the build will be available at /tmp/clang-install/.
23-
RUN /tmp/scripts/build_install_llvm.sh ${buildscript_args}
25+
ARG buildscript_args
26+
RUN /tmp/scripts/build_install_llvm.sh --to /tmp/clang-install ${buildscript_args}
2427

2528

2629
# Stage 2. Produce a minimal release image with build results.

utils/docker/scripts/build_install_llvm.sh

Lines changed: 15 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -14,112 +14,35 @@ function show_usage() {
1414
cat << EOF
1515
Usage: build_install_llvm.sh [options] -- [cmake-args]
1616
17-
Checkout svn sources and run cmake with the specified arguments. Used
18-
inside docker container.
17+
Run cmake with the specified arguments. Used inside docker container.
1918
Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into
20-
/tmp/clang-install/ directory.
19+
the directory specified by --to option.
2120
2221
Available options:
2322
-h|--help show this help message
24-
-b|--branch svn branch to checkout, i.e. 'trunk',
25-
'branches/release_40'
26-
(default: 'trunk')
27-
-r|--revision svn revision to checkout
28-
-c|--cherrypick revision to cherry-pick. Can be specified multiple times.
29-
Cherry-picks are performed in the sorted order using the
30-
following command:
31-
'svn patch <(svn diff -c \$rev)'.
32-
-p|--llvm-project name of an svn project to checkout. Will also add the
33-
project to a list LLVM_ENABLE_PROJECTS, passed to CMake.
34-
For clang, please use 'clang', not 'cfe'.
35-
Project 'llvm' is always included and ignored, if
36-
specified.
37-
Can be specified multiple times.
3823
-i|--install-target name of a cmake install target to build and include in
3924
the resulting archive. Can be specified multiple times.
40-
Required options: At least one --install-target.
25+
--to destination directory where to install the targets.
26+
Required options: --to, at least one --install-target.
4127
4228
All options after '--' are passed to CMake invocation.
4329
EOF
4430
}
4531

46-
LLVM_SVN_REV=""
47-
CHERRYPICKS=""
48-
LLVM_BRANCH=""
4932
CMAKE_ARGS=""
5033
CMAKE_INSTALL_TARGETS=""
51-
# We always checkout llvm
52-
LLVM_PROJECTS="llvm"
53-
CMAKE_LLVM_ENABLE_PROJECTS=""
54-
CLANG_TOOLS_EXTRA_ENABLED=0
55-
56-
function contains_project() {
57-
local TARGET_PROJ="$1"
58-
local PROJ
59-
for PROJ in $LLVM_PROJECTS; do
60-
if [ "$PROJ" == "$TARGET_PROJ" ]; then
61-
return 0
62-
fi
63-
done
64-
return 1
65-
}
66-
67-
function append_project() {
68-
local PROJ="$1"
69-
70-
LLVM_PROJECTS="$LLVM_PROJECTS $PROJ"
71-
if [ "$CMAKE_LLVM_ENABLE_PROJECTS" != "" ]; then
72-
CMAKE_LLVM_ENABLE_PROJECTS="$CMAKE_LLVM_ENABLE_PROJECTS;$PROJ"
73-
else
74-
CMAKE_LLVM_ENABLE_PROJECTS="$PROJ"
75-
fi
76-
}
34+
CLANG_INSTALL_DIR=""
7735

7836
while [[ $# -gt 0 ]]; do
7937
case "$1" in
80-
-r|--revision)
81-
shift
82-
LLVM_SVN_REV="$1"
83-
shift
84-
;;
85-
-c|--cherrypick)
86-
shift
87-
CHERRYPICKS="$CHERRYPICKS $1"
88-
shift
89-
;;
90-
-b|--branch)
38+
-i|--install-target)
9139
shift
92-
LLVM_BRANCH="$1"
40+
CMAKE_INSTALL_TARGETS="$CMAKE_INSTALL_TARGETS $1"
9341
shift
9442
;;
95-
-p|--llvm-project)
43+
--to)
9644
shift
97-
PROJ="$1"
98-
shift
99-
100-
if [ "$PROJ" == "cfe" ]; then
101-
PROJ="clang"
102-
fi
103-
104-
if [ "$PROJ" == "clang-tools-extra" ]; then
105-
if [ $CLANG_TOOLS_EXTRA_ENABLED -ne 0 ]; then
106-
echo "Project 'clang-tools-extra' is already enabled, ignoring extra occurrences."
107-
else
108-
CLANG_TOOLS_EXTRA_ENABLED=1
109-
fi
110-
111-
continue
112-
fi
113-
114-
if ! contains_project "$PROJ" ; then
115-
append_project "$PROJ"
116-
else
117-
echo "Project '$PROJ' is already enabled, ignoring extra occurrences."
118-
fi
119-
;;
120-
-i|--install-target)
121-
shift
122-
CMAKE_INSTALL_TARGETS="$CMAKE_INSTALL_TARGETS $1"
45+
CLANG_INSTALL_DIR="$1"
12346
shift
12447
;;
12548
--)
@@ -142,109 +65,29 @@ if [ "$CMAKE_INSTALL_TARGETS" == "" ]; then
14265
exit 1
14366
fi
14467

145-
if [ $CLANG_TOOLS_EXTRA_ENABLED -ne 0 ]; then
146-
if ! contains_project "clang"; then
147-
echo "Project 'clang-tools-extra' was enabled without 'clang'."
148-
echo "Adding 'clang' to a list of projects."
149-
150-
append_project "clang"
151-
fi
152-
fi
153-
154-
if [ "$LLVM_BRANCH" == "" ]; then
155-
LLVM_BRANCH="trunk"
156-
fi
157-
158-
if [ "$LLVM_SVN_REV" != "" ]; then
159-
SVN_REV_ARG="-r$LLVM_SVN_REV"
160-
echo "Checking out svn revision r$LLVM_SVN_REV."
161-
else
162-
SVN_REV_ARG=""
163-
echo "Checking out latest svn revision."
68+
if [ "$CLANG_INSTALL_DIR" == "" ]; then
69+
echo "No install directory. Please specify the --to argument."
70+
exit 1
16471
fi
16572

166-
# Sort cherrypicks and remove duplicates.
167-
CHERRYPICKS="$(echo "$CHERRYPICKS" | xargs -n1 | sort | uniq | xargs)"
168-
169-
function apply_cherrypicks() {
170-
local CHECKOUT_DIR="$1"
171-
172-
[ "$CHERRYPICKS" == "" ] || echo "Applying cherrypicks"
173-
pushd "$CHECKOUT_DIR"
174-
175-
# This function is always called on a sorted list of cherrypicks.
176-
for CHERRY_REV in $CHERRYPICKS; do
177-
echo "Cherry-picking r$CHERRY_REV into $CHECKOUT_DIR"
178-
179-
local PATCH_FILE="$(mktemp)"
180-
svn diff -c $CHERRY_REV > "$PATCH_FILE"
181-
svn patch "$PATCH_FILE"
182-
rm "$PATCH_FILE"
183-
done
184-
185-
popd
186-
}
187-
18873
CLANG_BUILD_DIR=/tmp/clang-build
189-
CLANG_INSTALL_DIR=/tmp/clang-install
190-
191-
mkdir "$CLANG_BUILD_DIR"
192-
193-
# Get the sources from svn.
194-
echo "Checking out sources from svn"
195-
mkdir "$CLANG_BUILD_DIR/src"
196-
for LLVM_PROJECT in $LLVM_PROJECTS; do
197-
if [ "$LLVM_PROJECT" == "clang" ]; then
198-
SVN_PROJECT="cfe"
199-
else
200-
SVN_PROJECT="$LLVM_PROJECT"
201-
fi
202-
203-
echo "Checking out https://llvm.org/svn/llvm-project/$SVN_PROJECT to $CLANG_BUILD_DIR/src/$LLVM_PROJECT"
204-
svn co -q $SVN_REV_ARG \
205-
"https://llvm.org/svn/llvm-project/$SVN_PROJECT/$LLVM_BRANCH" \
206-
"$CLANG_BUILD_DIR/src/$LLVM_PROJECT"
207-
208-
# We apply cherrypicks to all repositories regardless of whether the revision
209-
# changes this repository or not. For repositories not affected by the
210-
# cherrypick, applying the cherrypick is a no-op.
211-
apply_cherrypicks "$CLANG_BUILD_DIR/src/$LLVM_PROJECT"
212-
done
213-
214-
if [ $CLANG_TOOLS_EXTRA_ENABLED -ne 0 ]; then
215-
echo "Checking out https://llvm.org/svn/llvm-project/clang-tools-extra to $CLANG_BUILD_DIR/src/clang/tools/extra"
216-
svn co -q $SVN_REV_ARG \
217-
"https://llvm.org/svn/llvm-project/clang-tools-extra/$LLVM_BRANCH" \
218-
"$CLANG_BUILD_DIR/src/clang/tools/extra"
21974

220-
apply_cherrypicks "$CLANG_BUILD_DIR/src/clang/tools/extra"
221-
fi
222-
223-
CHECKSUMS_FILE="/tmp/checksums/checksums.txt"
224-
225-
if [ -f "$CHECKSUMS_FILE" ]; then
226-
echo "Validating checksums for LLVM checkout..."
227-
python "$(dirname $0)/llvm_checksum/llvm_checksum.py" -c "$CHECKSUMS_FILE" \
228-
--partial --multi_dir "$CLANG_BUILD_DIR/src"
229-
else
230-
echo "Skipping checksumming checks..."
231-
fi
75+
mkdir -p "$CLANG_INSTALL_DIR"
23276

233-
mkdir "$CLANG_BUILD_DIR/build"
77+
mkdir -p "$CLANG_BUILD_DIR/build"
23478
pushd "$CLANG_BUILD_DIR/build"
23579

23680
# Run the build as specified in the build arguments.
23781
echo "Running build"
23882
cmake -GNinja \
23983
-DCMAKE_INSTALL_PREFIX="$CLANG_INSTALL_DIR" \
240-
-DLLVM_ENABLE_PROJECTS="$CMAKE_LLVM_ENABLE_PROJECTS" \
24184
$CMAKE_ARGS \
24285
"$CLANG_BUILD_DIR/src/llvm"
24386
ninja $CMAKE_INSTALL_TARGETS
24487

24588
popd
24689

24790
# Cleanup.
248-
rm -rf "$CLANG_BUILD_DIR"
91+
rm -rf "$CLANG_BUILD_DIR/build"
24992

25093
echo "Done"

0 commit comments

Comments
 (0)