travis_linux_script.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/bin/bash
  2. set -e
  3. # Docker build test
  4. if ! [ -z ${DOCKER+x} ]; then
  5. docker build -t open62541 .
  6. docker run -d -p 127.0.0.1:80:80 --name open62541 open62541 /bin/sh
  7. docker ps | grep -q open62541
  8. # disabled since it randomly fails
  9. # docker ps | grep -q open62541
  10. exit 0
  11. fi
  12. # Fuzzer build test
  13. if ! [ -z ${FUZZER+x} ]; then
  14. mkdir -p build && cd build
  15. export CC=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin/clang
  16. export CXX=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin/clang++
  17. # libFuzzer.a is in the build dir.
  18. export LIB_FUZZER_DIR=$TRAVIS_BUILD_DIR
  19. cmake -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_FUZZING=ON ..
  20. make VERBOSE=1 && make run_fuzzer
  21. if [ $? -ne 0 ] ; then exit 1 ; fi
  22. cd .. && rm build -rf
  23. exit 0
  24. fi
  25. if [ $ANALYZE = "true" ]; then
  26. echo "=== Running static code analysis ===" && echo -en 'travis_fold:start:script.analyze\\r'
  27. if [ "$CC" = "clang" ]; then
  28. mkdir -p build
  29. cd build
  30. scan-build-3.9 cmake -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON ..
  31. scan-build-3.9 -enable-checker security.FloatLoopCounter \
  32. -enable-checker security.insecureAPI.UncheckedReturn \
  33. --status-bugs -v \
  34. make -j
  35. cd .. && rm build -rf
  36. mkdir -p build
  37. cd build
  38. scan-build-3.9 cmake -DUA_ENABLE_AMALGAMATION=ON ..
  39. scan-build-3.9 -enable-checker security.FloatLoopCounter \
  40. -enable-checker security.insecureAPI.UncheckedReturn \
  41. --status-bugs -v \
  42. make -j
  43. cd .. && rm build -rf
  44. mkdir -p build
  45. cd build
  46. cmake -DUA_BUILD_EXAMPLES=ON ..
  47. make -j
  48. make lint
  49. cd .. && rm build -rf
  50. else
  51. cppcheck --template "{file}({line}): {severity} ({id}): {message}" \
  52. --enable=style --force --std=c++11 -j 8 \
  53. --suppress=duplicateBranch \
  54. --suppress=incorrectStringBooleanError \
  55. --suppress=invalidscanf --inline-suppr \
  56. -I include src plugins 2> cppcheck.txt
  57. if [ -s cppcheck.txt ]; then
  58. echo "====== CPPCHECK Static Analysis Errors ======"
  59. cat cppcheck.txt
  60. exit 1
  61. fi
  62. fi
  63. echo -en 'travis_fold:end:script.analyze\\r'
  64. else
  65. echo -en "\r\n=== Building ===\r\n"
  66. echo -e "\r\n== Documentation and certificate build ==" && echo -en 'travis_fold:start:script.build.doc\\r'
  67. mkdir -p build
  68. cd build
  69. cmake -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_SELFSIGNED_CERTIFICATE=ON ..
  70. make doc
  71. make doc_pdf
  72. make selfsigned
  73. cp -r doc ../../
  74. cp -r doc_latex ../../
  75. cp ./examples/server_cert.der ../../
  76. cd .. && rm build -rf
  77. echo -en 'travis_fold:end:script.build.doc\\r'
  78. echo -e "\r\n== Full Namespace 0 Generation ==" && echo -en 'travis_fold:start:script.build.ns0\\r'
  79. mkdir -p build
  80. cd build
  81. cmake -DCMAKE_BUILD_TYPE=Debug -DUA_ENABLE_GENERATE_NAMESPACE0=On -DUA_BUILD_EXAMPLES=ON ..
  82. make -j
  83. if [ $? -ne 0 ] ; then exit 1 ; fi
  84. cd .. && rm build -rf
  85. echo -en 'travis_fold:end:script.build.ns0\\r'
  86. # cross compilation only with gcc
  87. if [ "$CC" = "gcc" ]; then
  88. echo -e "\r\n== Cross compile release build for MinGW 32 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw32\\r'
  89. mkdir -p build && cd build
  90. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  91. make -j
  92. if [ $? -ne 0 ] ; then exit 1 ; fi
  93. zip -r open62541-win32.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server.exe ./bin/examples/client.exe ./bin/libopen62541.dll.a open62541.h open62541.c
  94. cp open62541-win32.zip ..
  95. cd .. && rm build -rf
  96. echo -en 'travis_fold:end:script.build.cross_mingw32\\r'
  97. echo -e "\r\n== Cross compile release build for MinGW 64 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw64\\r'
  98. mkdir -p build && cd build
  99. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  100. make -j
  101. if [ $? -ne 0 ] ; then exit 1 ; fi
  102. zip -r open62541-win64.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server.exe ./bin/examples/client.exe ./bin/libopen62541.dll.a open62541.h open62541.c
  103. cp open62541-win64.zip ..
  104. cd .. && rm build -rf
  105. echo -en 'travis_fold:end:script.build.cross_mingw64\\r'
  106. echo -e "\r\n== Cross compile release build for 32-bit linux ==" && echo -en 'travis_fold:start:script.build.cross_linux\\r'
  107. mkdir -p build && cd build
  108. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-gcc-m32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  109. make -j
  110. if [ $? -ne 0 ] ; then exit 1 ; fi
  111. tar -pczf open62541-linux32.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server ./bin/examples/client ./bin/libopen62541.a open62541.h open62541.c
  112. cp open62541-linux32.tar.gz ..
  113. cd .. && rm build -rf
  114. echo -en 'travis_fold:end:script.build.cross_linux\\r'
  115. echo -e "\r\n== Cross compile release build for RaspberryPi ==" && echo -en 'travis_fold:start:script.build.cross_raspi\\r'
  116. mkdir -p build && cd build
  117. git clone https://github.com/raspberrypi/tools
  118. export PATH=$PATH:./tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
  119. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  120. make -j
  121. if [ $? -ne 0 ] ; then exit 1 ; fi
  122. tar -pczf open62541-raspberrypi.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server ./bin/examples/client ./bin/libopen62541.a open62541.h open62541.c
  123. cp open62541-raspberrypi.tar.gz ..
  124. cd .. && rm build -rf
  125. echo -en 'travis_fold:end:script.build.cross_raspi\\r'
  126. fi
  127. echo -e "\r\n== Compile release build for 64-bit linux ==" && echo -en 'travis_fold:start:script.build.linux_64\\r'
  128. mkdir -p build && cd build
  129. cmake -DCMAKE_BUILD_TYPE=Release -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  130. make -j
  131. if [ $? -ne 0 ] ; then exit 1 ; fi
  132. tar -pczf open62541-linux64.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server ./bin/examples/client ./bin/libopen62541.a open62541.h open62541.c
  133. cp open62541-linux64.tar.gz ..
  134. cp open62541.h ../.. # copy single file-release
  135. cp open62541.c ../.. # copy single file-release
  136. cd .. && rm build -rf
  137. echo -en 'travis_fold:end:script.build.linux_64\\r'
  138. echo -e "\r\n== Building the C++ example ==" && echo -en 'travis_fold:start:script.build.example\\r'
  139. mkdir -p build && cd build
  140. cp ../../open62541.* .
  141. gcc -std=c99 -c open62541.c
  142. g++ ../examples/server.cpp -I./ open62541.o -lrt -o cpp-server
  143. if [ $? -ne 0 ] ; then exit 1 ; fi
  144. cd .. && rm build -rf
  145. echo -en 'travis_fold:end:script.build.example\\r'
  146. echo "Compile as shared lib version" && echo -en 'travis_fold:start:script.build.shared_libs\\r'
  147. mkdir -p build && cd build
  148. cmake -DBUILD_SHARED_LIBS=ON -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  149. make -j
  150. if [ $? -ne 0 ] ; then exit 1 ; fi
  151. cd .. && rm build -rf
  152. echo -en 'travis_fold:end:script.build.shared_libs\\r'echo -e "\r\n==Compile multithreaded version==" && echo -en 'travis_fold:start:script.build.multithread\\r'
  153. mkdir -p build && cd build
  154. cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLES=ON ..
  155. make -j
  156. if [ $? -ne 0 ] ; then exit 1 ; fi
  157. cd .. && rm build -rf
  158. echo -en 'travis_fold:end:script.build.multithread\\r'
  159. echo -e "\r\n== Compile without discovery version ==" && echo -en 'travis_fold:start:script.build.unit_test_valgrind\\r'
  160. mkdir -p build && cd build
  161. cmake -DUA_ENABLE_DISCOVERY=OFF -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  162. make -j
  163. if [ $? -ne 0 ] ; then exit 1 ; fi
  164. cd .. && rm build -rf
  165. echo -e "\r\n== Compile discovery without multicast version =="
  166. mkdir -p build && cd build
  167. cmake -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  168. make -j
  169. if [ $? -ne 0 ] ; then exit 1 ; fi
  170. cd .. && rm build -rf
  171. echo -e "\r\n== Compile multithreaded version with discovery =="
  172. mkdir -p build && cd build
  173. cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_EXAMPLES=ON ..
  174. make -j
  175. if [ $? -ne 0 ] ; then exit 1 ; fi
  176. cd .. && rm build -rf
  177. echo -en 'travis_fold:end:script.build.multithread\\r'
  178. echo -e "\r\n== Debug build and unit tests (64 bit) ==" && echo -en 'travis_fold:start:script.build.unit_test_valgrind\\r'
  179. mkdir -p build && cd build
  180. cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON -DUA_ENABLE_VALGRIND_UNIT_TESTS=ON ..
  181. make -j && make test ARGS="-V"
  182. if [ $? -ne 0 ] ; then exit 1 ; fi
  183. echo -en 'travis_fold:end:script.build.unit_test_valgrind\\r'
  184. # without valgrind
  185. # echo -e "\r\n== Debug build and unit tests without valgrind ==" && echo -en 'travis_fold:start:script.build.unit_test\\r'
  186. # cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON -DUA_ENABLE_VALGRIND_UNIT_TESTS=OFF ..
  187. # make -j && make test ARGS="-V"
  188. # (./bin/examples/server & export pid=$!; sleep 2; kill -INT $pid; wait $pid);
  189. # echo -en 'travis_fold:end:script.build.unit_test\\r'
  190. # only run coveralls on main repo, otherwise it fails uploading the files
  191. echo -e "\r\n== -> Current repo: ${TRAVIS_REPO_SLUG} =="
  192. if [ "$CC" = "gcc" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
  193. echo -en "\r\n== Building coveralls for ${TRAVIS_REPO_SLUG} ==" && echo -en 'travis_fold:start:script.build.coveralls\\r'
  194. coveralls -E '.*\.h' -E '.*CMakeCXXCompilerId\.cpp' -E '.*CMakeCCompilerId\.c' -r ../ || true # ignore result since coveralls is unreachable from time to time
  195. echo -en 'travis_fold:end:script.build.coveralls\\r'
  196. fi
  197. cd .. && rm build -rf
  198. fi