<commit_before>---

- name: Check if OpenCV {{ opencv_version }} is already installed
  stat: path="/usr/local/lib/libopencv_core.so.{{ opencv_version }}"
  register: opencv_installed

- name: Install OpenCV dependencies
  apt: name={{ item }} state=latest
  with_items:
    - build-essential
    - cmake
    - g++
    - pkg-config
    - software-properties-common
    - libcurl3-dev
    - libfreetype6-dev
    - libjpeg-dev
    - libtiff5-dev
    - libjasper-dev
    - libpng12-dev
    - qtbase5-dev
    - libavcodec-dev
    - libavformat-dev
    - libswscale-dev
    - libdc1394-22-dev
    - libxine2-dev
    - libv4l-dev
    - libgtk2.0-dev
    - libatlas-base-dev
    - gfortran
    - libhdf5-serial-dev
    - libgstreamer1.0-dev
    - libgstreamer-plugins-base1.0-dev
    - libgstreamer-plugins-good1.0-dev
    - libtbb-dev
    - libmp3lame-dev
    - libfaac-dev
    - libtheora-dev
    - libvorbis-dev
    - libxvidcore-dev
    - libopencore-amrnb-dev
    - libopencore-amrwb-dev
    - x264
    - v4l-utils
    - libprotobuf-dev
    - protobuf-compiler
    - libgphoto2-dev
    - libeigen3-dev
    - libhdf5-dev
    - doxygen
  become: yes

- name: Clone OpenCV repo and set branch to '{{ opencv_repo_branch }}'
  git:
    repo: https://github.com/opencv/opencv.git
    dest: ../../opencv
    force: yes
    version: "{{ opencv_repo_branch }}"
  register: opencv_repo_state

- name: Clone OpenCV contrib repo and set branch to '{{ opencv_contrib_repo_branch }}'
  git:
    repo: https://github.com/opencv/opencv_contrib.git
    dest: ../../opencv_contrib
    force: yes
    version: "{{ opencv_contrib_repo_branch }}"
  register: opencv_contrib_repo_state

- name: Clone OpenCV extra repo and set branch to '{{ opencv_extra_repo_branch }}'
  git:
    repo: https://github.com/opencv/opencv_extra.git
    dest: ../../opencv_extra
    force: yes
    version: "{{ opencv_extra_repo_branch }}"
  register: opencv_extra_repo_state

- block:
    - name: Check if there is a previous OpenCV build
      stat: path="../../opencv/build/install_manifest.txt"
      register: opencv_prev_build

    - block:
        - name: Uninstall previous OpenCV build
          make: target=uninstall
          args:
            chdir: "../../opencv/build"
          become: yes

        - name: Remove old OpenCV build folder
          file: path="../../opencv/build" state=absent
      when: opencv_prev_build.stat.exists

    - name: Remove remainings from previous OpenCV build (1/2)
      file: path="{{ item }}" state=absent
      with_items:
        - /usr/local/include/opencv
        - /usr/local/include/opencv2
        - /usr/local/share/OpenCV
      become: yes

      # with_fileglob unfortunately seems to ignore symlinks, but they should not cause harm ...
    - name: Remove remainings from previous OpenCV build (2/2)
      file: path="{{ item }}" state=absent
      with_fileglob:
        - /usr/local/lib/libopencv_*
      become: yes

    - name: Ensure build folder inside OpenCV repo
      file: path="../../opencv/build" state=directory

    - name: CMake for OpenCV (no CUDA for now as not yet compatible with 9.0 and benefit for python is very limited)
      shell: >
        /bin/bash -ic "cmake
        -D CMAKE_BUILD_TYPE=RELEASE
        -D CMAKE_INSTALL_PREFIX=/usr/local
        -D WITH_CUDA=OFF
        -D WITH_TBB=ON
        -D WITH_V4L=ON
        -D WITH_QT=ON
        -D USE_GStreamer=ON
        -D WITH_OPENGL=ON
        -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules
        -D WITH_IPP=ON
        -D PYTHON_DEFAULT_EXECUTABLE=$(which python3)
        -D INSTALL_PYTHON_EXAMPLES=ON
        -D BUILD_PERF_TESTS=OFF
        -D BUILD_TESTS=OFF
        -D BUILD_DOCS=OFF
        -D BUILD_EXAMPLES={{ opencv_build_examples }}
        -D ENABLE_FAST_MATH=1
        -D PROTOBUF_PROTOC_EXECUTABLE=/usr/bin/protoc .."
      args:
        chdir: "../../opencv/build"

    - name: Build OpenCV {{ opencv_version }} (takes about 10 minutes)
      shell: make -j$(nproc)
      args:
        chdir: "../../opencv/build"

    - name: Install OpenCV {{ opencv_version }}
      make: target=install
      args:
        chdir: "../../opencv/build"
      become: yes
  when:
    - not opencv_installed.stat.exists or opencv_repo_state.changed or opencv_force_rebuild

- name: Add /usr/local/lib to system library paths
  lineinfile:
    dest: /etc/ld.so.conf.d/opencv.conf
    create: yes
    line: /usr/local/lib
  become: yes<commit_msg>fix opencv contrib undefined symbol errors with protobuf for latest opencv 3.3.1 by indirectly not building dnn_modern<commit_after>---

- name: Check if OpenCV {{ opencv_version }} is already installed
  stat: path="/usr/local/lib/libopencv_core.so.{{ opencv_version }}"
  register: opencv_installed

