Skip to content

Latest commit

 

History

History
319 lines (284 loc) · 14 KB

index.adoc

File metadata and controls

319 lines (284 loc) · 14 KB

Master programming.
Лекция №12 (Пример проекта на C++)

1. Составляющие проекта

1.1. Структура проекта

[21:36] igor@nixos-pc imgproc [nix-shell] % tree -I build
.
├── CMakeLists.txt
├── imgproc-config.cmake.in
├── imgproc-version.hpp.in
├── include
│   └── imgproc.hpp
├── README.rst
├── shell.nix
├── src
│   └── main.cpp
└── tests
    ├── CMakeLists.txt
    ├── imgproc.cpp
    └── main.cpp

3 directories, 10 files

1.2. Пример запуска

[21:35] igor@nixos-pc build [nix-shell] % ./imgproc -h
An image processing example. Version 0.1.0
Usage:
  ./imgproc [OPTION...] input images

  -h, --help        show help
  -v, --version     show version
  -t, --transform   use transform matrix
  -s, --histogram   create histogram of an image
  -o, --output arg  output image (default: /dev/null)

[21:35] igor@nixos-pc build [nix-shell] % ./imgproc --version
Version 0.1.0

1.3. Необходимые для сборки программы и библиотеки

[20:19] igor@nixos-pc imgproc % cat shell.nix
with import <nixpkgs> {};
let
  cxxopts = stdenv.mkDerivation rec {
    name = "cxxopts";
    version = "2.1.1";
    src = fetchFromGitHub {
      owner = "jarro2783";
      repo = name;
      rev = "v${version}";
      sha256 = "1l0bm0ysqa7j7kqhfi4mk6k4rhh5xc6mx82lw468sccn8m8a4ppg";
    };
    buildInputs = [ cmake ];
  };

in mkShell rec {
  name = "imgproc";
  buildInputs = [ boost168 libpng libjpeg cxxopts catch2 ];
  nativeBuildInputs = [ cmake gnumake clang_7 gdb valgrind strace cpplint include-what-you-use dpkg ];
  hardeningDisable = [ "all" ];
}

2. Сборка и тестирование проекта

2.1. Дополнительные опции сборки

[22:19] igor@nixos-pc build [nix-shell] % CXX=clang++ cmake -DCMAKE_CXX_CPPLINT=`which cpplint` -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=`which include-what-you-use` ..
-- The CXX compiler identification is Clang 7.0.0
-- Check for working CXX compiler: /nix/store/z7fadhim7jrdz5fbqqssbsk50bl3iv2x-clang-wrapper-7.0.0/bin/clang++
-- Check for working CXX compiler: /nix/store/z7fadhim7jrdz5fbqqssbsk50bl3iv2x-clang-wrapper-7.0.0/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.68.0
-- Found ZLIB: /nix/store/ma27f3n6h01ppxbl6h1igdywhvy4cmr1-zlib-1.2.11/lib/libz.so (found version "1.2.11")
-- Found PNG: /nix/store/f3l96d1br38kdlif8b5031wc6lal3n38-libpng-apng-1.6.35/lib/libpng.so (found version "1.6.35")
-- Found JPEG: /nix/store/65qgn465rkrryscfpf2b0mypdchzzj8z-libjpeg-turbo-2.0.1/lib/libjpeg.so (found version "62")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/igor/master-programming/lecture-11/imgproc/build
[22:19] igor@nixos-pc build [nix-shell] % make
Scanning dependencies of target imgproc_exe
[ 20%] Building CXX object CMakeFiles/imgproc_exe.dir/main.cpp.o
Warning: include-what-you-use reported diagnostics:
/home/igor/master-programming/lecture-11/imgproc/main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~

/home/igor/master-programming/lecture-11/imgproc/main.cpp should add these lines:
#include <boost/gil/extension/dynamic_image/../../utilities.hpp>  // for gil

/home/igor/master-programming/lecture-11/imgproc/main.cpp should remove these lines:
- #include <boost/gil/extension/io/png.hpp>  // lines 5-5
- #include "imgproc.hpp"  // lines 8-8

