version: 2

jobs:

  lin-sys:
    docker:
        - image: kovidgoyal/kitty-test:latest
    steps:
        - checkout
        - run: if grep -Inr '\s$' kitty kitty_tests kittens docs *.py *.asciidoc *.rst .gitattributes .gitignore; then echo Trailing whitespace found, aborting.; exit 1; fi
        - run: python3 -m flake8 --count .
        - run: python3 setup.py build --debug --verbose
        - run: ./kitty/launcher/kitty +launch test.py
        - run: make FAIL_WARN=-W man
        - run: make FAIL_WARN=-W html

  lin-package:
    docker:
        - image: kovidgoyal/kitty-test:latest
    steps:
        - checkout
        - run: python3 setup.py linux-package --update-check-interval=0

  lin-35:
    docker:
        - image: kovidgoyal/kitty-test:latest
    environment:
        CC: gcc
        CFLAGS: -funsigned-char
        LD_LIBRARY_PATH: /opt/py3.5/lib
        ASAN_OPTIONS: leak_check_at_exit=0
    steps:
        - checkout
        - run: /opt/py3.5/bin/python3 setup.py build --debug --verbose --sanitize
        - run: ./kitty/launcher/kitty +launch test.py

  lin-37:
    docker:
        - image: kovidgoyal/kitty-test:latest
    environment:
        CC: clang
        LD_LIBRARY_PATH: /opt/py3.7/lib
        ASAN_OPTIONS: leak_check_at_exit=0
    steps:
        - checkout
        - run: /opt/py3.7/bin/python3 setup.py build --debug --verbose --sanitize
        - run: ./kitty/launcher/kitty +launch test.py

  lin-bundle:
    docker:
        - image: kovidgoyal/kitty-test:latest
    environment:
        ASAN_OPTIONS: leak_check_at_exit=0
    steps:
        - checkout
        - run: echo "export LD_LIBRARY_PATH=$SW/lib" >> $BASH_ENV
        - run: echo "export PKG_CONFIG_PATH=$SW/lib/pkgconfig" >> $BASH_ENV
        - run: echo "export PYTHONHOME=$SW" >> $BASH_ENV
        - run: $SW/bin/python3 setup.py build --debug --verbose
        - run: ./kitty/launcher/kitty +launch test.py

  mac-bundle:
      macos:
          xcode: "10.1.0"
      environment:
          LC_ALL: en_US.UTF-8
          LANG: en_US.UTF-8
          SW: /Users/Shared/buildbot/sw/sw
      steps:
          - checkout
          - run: mkdir -p $SW
          - run: curl https://download.calibre-ebook.com/travis/kitty/osx.tar.xz | tar xJ -C $SW
          - run: echo "export PATH=$SW/bin:$PATH" >> $BASH_ENV
          - run: python3 setup.py build --debug --verbose
          - run: ./kitty/launcher/kitty +launch test.py

  mac-brew:
      macos:
          xcode: "10.2.0"
      environment:
          LC_ALL: en_US.UTF-8
          LANG: en_US.UTF-8
      steps:
          - checkout
          - run: brew bundle
          - run: python3 setup.py build --debug --verbose
          - run: ./kitty/launcher/kitty +launch test.py
          - run: echo "export PATH=/usr/local/opt/sphinx-doc/bin:$PATH" >> $BASH_ENV
          - run: python3 setup.py linux-package --verbose
          - run: python3 setup.py kitty.app --verbose
          - run: kitty.app/Contents/MacOS/kitty +runpy "from kitty.constants import *; print(kitty_exe())"


workflows:
    version: 2
    all_jobs:
        jobs:
            - mac-bundle
            - lin-sys
            - lin-35
            - lin-37
            - lin-package
            - lin-bundle
            - mac-brew
