"mediatek-filogic/build.sh" did not exist on "60995277852ea95551c4f9281b6b719b8408d31d"
test.sh 13.3 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
#!/bin/bash

3
if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "gcc" ]]; then
4
5
    export CXX=g++-11
    export CC=gcc-11
6
elif [[ $OS_NAME == "linux" ]] && [[ $COMPILER == "clang" ]]; then
7
8
    export CXX=clang++
    export CC=clang
Guolin Ke's avatar
Guolin Ke committed
9
10
fi

11
12
13
14
15
if [[ $IN_UBUNTU_BASE_CONTAINER == "true" ]]; then
    export LANG="en_US.UTF-8"
    export LC_ALL="en_US.UTF-8"
fi

16
if [[ "${TASK}" == "r-package" ]] || [[ "${TASK}" == "r-rchk" ]]; then
17
18
19
20
    bash ${BUILD_DIRECTORY}/.ci/test_r_package.sh || exit -1
    exit 0
fi

21
22
if [[ "$TASK" == "cpp-tests" ]]; then
    mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build
23
24
25
26
27
28
29
30
31
    if [[ $METHOD == "with-sanitizers" ]]; then
        extra_cmake_opts="-DUSE_SANITIZER=ON"
        if [[ -n $SANITIZERS ]]; then
            extra_cmake_opts="$extra_cmake_opts -DENABLED_SANITIZERS=$SANITIZERS"
        fi
    else
        extra_cmake_opts=""
    fi
    cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF -DUSE_DEBUG=ON $extra_cmake_opts ..
32
33
34
35
36
    make testlightgbm -j4 || exit -1
    ./../testlightgbm || exit -1
    exit 0
fi

37
conda create -q -y -n $CONDA_ENV "python=$PYTHON_VERSION[build=*cpython]"
38
source activate $CONDA_ENV
39
40
41

cd $BUILD_DIRECTORY

42
if [[ $TASK == "check-docs" ]] || [[ $TASK == "check-links" ]]; then
43
    cd $BUILD_DIRECTORY/docs
44
45
46
47
48
49
50
51
    conda env update \
        -n $CONDA_ENV \
        --file ./env.yml || exit -1
    conda install \
        -q \
        -y \
        -n $CONDA_ENV \
            doxygen \
52
            'rstcheck>=6.0.0' || exit -1
53
54
    # check reStructuredText formatting
    cd $BUILD_DIRECTORY/python-package
55
    rstcheck --report-level warning $(find . -type f -name "*.rst") || exit -1
56
    cd $BUILD_DIRECTORY/docs
57
    rstcheck --report-level warning --ignore-directives=autoclass,autofunction,autosummary,doxygenfile $(find . -type f -name "*.rst") || exit -1
58
    # build docs
59
    make html || exit -1
60
61
    if [[ $TASK == "check-links" ]]; then
        # check docs for broken links
62
        pip install --user linkchecker
