1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
#!/bin/sh
set -e
script_path="$(
cd "$(dirname "$0")"
pwd -P
)"
os=ubuntu-focal
dart_version=v6.12
build_dir_prefix=.build/
project_dir=/opt/dart/
cleanup_command=""
use_dev_image=false
build_mode="Release"
build_test=true
build_example=true
build_tutorial=true
build_dartpy=true
codecov_option=""
num_cores=1
help() {
cat <<EOF
Usage: ${0##*/} <routine> [<options>...]
Example: ${0##*/} build # Build with the default settings
Routines:
build Build DART and run its tests
clean Remove build directory for a specific build configuration
clean_all Remove all the build directories
launch Launch Docker image for DART build
Options:
-o <name> OS version. Available <name>: {ubuntu-bionic, ubuntu-focal (default), ubuntu-impish}
-v <version> DART version. Available <version>: {v6.10, v7.0 (default)}
-c Clean build. Empty the build directory before building.
-j <num_cores> Number of cores to use for build. Use -j 1 to disable parallel build. Single core will be used if this option is not specified.
--dev Use Docker image for development rather than release image.
--no-test Skip building and running tests
--no-example Skip building examples
--no-tutorial Skip building tutorials
--no-dartpy Skip building dartpy
--codecov Enable code coverage (experimental)
--mode <mode> Build mode. Available <mode>: {Release (default), Debug}
EOF
}
if [ "$#" -lt 1 ]; then
help
exit
else
routine=$1
shift
fi
while [ $# -gt 0 ]; do
case "$1" in
-o)
os=$2
shift
;;
-v)
dart_version=$2
shift
;;
-c)
cleanup_command="&& rm -rf *"
;;
--dev)
use_dev_image=true
;;
--no-test)
build_test=false
;;
--no-example)
build_example=false
;;
--no-tutorial)
build_tutorial=false
;;
--no-dartpy)
build_dartpy=false
;;
--mode)
build_mode=$2
shift
;;
-j)
num_cores=$2
shift
;;
--codecov)
codecov_option="-DDART_CODECOV=ON"
;;
*)
bash_command=$@
break
;;
esac
shift
done
full_image_name_deploy=dartsim/dart:$os-$dart_version
full_image_name_dev=dartsim/dart-dev:$os-$dart_version
if [ "$build_test" = true ]; then
test_command="&& make -j$num_cores tests && ctest --output-on-failure"
else
test_command=""
fi
if [ "$build_example" = true ]; then
example_command="&& make -j$num_cores examples"
else
example_command=""
fi
if [ "$build_tutorial" = true ]; then
tutorial_command="&& make -j$num_cores tutorials"
else
tutorial_command=""
fi
if [ "$build_dartpy" = true ]; then
dartpy_command="&& make -j30 dartpy && make pytest"
else
dartpy_command=""
fi
full_build_dir=$project_dir$build_dir_prefix$os-$dart_version-$build_mode/
launch() {
if [ "$use_dev_image" = true ]; then
full_image_name=$full_image_name_dev
else
full_image_name=$full_image_name_deploy
fi
docker pull $full_image_name
docker run \
-it \
--privileged \
--volume $(pwd):$project_dir \
-w $project_dir \
-t $full_image_name \
/bin/bash
}
clean() {
full_image_name=$full_image_name_dev
docker pull $full_image_name
docker run \
-it \
--volume $(pwd):$project_dir \
-w $project_dir/ \
$full_image_name /bin/bash -c \
"rm -rf $full_build_dir"
}
clean_all() {
full_image_name=$full_image_name_dev
docker pull $full_image_name
docker run \
-it \
--volume $(pwd):$project_dir \
-w $project_dir/ \
$full_image_name /bin/bash -c \
"rm -rf $project_dir$build_dir_prefix"
}
build() {
full_image_name=$full_image_name_dev
echo "======================================================================="
echo " [Build] "
echo " Docker : $full_image_name"
echo " Num cores: $num_cores / $(nproc)"
echo "======================================================================="
docker pull $full_image_name
docker run \
-it \
--volume $(pwd):$project_dir \
-w $project_dir/ \
$full_image_name /bin/bash -c \
"mkdir -p $full_build_dir \
&& cd $full_build_dir \
$cleanup_command \
&& cmake $project_dir \
-DCMAKE_BUILD_TYPE=$build_mode \
$codecov_option \
&& make -j$num_cores \
$test_command \
$example_command \
$tutorial_command \
$dartpy_command"
}
# Run the selected routine
"$routine"
|