libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

build_docker_image.sh (2715B)


      1 #!/bin/bash
      2 #===- libcxx/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 
     16 function show_usage() {
     17   cat << EOF
     18 Usage: build_docker_image.sh [options] [-- [cmake_args]...]
     19 
     20 Available options:
     21   General:
     22     -h|--help               show this help message
     23   Docker-specific:
     24     -s|--source             image source dir (i.e. debian8, nvidia-cuda, etc)
     25     -d|--docker-repository  docker repository for the image
     26     -t|--docker-tag         docker tag for the image
     27 
     28 Required options: --source and --docker-repository.
     29 
     30 For example, running:
     31 $ build_docker_image.sh -s debian9 -d mydocker/debian9-clang -t latest
     32 will produce two docker images:
     33     mydocker/debian9-clang-build:latest - an intermediate image used to compile
     34       clang.
     35     mydocker/clang-debian9:latest       - a small image with preinstalled clang.
     36 Please note that this example produces a not very useful installation, since it
     37 doesn't override CMake defaults, which produces a Debug and non-boostrapped
     38 version of clang.
     39 EOF
     40 }
     41 
     42 while [[ $# -gt 0 ]]; do
     43   case "$1" in
     44     -h|--help)
     45       show_usage
     46       exit 0
     47       ;;
     48     -s|--source)
     49       shift
     50       IMAGE_SOURCE="$1"
     51       shift
     52       ;;
     53     -d|--docker-repository)
     54       shift
     55       DOCKER_REPOSITORY="$1"
     56       shift
     57       ;;
     58     -t|--docker-tag)
     59       shift
     60       DOCKER_TAG="$1"
     61       shift
     62       ;;
     63     *)
     64       echo "Unknown argument $1"
     65       exit 1
     66       ;;
     67   esac
     68 done
     69 
     70 
     71 command -v docker >/dev/null ||
     72   {
     73     echo "Docker binary cannot be found. Please install Docker to use this script."
     74     exit 1
     75   }
     76 
     77 if [ "$IMAGE_SOURCE" == "" ]; then
     78   echo "Required argument missing: --source"
     79   exit 1
     80 fi
     81 
     82 if [ "$DOCKER_REPOSITORY" == "" ]; then
     83   echo "Required argument missing: --docker-repository"
     84   exit 1
     85 fi
     86 
     87 SOURCE_DIR=$(dirname $0)
     88 if [ ! -d "$SOURCE_DIR/$IMAGE_SOURCE" ]; then
     89   echo "No sources for '$IMAGE_SOURCE' were found in $SOURCE_DIR"
     90   exit 1
     91 fi
     92 
     93 BUILD_DIR=$(mktemp -d)
     94 trap "rm -rf $BUILD_DIR" EXIT
     95 echo "Using a temporary directory for the build: $BUILD_DIR"
     96 
     97 cp -r "$SOURCE_DIR/$IMAGE_SOURCE" "$BUILD_DIR/$IMAGE_SOURCE"
     98 cp -r "$SOURCE_DIR/scripts" "$BUILD_DIR/scripts"
     99 
    100 
    101 if [ "$DOCKER_TAG" != "" ]; then
    102   DOCKER_TAG=":$DOCKER_TAG"
    103 fi
    104 
    105 echo "Building ${DOCKER_REPOSITORY}${DOCKER_TAG} from $IMAGE_SOURCE"
    106 docker build -t "${DOCKER_REPOSITORY}${DOCKER_TAG}" \
    107   -f "$BUILD_DIR/$IMAGE_SOURCE/Dockerfile" \
    108   "$BUILD_DIR"
    109 echo "Done"