63
64
65
        linkchecker --config=.linkcheckerrc ./_build/html/*.html || exit -1
        exit 0
    fi
66
67
68
    # check the consistency of parameters' descriptions and other stuff
    cp $BUILD_DIRECTORY/docs/Parameters.rst $BUILD_DIRECTORY/docs/Parameters-backup.rst
    cp $BUILD_DIRECTORY/src/io/config_auto.cpp $BUILD_DIRECTORY/src/io/config_auto-backup.cpp
69
    python $BUILD_DIRECTORY/helpers/parameter_generator.py || exit -1
70
71
72
73
    diff $BUILD_DIRECTORY/docs/Parameters-backup.rst $BUILD_DIRECTORY/docs/Parameters.rst || exit -1
    diff $BUILD_DIRECTORY/src/io/config_auto-backup.cpp $BUILD_DIRECTORY/src/io/config_auto.cpp || exit -1
    exit 0
fi
74

75
if [[ $TASK == "lint" ]]; then
76
    conda install -q -y -n $CONDA_ENV \
77
78
        cmakelint \
        cpplint \
79
        flake8 \
80
81
        isort \
        mypy \
82
        pydocstyle \
83
        "r-lintr>=3.0"
84
    echo "Linting Python code"
85
86
87
88
    flake8 \
        --ignore=E501,W503 \
        --exclude=./.nuget,./external_libs,./python-package/build \
        . || exit -1
89
    pydocstyle --convention=numpy --add-ignore=D105 --match-dir="^(?!^external_libs|test|example).*" --match="(?!^test_|setup).*\.py" . || exit -1
90
    isort . --check-only || exit -1
91
    mypy --ignore-missing-imports python-package/ || true
92
93
94
    echo "Linting R code"
    Rscript ${BUILD_DIRECTORY}/.ci/lint_r_code.R ${BUILD_DIRECTORY} || exit -1
    echo "Linting C++ code"
95
    cpplint --filter=-build/c++11,-build/include_subdir,-build/header_guard,-whitespace/line_length --recursive ./src ./include ./R-package ./swig ./tests || exit -1
96
    cmake_files=$(find . -name CMakeLists.txt -o -path "*/cmake/*.cmake")
97
    cmakelint --linelength=120 --filter=-convention/filename,-package/stdargs,-readability/wonkycase ${cmake_files} || exit -1
Guolin Ke's avatar
Guolin Ke committed
98
99
100
101
    exit 0
fi

if [[ $TASK == "if-else" ]]; then
Nikita Titov's avatar
Nikita Titov committed
102
    conda install -q -y -n $CONDA_ENV numpy
103
    mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build && cmake .. && make lightgbm -j4 || exit -1
104
    cd $BUILD_DIRECTORY/tests/cpp_tests && ../../lightgbm config=train.conf convert_model_language=cpp convert_model=../../src/boosting/gbdt_prediction.cpp && ../../lightgbm config=predict.conf output_result=origin.pred || exit -1
105
    cd $BUILD_DIRECTORY/build && make lightgbm -j4 || exit -1
106
    cd $BUILD_DIRECTORY/tests/cpp_tests && ../../lightgbm config=predict.conf output_result=ifelse.pred && python test.py || exit -1
Guolin Ke's avatar
Guolin Ke committed
107
108
109
    exit 0
fi

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
if [[ $TASK == "swig" ]]; then
    mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build
    if [[ $OS_NAME == "macos" ]]; then
        cmake -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON ..
    else
        cmake -DUSE_SWIG=ON ..
    fi
    make -j4 || exit -1
    if [[ $OS_NAME == "linux" ]] && [[ $COMPILER == "gcc" ]]; then
        objdump -T $BUILD_DIRECTORY/lib_lightgbm.so > $BUILD_DIRECTORY/objdump.log || exit -1
        objdump -T $BUILD_DIRECTORY/lib_lightgbm_swig.so >> $BUILD_DIRECTORY/objdump.log || exit -1
        python $BUILD_DIRECTORY/helpers/check_dynamic_dependencies.py $BUILD_DIRECTORY/objdump.log || exit -1
    fi
    if [[ $PRODUCES_ARTIFACTS == "true" ]]; then
        cp $BUILD_DIRECTORY/build/lightgbmlib.jar $BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_$OS_NAME.jar
    fi
    exit 0
fi

129
# re-including python=version[build=*cpython] to ensure that conda doesn't fall back to pypy
130
131
conda install -q -y -n $CONDA_ENV \
    cloudpickle \
132
133
    dask-core \
    distributed \
134
135
136
137
138
139
    joblib \
    matplotlib \
    numpy \
    pandas \
    psutil \
    pytest \
140
141
    "python=$PYTHON_VERSION[build=*cpython]" \
    python-graphviz \
142
143
    scikit-learn \
    scipy || exit -1
144

145
if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "clang" ]]; then
146
147
    # fix "OMP: Error #15: Initializing libiomp5.dylib, but found libomp.dylib already initialized." (OpenMP library conflict due to conda's MKL)
    for LIBOMP_ALIAS in libgomp.dylib libiomp5.dylib libomp.dylib; do sudo ln -sf "$(brew --cellar libomp)"/*/lib/libomp.dylib $CONDA_PREFIX/lib/$LIBOMP_ALIAS || exit -1; done
148
149
fi

Guolin Ke's avatar
Guolin Ke committed
150
if [[ $TASK == "sdist" ]]; then
151
    cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
