build_paddle.sh 2.6 KB
Newer Older
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
#!/bin/bash

# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

CUR_DIR=$(dirname "${BASH_SOURCE[0]}")
CUR_DIR=$(realpath "$CUR_DIR")

# shellcheck disable=1090
source "$CUR_DIR/config.sh"

# exit when any command fails
set -e

# check build mode auto/man
BUILD_AUTO=${BUILD_AUTO:-1}


declare -a ENV_ARGS
if [ "$HTTP_PROXY" ]; then
    ENV_ARGS+=("--env" "HTTP_PROXY=$HTTP_PROXY")
    echo "using http proxy: $HTTP_PROXY"
fi

if [ "$HTTPS_PROXY" ]; then
    ENV_ARGS+=("--env" "HTTPS_PROXY=$HTTPS_PROXY")
    echo "using https proxy: $HTTPS_PROXY"
fi

echo "compile paddle in docker"
echo "docker image: $BUILD_IMAGE"

BUILD_ID=$(docker images -q "$BUILD_IMAGE")
if [ ! "$BUILD_ID" ]; then
    echo "docker image is not existed, and try to build."

    "$CUR_DIR/build_docker.sh"
fi

BUILD_NAME="paddle-musl-build-$(date +%Y%m%d-%H%M%S)"
echo "container name: $BUILD_NAME"

MOUNT_DIR="/paddle"
echo "mount paddle: $PADDLE_DIR => $MOUNT_DIR"

57 58 59
CCACHE_DIR="${HOME}/.ccache"
mkdir -p "$CCACHE_DIR"
echo "ccache dir: $CCACHE_DIR"
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

if [ "$BUILD_AUTO" -eq "1" ]; then
    echo "enter automatic build mode"

    # no exit when fails
    set +e

    BUILD_SCRIPT=$MOUNT_DIR/paddle/scripts/musl_build/build_inside.sh
    echo "build script: $BUILD_SCRIPT"

    OUTPUT_DIR="output"
    mkdir -p $OUTPUT_DIR
    OUTPUT_DIR=$(realpath $OUTPUT_DIR)
    echo "build output: $OUTPUT_DIR"

    # shellcheck disable=2086,2068
    docker run \
        -v "$PADDLE_DIR":"$MOUNT_DIR" \
78 79
        -v "$OUTPUT_DIR":"/output" \
        -v "$CCACHE_DIR":"/root/.ccache" \
80 81 82 83 84 85 86 87 88
        --rm \
        --workdir /root \
        --network host \
        ${ENV_ARGS[*]} \
        --name "$BUILD_NAME" \
        "$BUILD_IMAGE" \
        "$BUILD_SCRIPT" $@

    echo "list output: $OUTPUT_DIR"
89
    find "$OUTPUT_DIR" -type f
90 91 92 93 94 95 96
else
    echo "enter manual build mode"

    # shellcheck disable=2086
    docker run \
        -it \
        -v "$PADDLE_DIR":"$MOUNT_DIR" \
97
        -v "$CCACHE_DIR":"/root/.ccache" \
98 99 100 101 102
        --workdir /root \
        --network host ${ENV_ARGS[*]}\
        --name "$BUILD_NAME" \
        "$BUILD_IMAGE"
fi