travis_linux_script.sh 10 KB

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