152
    pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v || exit -1
153
    if [[ $PRODUCES_ARTIFACTS == "true" ]]; then
154
155
156
        cp $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz $BUILD_ARTIFACTSTAGINGDIRECTORY
    fi
    pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
Guolin Ke's avatar
Guolin Ke committed
157
158
    exit 0
elif [[ $TASK == "bdist" ]]; then
159
    if [[ $OS_NAME == "macos" ]]; then
160
        cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=macosx --python-tag py3 || exit -1
161
        mv dist/lightgbm-$LGB_VER-py3-none-macosx.whl dist/lightgbm-$LGB_VER-py3-none-macosx_10_15_x86_64.macosx_11_6_x86_64.macosx_12_5_x86_64.whl
162
        if [[ $PRODUCES_ARTIFACTS == "true" ]]; then
163
            cp dist/lightgbm-$LGB_VER-py3-none-macosx*.whl $BUILD_ARTIFACTSTAGINGDIRECTORY
164
        fi
Guolin Ke's avatar
Guolin Ke committed
165
    else
166
167
        ARCH=$(uname -m)
        if [[ $ARCH == "x86_64" ]]; then
168
            PLATFORM="manylinux_2_28_x86_64"
169
170
171
        else
            PLATFORM="manylinux2014_$ARCH"
        fi
172
        cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --integrated-opencl --plat-name=$PLATFORM --python-tag py3 || exit -1
173
        if [[ $PRODUCES_ARTIFACTS == "true" ]]; then
174
            cp dist/lightgbm-$LGB_VER-py3-none-$PLATFORM.whl $BUILD_ARTIFACTSTAGINGDIRECTORY
175
        fi
176
177
        # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py
        export LIGHTGBM_TEST_DUAL_CPU_GPU=1
Guolin Ke's avatar
Guolin Ke committed
178
    fi
