travis_linux_script.sh 9.9 KB

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