The full include-list for /home/igor/master-programming/lecture-11/imgproc/main.cpp:
#include <boost/gil/extension/dynamic_image/../../utilities.hpp>  // for gil
#include <cxxopts.hpp>                                            // for Opt...
---

Warning: cpplint diagnostics:
/home/igor/master-programming/lecture-11/imgproc/main.cpp:0:  No copyright message found.  You should have a line: "Copyright [year] <Copyright Owner>"  [legal/copyright] [5]
/home/igor/master-programming/lecture-11/imgproc/main.cpp:11:  { should almost always be at the end of the previous line  [whitespace/braces] [4]
/home/igor/master-programming/lecture-11/imgproc/main.cpp:21:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
/home/igor/master-programming/lecture-11/imgproc/main.cpp:27:  { should almost always be at the end of the previous line  [whitespace/braces] [4]
/home/igor/master-programming/lecture-11/imgproc/main.cpp:33:  { should almost always be at the end of the previous line  [whitespace/braces] [4]
/home/igor/master-programming/lecture-11/imgproc/main.cpp:44:  { should almost always be at the end of the previous line  [whitespace/braces] [4]
/home/igor/master-programming/lecture-11/imgproc/main.cpp:46:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
/home/igor/master-programming/lecture-11/imgproc/main.cpp:48:  An else should appear on the same line as the preceding }  [whitespace/newline] [4]

2.2. Способы тестирования

[21:44] igor@nixos-pc build [nix-shell] % ctest -T test
   Site: nixos-pc
   Build name: Linux-clang++
Create new tag: 20181219-1844 - Experimental
Test project /home/igor/master-programming/lecture-11/imgproc/build
    Start 1: imgproc::histogram
1/5 Test #1: imgproc::histogram ...............   Passed    0.00 sec
    Start 2: imgproc::bar
2/5 Test #2: imgproc::bar .....................   Passed    0.00 sec
    Start 3: imgproc::transform
3/5 Test #3: imgproc::transform ...............   Passed    0.00 sec
    Start 4: test_help
4/5 Test #4: test_help ........................   Passed    0.00 sec
    Start 5: test_no_args
5/5 Test #5: test_no_args .....................   Passed    0.00 sec

100% tests passed, 0 tests failed out of 5

Total Test time (real) =   0.01 sec
[21:47] igor@nixos-pc build [nix-shell] % ctest -T memcheck
   Site: nixos-pc
   Build name: Linux-clang++
Memory check project /home/igor/master-programming/lecture-11/imgproc/build
    Start 1: imgproc::histogram
1/5 MemCheck #1: imgproc::histogram ...............   Passed    0.89 sec
    Start 2: imgproc::bar
2/5 MemCheck #2: imgproc::bar .....................   Passed    0.90 sec
    Start 3: imgproc::transform
3/5 MemCheck #3: imgproc::transform ...............   Passed    0.89 sec
    Start 4: test_help
4/5 MemCheck #4: test_help ........................   Passed    0.79 sec
    Start 5: test_no_args
5/5 MemCheck #5: test_no_args .....................   Passed    0.75 sec

100% tests passed, 0 tests failed out of 5

Total Test time (real) =   4.21 sec
-- Processing memory checking output:
1/5 MemCheck: #1: imgproc::histogram ...............   Defects: 1
2/5 MemCheck: #2: imgproc::bar .....................   Defects: 1
3/5 MemCheck: #3: imgproc::transform ...............   Defects: 1
4/5 MemCheck: #4: test_help ........................   Defects: 1
5/5 MemCheck: #5: test_no_args .....................   Defects: 1
MemCheck log files can be found here: ( * corresponds to test number)
/home/igor/master-programming/lecture-11/imgproc/build/Testing/Temporary/MemoryChecker.*.log
Memory checking results:
Potential Memory Leak - 5
[22:03] igor@nixos-pc build [nix-shell] % ctest -T memcheck
   Site: nixos-pc
   Build name: Linux-g++
Create new tag: 20181219-1903 - Experimental
Memory check project /home/igor/master-programming/lecture-11/imgproc/build
    Start 1: imgproc::histogram
1/5 MemCheck #1: imgproc::histogram ...............   Passed    1.23 sec
    Start 2: imgproc::bar
2/5 MemCheck #2: imgproc::bar .....................   Passed    1.22 sec
    Start 3: imgproc::transform
3/5 MemCheck #3: imgproc::transform ...............   Passed    1.19 sec
    Start 4: test_help
4/5 MemCheck #4: test_help ........................   Passed    1.02 sec
    Start 5: test_no_args
5/5 MemCheck #5: test_no_args .....................   Passed    0.97 sec

100% tests passed, 0 tests failed out of 5

Total Test time (real) =   5.64 sec
-- Processing memory checking output:
MemCheck log files can be found here: ( * corresponds to test number)
/home/igor/master-programming/lecture-11/imgproc/build/Testing/Temporary/MemoryChecker.*.log
Memory checking results:
[22:12] igor@nixos-pc build [nix-shell] % ctest -T coverage
   Site: nixos-pc
   Build name: Linux-g++
Performing coverage
   Processing coverage (each . represents one file):
    ...
   Accumulating results (each . represents one file):
    ...............................................
        Covered LOC:         92
        Not covered LOC:     18
        Total LOC:           110
        Percentage Coverage: 83.64%

2.3. Где найти полные логи результатов тестов

[22:15] igor@nixos-pc build [nix-shell] % ls Testing/
20181219-1903  CoverageInfo  TAG  Temporary
[22:15] igor@nixos-pc build [nix-shell] % ls Testing/Temporary/
CTestCostData.txt               LastDynamicAnalysis_20181219-1903.log  MemoryChecker.1.log  MemoryChecker.3.log  MemoryChecker.5.log
LastCoverage_20181219-1903.log  LastTest_20181219-1903.log             MemoryChecker.2.log  MemoryChecker.4.log
[22:15] igor@nixos-pc build [nix-shell] % ls Testing/20181219-1903/
CoverageLog-0.xml  Coverage.xml  DynamicAnalysis.xml  Test.xml
[22:15] igor@nixos-pc build [nix-shell] % ls Testing/CoverageInfo/
imgproc.cpp.gcda##affine.hpp.gcov                    main.cpp.gcda##iterator_from_2d.hpp.gcov
imgproc.cpp.gcda##allocator.h.gcov                   main.cpp.gcda##lambda_functors.hpp.gcov
imgproc.cpp.gcda##alloc_traits.h.gcov                main.cpp.gcda##limits.gcov
imgproc.cpp.gcda##basic_string.h.gcov                main.cpp.gcda##locale_classes.tcc.gcov
imgproc.cpp.gcda##basic_string.tcc.gcov              main.cpp.gcda##locale_facets.h.gcov
imgproc.cpp.gcda##catch.hpp.gcov                     main.cpp.gcda##locator.hpp.gcov
imgproc.cpp.gcda##char_traits.h.gcov                 main.cpp.gcda##main.cpp.gcov
imgproc.cpp.gcda##cpp_type_traits.h.gcov             main.cpp.gcda##make_reader.hpp.gcov
imgproc.cpp.gcda##imgproc.cpp.gcov                   main.cpp.gcda##make_writer.hpp.gcov
imgproc.cpp.gcda##imgproc.hpp.gcov                   main.cpp.gcda##move.h.gcov
imgproc.cpp.gcda##initializer_list.gcov              main.cpp.gcda##new_allocator.h.gcov
imgproc.cpp.gcda##lambda_functors.hpp.gcov           main.cpp.gcda##new.gcov
imgproc.cpp.gcda##limits.gcov                        main.cpp.gcda##path_spec.hpp.gcov
imgproc.cpp.gcda##move.h.gcov                        main.cpp.gcda##pixel.hpp.gcov
imgproc.cpp.gcda##new_allocator.h.gcov               main.cpp.gcda##pixel_iterator.hpp.gcov
imgproc.cpp.gcda##new.gcov                           main.cpp.gcda##predefined_ops.h.gcov
imgproc.cpp.gcda##ptr_traits.h.gcov                  main.cpp.gcda##ptr_traits.h.gcov
imgproc.cpp.gcda##range_access.h.gcov                main.cpp.gcda##random.h.gcov
imgproc.cpp.gcda##stl_algobase.h.gcov                main.cpp.gcda##random.tcc.gcov
...

2.4. Сборка установочного пакета

[23:11] igor@nixos-pc build [nix-shell] % CXX=clang++ cmake -DCPACK_GENERATOR=DEB ..
-- The CXX compiler identification is Clang 7.0.0
-- Check for working CXX compiler: /nix/store/z7fadhim7jrdz5fbqqssbsk50bl3iv2x-clang-wrapper-7.0.0/bin/clang++
-- Check for working CXX compiler: /nix/store/z7fadhim7jrdz5fbqqssbsk50bl3iv2x-clang-wrapper-7.0.0/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.68.0
-- Found ZLIB: /nix/store/ma27f3n6h01ppxbl6h1igdywhvy4cmr1-zlib-1.2.11/lib/libz.so (found version "1.2.11")
-- Found PNG: /nix/store/f3l96d1br38kdlif8b5031wc6lal3n38-libpng-apng-1.6.35/lib/libpng.so (found version "1.6.35")
-- Found JPEG: /nix/store/65qgn465rkrryscfpf2b0mypdchzzj8z-libjpeg-turbo-2.0.1/lib/libjpeg.so (found version "62")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/igor/master-programming/lecture-11/imgproc/build
[23:12] igor@nixos-pc build [nix-shell] % make -j package
Scanning dependencies of target imgproc_exe
Scanning dependencies of target imgproc_test
[ 20%] Building CXX object tests/CMakeFiles/imgproc_test.dir/main.cpp.o
[ 40%] Building CXX object tests/CMakeFiles/imgproc_test.dir/imgproc.cpp.o
[ 60%] Building CXX object CMakeFiles/imgproc_exe.dir/main.cpp.o
[ 80%] Linking CXX executable imgproc_test
[100%] Linking CXX executable imgproc
[100%] Built target imgproc_test
[100%] Built target imgproc_exe
Run CPack packaging tool...
CPack: Create package using DEB
CPack: Install projects
CPack: - Run preinstall target for: imgproc
CPack: - Install project: imgproc
CPack: Create package
CPack: - package: /home/igor/master-programming/lecture-11/imgproc/build/imgproc-0.1.0-Linux-x86_64.deb generated.
CPack: Create package using TGZ
CPack: Install projects
CPack: - Run preinstall target for: imgproc
CPack: - Install project: imgproc
CPack: Create package
CPack: - package: /home/igor/master-programming/lecture-11/imgproc/build/imgproc-0.1.0-Linux-x86_64.tar.gz generated.
[23:19] igor@nixos-pc build [nix-shell] % tar tf /home/igor/master-programming/lecture-11/imgproc/build/imgproc-0.1.0-Linux-x86_64.tar.gz
imgproc-0.1.0-Linux-x86_64/bin/
imgproc-0.1.0-Linux-x86_64/bin/imgproc
imgproc-0.1.0-Linux-x86_64/share/
imgproc-0.1.0-Linux-x86_64/share/doc/
imgproc-0.1.0-Linux-x86_64/share/doc/imgproc/
imgproc-0.1.0-Linux-x86_64/share/doc/imgproc/CMakeLists.txt
imgproc-0.1.0-Linux-x86_64/share/doc/imgproc/imgproc.cpp
imgproc-0.1.0-Linux-x86_64/share/doc/imgproc/main.cpp
imgproc-0.1.0-Linux-x86_64/share/cmake/
imgproc-0.1.0-Linux-x86_64/share/cmake/imgproc/
imgproc-0.1.0-Linux-x86_64/share/cmake/imgproc/imgproc-targets.cmake
imgproc-0.1.0-Linux-x86_64/share/cmake/imgproc/imgproc-targets-noconfig.cmake
imgproc-0.1.0-Linux-x86_64/share/cmake/imgproc/imgproc-config.cmake
imgproc-0.1.0-Linux-x86_64/share/cmake/imgproc/imgproc-config-version.cmake
imgproc-0.1.0-Linux-x86_64/include/
imgproc-0.1.0-Linux-x86_64/include/imgproc.hpp