build.sh 2.1 KB
Newer Older
1
#!/bin/bash
P
Peter Pan 已提交
2
set -e
3 4 5 6 7 8 9 10

TOP_DIR=$(pwd)
FRONTEND_DIR=$TOP_DIR/frontend
BACKEND_DIR=$TOP_DIR/visualdl
BUILD_DIR=$TOP_DIR/build

mkdir -p $BUILD_DIR

11
build_frontend_from_source() {
12
    cd $FRONTEND_DIR
P
Peter Pan 已提交
13 14 15
    PUBLIC_PATH="/app" API_URL="/api" ./scripts/build.sh
}

16 17
build_frontend() {
    local PACKAGE_NAME="visualdl"
P
Peter Pan 已提交
18
    echo "Donwloading npm package, please wait..."
19
    local PACKAGE=`(cd $BUILD_DIR && npm pack ${PACKAGE_NAME}@latest)`
P
Peter Pan 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32
    local SHA1SUM=`npm view ${PACKAGE_NAME}@latest dist.shasum`
    if [ "$?" -ne "0" ]; then
        echo "Cannot get sha1sum"
        exit 1
    fi
    echo "${SHA1SUM} ${PACKAGE}" > "$BUILD_DIR/${PACKAGE}.sha1"
    (cd $BUILD_DIR && sha1sum -c "${PACKAGE}.sha1")
    if [ "$?" -ne "0" ]; then
        echo "Check sum failed, download may not finish correctly."
        exit 1
    else
        echo "Check sum pass."
    fi
33
    tar zxf "$BUILD_DIR/$PACKAGE" -C "$BUILD_DIR"
34 35
}

P
Peter Pan 已提交
36
build_frontend_fake() {
37
    mkdir -p "$BUILD_DIR/package/serverless"
38 39 40 41
}

build_backend() {
    cd $BUILD_DIR
O
Oraoto 已提交
42 43 44 45 46
    if [[ $WITH_PYTHON3 ]]; then
        cmake -DWITH_PYTHON3=ON .. ${PYTHON_FLAGS}
    else
        cmake .. ${PYTHON_FLAGS}
    fi
47 48 49 50 51
    make -j2
}

build_onnx_graph() {
    export PATH="$BUILD_DIR/third_party/protobuf/src/extern_protobuf-build/:$PATH"
P
Peter Pan 已提交
52
    cd $TOP_DIR/visualdl/server/model/onnx
53
    protoc onnx.proto --python_out .
P
Peter Pan 已提交
54 55
    cd $TOP_DIR/visualdl/server/model/paddle
    protoc framework.proto --python_out .
56 57 58 59 60 61 62 63
}

clean_env() {
    rm -rf $TOP_DIR/visualdl/server/dist
    rm -rf $BUILD_DIR/bdist*
    rm -rf $BUILD_DIR/lib*
    rm -rf $BUILD_DIR/temp*
    rm -rf $BUILD_DIR/scripts*
64
    rm -rf $BUILD_DIR/*.tgz
P
Peter Pan 已提交
65
    rm -rf $BUILD_DIR/*.sha1
66
    rm -rf $BUILD_DIR/package
67 68 69
}

package() {
P
Peter Pan 已提交
70
    mkdir -p $TOP_DIR/visualdl/server/dist
71
    cp -rf $BUILD_DIR/package/serverless/* $TOP_DIR/visualdl/server/dist
P
Peter Pan 已提交
72 73
    cp $BUILD_DIR/visualdl/logic/core.so $TOP_DIR/visualdl
    cp $BUILD_DIR/visualdl/logic/core.so $TOP_DIR/visualdl/python/
74 75 76 77 78
}

ARG=$1
echo "ARG: " $ARG

79 80
clean_env

P
Peter Pan 已提交
81 82 83 84 85 86
if [ "$ARG" = "travis-CI" ]; then
    build_frontend_fake
else
    build_frontend
fi

87 88 89
build_backend
build_onnx_graph
package