179
    pip install --user $BUILD_DIRECTORY/python-package/dist/*.whl || exit -1
180
    pytest $BUILD_DIRECTORY/tests || exit -1
Guolin Ke's avatar
Guolin Ke committed
181
182
183
    exit 0
fi

184
185
mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build

Guolin Ke's avatar
Guolin Ke committed
186
if [[ $TASK == "gpu" ]]; then
187
188
    sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "gpu";/' $BUILD_DIRECTORY/include/LightGBM/config.h
    grep -q 'std::string device_type = "gpu"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1  # make sure that changes were really done
Guolin Ke's avatar
Guolin Ke committed
189
    if [[ $METHOD == "pip" ]]; then
190
        cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
191
        pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--gpu || exit -1
192
        pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
Guolin Ke's avatar
Guolin Ke committed
193
        exit 0
194
    elif [[ $METHOD == "wheel" ]]; then
195
        cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --gpu || exit -1
196
197
198
199
        pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER*.whl -v || exit -1
        pytest $BUILD_DIRECTORY/tests || exit -1
        exit 0
    elif [[ $METHOD == "source" ]]; then
200
        cmake -DUSE_GPU=ON ..
Guolin Ke's avatar
Guolin Ke committed
201
    fi
202
203
204
205
206
207
208
209
210
211
212
elif [[ $TASK == "cuda" || $TASK == "cuda_exp" ]]; then
    if [[ $TASK == "cuda" ]]; then
        sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "cuda";/' $BUILD_DIRECTORY/include/LightGBM/config.h
        grep -q 'std::string device_type = "cuda"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1  # make sure that changes were really done
    else
        sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "cuda_exp";/' $BUILD_DIRECTORY/include/LightGBM/config.h
        grep -q 'std::string device_type = "cuda_exp"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1  # make sure that changes were really done
        # by default ``gpu_use_dp=false`` for efficiency. change to ``true`` here for exact results in ci tests
        sed -i'.bak' 's/gpu_use_dp = false;/gpu_use_dp = true;/' $BUILD_DIRECTORY/include/LightGBM/config.h
        grep -q 'gpu_use_dp = true' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1  # make sure that changes were really done
    fi
213
214
    if [[ $METHOD == "pip" ]]; then
        cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
215
216
217
218
219
        if [[ $TASK == "cuda" ]]; then
            pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--cuda || exit -1
        else
            pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--cuda-exp || exit -1
        fi
220
221
        pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
        exit 0
222
    elif [[ $METHOD == "wheel" ]]; then
223
224
225
226
227
        if [[ $TASK == "cuda" ]]; then
            cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --cuda || exit -1
        else
            cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --cuda-exp || exit -1
        fi
228
229
230
231
        pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER*.whl -v || exit -1
        pytest $BUILD_DIRECTORY/tests || exit -1
        exit 0
    elif [[ $METHOD == "source" ]]; then
232
233
234
235
236
        if [[ $TASK == "cuda" ]]; then
            cmake -DUSE_CUDA=ON ..
        else
            cmake -DUSE_CUDA_EXP=ON ..
        fi
237
    fi
238
elif [[ $TASK == "mpi" ]]; then
239
    if [[ $METHOD == "pip" ]]; then
240
        cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
241
        pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--mpi || exit -1
242
        pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
243
        exit 0
244
245
246
247
248
249
250
    elif [[ $METHOD == "wheel" ]]; then
        cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --mpi || exit -1
        pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER*.whl -v || exit -1
        pytest $BUILD_DIRECTORY/tests || exit -1
        exit 0
    elif [[ $METHOD == "source" ]]; then
        cmake -DUSE_MPI=ON -DUSE_DEBUG=ON ..
251
    fi
Guolin Ke's avatar
Guolin Ke committed
252
else
253
    cmake ..
Guolin Ke's avatar
Guolin Ke committed
254
255
fi

256
make _lightgbm -j4 || exit -1
Guolin Ke's avatar
Guolin Ke committed
257

258
cd $BUILD_DIRECTORY/python-package && python setup.py install --precompile --user || exit -1
259
pytest $BUILD_DIRECTORY/tests || exit -1
Guolin Ke's avatar
Guolin Ke committed
260
261

if [[ $TASK == "regular" ]]; then
262
    if [[ $PRODUCES_ARTIFACTS == "true" ]]; then
263
264
265
        if [[ $OS_NAME == "macos" ]]; then
            cp $BUILD_DIRECTORY/lib_lightgbm.so $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.dylib
        else
266
267
268
269
            if [[ $COMPILER == "gcc" ]]; then
                objdump -T $BUILD_DIRECTORY/lib_lightgbm.so > $BUILD_DIRECTORY/objdump.log || exit -1
                python $BUILD_DIRECTORY/helpers/check_dynamic_dependencies.py $BUILD_DIRECTORY/objdump.log || exit -1
            fi
270
271
            cp $BUILD_DIRECTORY/lib_lightgbm.so $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.so
        fi
Guolin Ke's avatar
Guolin Ke committed
272
    fi
273
    cd $BUILD_DIRECTORY/examples/python-guide
Guolin Ke's avatar
Guolin Ke committed
274
275
276
277
    sed -i'.bak' '/import lightgbm as lgb/a\
import matplotlib\
matplotlib.use\(\"Agg\"\)\
' plot_example.py  # prevent interactive window mode
278
    sed -i'.bak' 's/graph.render(view=True)/graph.render(view=False)/' plot_example.py
279
280
281
282
283
    # requirements for examples
    conda install -q -y -n $CONDA_ENV \
        h5py \
        ipywidgets \
        notebook
284
    for f in *.py **/*.py; do python $f || exit -1; done  # run all examples
285
    cd $BUILD_DIRECTORY/examples/python-guide/notebooks
286
    sed -i'.bak' 's/INTERACTIVE = False/assert False, \\"Interactive mode disabled\\"/' interactive_plot_example.ipynb
287
    jupyter nbconvert --ExecutePreprocessor.timeout=180 --to notebook --execute --inplace *.ipynb || exit -1  # run all notebooks
288
289
290
291
292
293
294
295
296
297
298

    # importing the library should succeed even if all optional dependencies are not present
    conda uninstall --force --yes \
        dask \
        distributed \
        joblib \
        matplotlib \
        psutil \
        python-graphviz \
        scikit-learn || exit -1
    python -c "import lightgbm" || exit -1
Guolin Ke's avatar
Guolin Ke committed
299
fi