travis_linux_script.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/bash
  2. set -ev
  3. if [ -z ${DOCKER+x} ]; then
  4. if [ $ANALYZE = "true" ]; then
  5. echo "=== Running static code analysis ===" && echo -en 'travis_fold:start:script.analyze\\r'
  6. if [ "$CC" = "clang" ]; then
  7. mkdir -p build
  8. cd build
  9. scan-build-3.9 cmake -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON ..
  10. scan-build-3.9 -enable-checker security.FloatLoopCounter \
  11. -enable-checker security.insecureAPI.UncheckedReturn \
  12. --status-bugs -v \
  13. make -j
  14. cd .. && rm build -rf
  15. mkdir -p build
  16. cd build
  17. scan-build-3.9 cmake -DUA_ENABLE_AMALGAMATION=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. cmake -DUA_BUILD_EXAMPLES=ON ..
  26. make -j
  27. make lint
  28. cd .. && rm build -rf
  29. else
  30. cppcheck --template "{file}({line}): {severity} ({id}): {message}" \
  31. --enable=style --force --std=c++11 -j 8 \
  32. --suppress=duplicateBranch \
  33. --suppress=incorrectStringBooleanError \
  34. --suppress=invalidscanf --inline-suppr \
  35. -I include src plugins 2> cppcheck.txt
  36. if [ -s cppcheck.txt ]; then
  37. echo "====== CPPCHECK Static Analysis Errors ======"
  38. cat cppcheck.txt
  39. exit 1
  40. fi
  41. fi
  42. echo -en 'travis_fold:end:script.analyze\\r'
  43. else
  44. echo "=== Building ==="
  45. echo "Documentation and certificate build" && echo -en 'travis_fold:start:script.build.doc\\r'
  46. mkdir -p build
  47. cd build
  48. cmake -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_DOCUMENTATION=ON -DUA_BUILD_SELFSIGNED_CERTIFICATE=ON ..
  49. make doc
  50. make doc_pdf
  51. make selfsigned
  52. cp -r doc ../../
  53. cp -r doc_latex ../../
  54. cp ./examples/server_cert.der ../../
  55. cd .. && rm build -rf
  56. echo -en 'travis_fold:end:script.build.doc\\r'
  57. echo "Full Namespace 0 Generation" && echo -en 'travis_fold:start:script.build.ns0\\r'
  58. mkdir -p build
  59. cd build
  60. cmake -DCMAKE_BUILD_TYPE=Debug -DUA_ENABLE_GENERATE_NAMESPACE0=On -DUA_BUILD_EXAMPLES=ON ..
  61. make -j
  62. cd .. && rm build -rf
  63. echo -en 'travis_fold:end:script.build.ns0\\r'
  64. # cross compilation only with gcc
  65. if [ "$CC" = "gcc" ]; then
  66. echo "Cross compile release build for MinGW 32 bit" && echo -en 'travis_fold:start:script.build.cross_mingw32\\r'
  67. mkdir -p build && cd build
  68. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  69. make -j
  70. zip -r open62541-win32.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server.exe examples/client.exe libopen62541.dll.a open62541.h open62541.c
  71. cp open62541-win32.zip ..
  72. cd .. && rm build -rf
  73. echo -en 'travis_fold:end:script.build.cross_mingw32\\r'
  74. echo "Cross compile release build for MinGW 64 bit" && echo -en 'travis_fold:start:script.build.cross_mingw64\\r'
  75. mkdir -p build && cd build
  76. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  77. make -j
  78. zip -r open62541-win64.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server.exe examples/client.exe libopen62541.dll.a open62541.h open62541.c
  79. cp open62541-win64.zip ..
  80. cd .. && rm build -rf
  81. echo -en 'travis_fold:end:script.build.cross_mingw64\\r'
  82. echo "Cross compile release build for 32-bit linux" && echo -en 'travis_fold:start:script.build.cross_linux\\r'
  83. mkdir -p build && cd build
  84. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-gcc-m32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  85. make -j
  86. tar -pczf open62541-linux32.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
  87. cp open62541-linux32.tar.gz ..
  88. cd .. && rm build -rf
  89. echo -en 'travis_fold:end:script.build.cross_linux\\r'
  90. echo "Cross compile release build for RaspberryPi" && echo -en 'travis_fold:start:script.build.cross_raspi\\r'
  91. mkdir -p build && cd build
  92. git clone https://github.com/raspberrypi/tools
  93. export PATH=$PATH:./tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
  94. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  95. make -j
  96. tar -pczf open62541-raspberrypi.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
  97. cp open62541-raspberrypi.tar.gz ..
  98. cd .. && rm build -rf
  99. echo -en 'travis_fold:end:script.build.cross_raspi\\r'
  100. fi
  101. echo "Compile release build for 64-bit linux" && echo -en 'travis_fold:start:script.build.linux_64\\r'
  102. mkdir -p build && cd build
  103. cmake -DCMAKE_BUILD_TYPE=Release -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  104. make -j
  105. tar -pczf open62541-linux64.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
  106. cp open62541-linux64.tar.gz ..
  107. cp open62541.h ../.. # copy single file-release
  108. cp open62541.c ../.. # copy single file-release
  109. cd .. && rm build -rf
  110. echo -en 'travis_fold:end:script.build.linux_64\\r'
  111. echo "Building the C++ example" && echo -en 'travis_fold:start:script.build.example\\r'
  112. mkdir -p build && cd build
  113. cp ../../open62541.* .
  114. gcc -std=c99 -c open62541.c
  115. g++ ../examples/server.cpp -I./ open62541.o -lrt -o cpp-server
  116. cd .. && rm build -rf
  117. echo -en 'travis_fold:end:script.build.example\\r'
  118. echo "Compile multithreaded version" && echo -en 'travis_fold:start:script.build.multithread\\r'
  119. mkdir -p build && cd build
  120. cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLESERVER=ON -DUA_BUILD_EXAMPLES=ON ..
  121. make -j
  122. cd .. && rm build -rf
  123. echo -en 'travis_fold:end:script.build.multithread\\r'
  124. echo "Debug build and unit tests (64 bit)" && echo -en 'travis_fold:start:script.build.unit_test_valgrind\\r'
  125. mkdir -p build && cd build
  126. cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON -DUA_ENABLE_VALGRIND_UNIT_TESTS=ON ..
  127. make -j && make test ARGS="-V"
  128. (valgrind --leak-check=yes --error-exitcode=3 ./examples/server & export pid=$!; sleep 2; kill -INT $pid; wait $pid);
  129. echo -en 'travis_fold:end:script.build.unit_test_valgrind\\r'
  130. # without valgrind
  131. echo "Debug build and unit tests without valgrind" && echo -en 'travis_fold:start:script.build.unit_test\\r'
  132. cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON -DUA_ENABLE_VALGRIND_UNIT_TESTS=OFF ..
  133. make -j && make test ARGS="-V"
  134. (./examples/server & export pid=$!; sleep 2; kill -INT $pid; wait $pid);
  135. echo -en 'travis_fold:end:script.build.unit_test\\r'
  136. # only run coveralls on main repo, otherwise it fails uploading the files
  137. echo "-> Current repo: ${TRAVIS_REPO_SLUG}"
  138. if [ "$CC" = "gcc" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
  139. echo " Building coveralls for ${TRAVIS_REPO_SLUG}" && echo -en 'travis_fold:start:script.build.coveralls\\r'
  140. coveralls -E '.*\.h' -E '.*CMakeCXXCompilerId\.cpp' -E '.*CMakeCCompilerId\.c' -r ../ || true # ignore result since coveralls is unreachable from time to time
  141. echo -en 'travis_fold:end:script.build.coveralls\\r'
  142. fi
  143. cd .. && rm build -rf
  144. fi
  145. else
  146. # Docker build test
  147. docker build -t open62541 .
  148. docker run -d -p 127.0.0.1:80:80 --name open62541 open62541 /bin/sh
  149. docker ps | grep -q open62541
  150. fi