- name: Install OpenCV dependencies
  apt: name={{ item }} state=latest
  with_items:
    - build-essential
    - cmake
    - g++
    - pkg-config
    - software-properties-common
    - libcurl3-dev
    - libfreetype6-dev
    - libjpeg-dev
    - libtiff5-dev
    - libjasper-dev
    - libpng12-dev
    - qtbase5-dev
    - libavcodec-dev
    - libavformat-dev
    - libswscale-dev
    - libdc1394-22-dev
    - libxine2-dev
    - libv4l-dev
    - libgtk2.0-dev
    - libatlas-base-dev
    - gfortran
    - libhdf5-serial-dev
    - libgstreamer1.0-dev
    - libgstreamer-plugins-base1.0-dev
    - libgstreamer-plugins-good1.0-dev
    - libtbb-dev
    - libmp3lame-dev
    - libfaac-dev
    - libtheora-dev
    - libvorbis-dev
    - libxvidcore-dev
    - libopencore-amrnb-dev
    - libopencore-amrwb-dev
    - x264
    - v4l-utils
    - libprotobuf-dev
    - protobuf-compiler
    - libgphoto2-dev
    - libeigen3-dev
    - libhdf5-dev
    - doxygen
  become: yes

- name: Clone OpenCV repo and set branch to '{{ opencv_repo_branch }}'
  git:
    repo: https://github.com/opencv/opencv.git
    dest: ../../opencv
    force: yes
    version: "{{ opencv_repo_branch }}"
  register: opencv_repo_state

- name: Clone OpenCV contrib repo and set branch to '{{ opencv_contrib_repo_branch }}'
  git:
    repo: https://github.com/opencv/opencv_contrib.git
    dest: ../../opencv_contrib
    force: yes
    version: "{{ opencv_contrib_repo_branch }}"
  register: opencv_contrib_repo_state

- name: Clone OpenCV extra repo and set branch to '{{ opencv_extra_repo_branch }}'
  git:
    repo: https://github.com/opencv/opencv_extra.git
    dest: ../../opencv_extra
    force: yes
    version: "{{ opencv_extra_repo_branch }}"
  register: opencv_extra_repo_state

- block:
    - name: Check if there is a previous OpenCV build
      stat: path="../../opencv/build/install_manifest.txt"
      register: opencv_prev_build

    - block:
        - name: Uninstall previous OpenCV build
          make: target=uninstall
          args:
            chdir: "../../opencv/build"
          become: yes

        - name: Remove old OpenCV build folder
          file: path="../../opencv/build" state=absent
      when: opencv_prev_build.stat.exists

    - name: Remove remainings from previous OpenCV build (1/2)
      file: path="{{ item }}" state=absent
      with_items:
        - /usr/local/include/opencv
        - /usr/local/include/opencv2
        - /usr/local/share/OpenCV
      become: yes

      # with_fileglob unfortunately seems to ignore symlinks, but they should not cause harm ...
    - name: Remove remainings from previous OpenCV build (2/2)
      file: path="{{ item }}" state=absent
      with_fileglob:
        - /usr/local/lib/libopencv_*
      no_log: True
      become: yes

    - name: Ensure build folder inside OpenCV repo
      file: path="../../opencv/build" state=directory

    # Note: libopencv_dnn_modern should be disabled for now (which it will by leaving out '-D PROTOBUF_PROTOC_EXECUTABLE=/usr/bin/protoc' lol) as it causes undefined symbol errors with protobuf (see also https://github.com/opencv/opencv/issues/10021)
    - name: CMake for OpenCV (no CUDA for now as not yet compatible with 9.0 and benefit for python is very limited)
      shell: >
        /bin/bash -ic "cmake
        -D CMAKE_BUILD_TYPE=RELEASE
        -D CMAKE_INSTALL_PREFIX=/usr/local
        -D WITH_CUDA=OFF
        -D WITH_TBB=ON
        -D WITH_V4L=ON
        -D WITH_QT=ON
        -D USE_GStreamer=ON
        -D WITH_OPENGL=ON
        -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules
        -D WITH_IPP=ON
        -D PYTHON_DEFAULT_EXECUTABLE=$(which python3)
        -D INSTALL_PYTHON_EXAMPLES=ON
        -D BUILD_PERF_TESTS=OFF
        -D BUILD_TESTS=OFF
        -D BUILD_DOCS=OFF
        -D BUILD_EXAMPLES={{ opencv_build_examples }}
        -D ENABLE_FAST_MATH=1 .."
      args:
        chdir: "../../opencv/build"

    - name: Build OpenCV {{ opencv_version }} (takes about 10 minutes)
      shell: make -j$(nproc)
      args:
        chdir: "../../opencv/build"

    - name: Install OpenCV {{ opencv_version }}
      make: target=install
      args:
        chdir: "../../opencv/build"
      become: yes
  when:
    - not opencv_installed.stat.exists or opencv_repo_state.changed or opencv_force_rebuild

- name: Add /usr/local/lib to system library paths
  lineinfile:
    dest: /etc/ld.so.conf.d/opencv.conf
    create: yes
    line: /usr/local/lib
  become: yes
{'fraction_non_alphanumeric': 0.11137620648519683, 'fraction_numerical': 0.010194122112569136, 'mean_word_length': 2.2357894736842105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4919927', 'n_tokens_mistral': 3308, 'n_tokens_neox': 3215, 'n_words': 714}