travis_linux_script.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #!/bin/bash
  2. set -ev
  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_DOCUMENTATION=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. cd .. && rm build -rf
  71. echo -en 'travis_fold:end:script.build.ns0\\r'
  72. # cross compilation only with gcc
  73. if [ "$CC" = "gcc" ]; then
  74. echo -e "\r\n== Cross compile release build for MinGW 32 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw32\\r'
  75. mkdir -p build && cd build
  76. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  77. make -j
  78. 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
  79. cp open62541-win32.zip ..
  80. cd .. && rm build -rf
  81. echo -en 'travis_fold:end:script.build.cross_mingw32\\r'
  82. echo -e "\r\n== Cross compile release build for MinGW 64 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw64\\r'
  83. mkdir -p build && cd build
  84. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  85. make -j
  86. 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
  87. cp open62541-win64.zip ..
  88. cd .. && rm build -rf
  89. echo -en 'travis_fold:end:script.build.cross_mingw64\\r'
  90. echo -e "\r\n== Cross compile release build for 32-bit linux ==" && echo -en 'travis_fold:start:script.build.cross_linux\\r'
  91. mkdir -p build && cd build
  92. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-gcc-m32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  93. make -j
  94. 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
  95. cp open62541-linux32.tar.gz ..
  96. cd .. && rm build -rf
  97. echo -en 'travis_fold:end:script.build.cross_linux\\r'
  98. echo -e "\r\n== Cross compile release build for RaspberryPi ==" && echo -en 'travis_fold:start:script.build.cross_raspi\\r'
  99. mkdir -p build && cd build
  100. git clone https://github.com/raspberrypi/tools
  101. export PATH=$PATH:./tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
  102. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  103. make -j
  104. 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
  105. cp open62541-raspberrypi.tar.gz ..
  106. cd .. && rm build -rf
  107. echo -en 'travis_fold:end:script.build.cross_raspi\\r'
  108. fi
  109. echo -e "\r\n== Compile release build for 64-bit linux ==" && echo -en 'travis_fold:start:script.build.linux_64\\r'
  110. mkdir -p build && cd build
  111. cmake -DCMAKE_BUILD_TYPE=Release -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  112. make -j
  113. 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
  114. cp open62541-linux64.tar.gz ..
  115. cp open62541.h ../.. # copy single file-release
  116. cp open62541.c ../.. # copy single file-release
  117. cd .. && rm build -rf
  118. echo -en 'travis_fold:end:script.build.linux_64\\r'
  119. echo -e "\r\n== Building the C++ example ==" && echo -en 'travis_fold:start:script.build.example\\r'
  120. mkdir -p build && cd build
  121. cp ../../open62541.* .
  122. gcc -std=c99 -c open62541.c
  123. g++ ../examples/server.cpp -I./ open62541.o -lrt -o cpp-server
  124. cd .. && rm build -rf
  125. echo -en 'travis_fold:end:script.build.example\\r'
  126. echo -e "\r\n== Compile multithreaded version ==" && echo -en 'travis_fold:start:script.build.multithread\\r'
  127. mkdir -p build && cd build
  128. cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLES=ON ..
  129. make -j
  130. cd .. && rm build -rf
  131. echo -en 'travis_fold:end:script.build.multithread\\r'
  132. echo -e "\r\n== Compile without discovery version ==" && echo -en 'travis_fold:start:script.build.unit_test_valgrind\\r'
  133. mkdir -p build && cd build
  134. cmake -DUA_ENABLE_DISCOVERY=OFF -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  135. make -j
  136. cd .. && rm build -rf
  137. echo -e "\r\n== Compile discovery without multicast version =="
  138. mkdir -p build && cd build
  139. cmake -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  140. make -j
  141. cd .. && rm build -rf
  142. echo -e "\r\n== Compile multithreaded version with discovery =="
  143. mkdir -p build && cd build
  144. cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_EXAMPLES=ON ..
  145. make -j
  146. cd .. && rm build -rf
  147. echo -en 'travis_fold:end:script.build.multithread\\r'
  148. echo -e "\r\n== Debug build and unit tests (64 bit) ==" && echo -en 'travis_fold:start:script.build.unit_test_valgrind\\r'
  149. mkdir -p build && cd build
  150. 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 ..
  151. make -j && make test ARGS="-V"
  152. echo -en 'travis_fold:end:script.build.unit_test_valgrind\\r'
  153. # without valgrind
  154. # echo -e "\r\n== Debug build and unit tests without valgrind ==" && echo -en 'travis_fold:start:script.build.unit_test\\r'
  155. # 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 ..
  156. # make -j && make test ARGS="-V"
  157. # (./bin/examples/server & export pid=$!; sleep 2; kill -INT $pid; wait $pid);
  158. # echo -en 'travis_fold:end:script.build.unit_test\\r'
  159. # only run coveralls on main repo, otherwise it fails uploading the files
  160. echo -e "\r\n== -> Current repo: ${TRAVIS_REPO_SLUG} =="
  161. if [ "$CC" = "gcc" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
  162. echo -en "\r\n== Building coveralls for ${TRAVIS_REPO_SLUG} ==" && echo -en 'travis_fold:start:script.build.coveralls\\r'
  163. coveralls -E '.*\.h' -E '.*CMakeCXXCompilerId\.cpp' -E '.*CMakeCCompilerId\.c' -r ../ || true # ignore result since coveralls is unreachable from time to time
  164. echo -en 'travis_fold:end:script.build.coveralls\\r'
  165. fi
  166. cd .. && rm build -rf
  167. fi