version: 2.1
jobs:
  build:
    macos:
      xcode: 12.3.0
    steps:
      - checkout:
          path: ~/LIEF
      - restore_cache:
          keys:
            - ccache-{{ arch }}-{{ .Branch }}
            - ccache-{{ arch }}-master
            - ccache-{{ arch }}
            - pyenv
      - run:
          name: Install pyenv
          command: |
            brew install pyenv
            pyenv root
            pyenv install --list
      - run:
          name: Install ccache
          command: brew install ccache
      - run:
          name: Install ninja
          command: brew install ninja
      - run:
          name: CCache initialization
          command: |
            ccache --show-stats
            ccache --zero-stats
            ccache --max-size=10.0G
            ccache --set-config=compiler_check=content
      - run:
          name: LIEF build setup
          command: |
            export PYTHON_CONFIGURE_OPTS="--enable-shared --enable-unicode=ucs2"
            pyenv install --skip-existing 3.9.0
            export PYTHON_BINARY=$(pyenv root)/versions/3.9.0/bin/python3.9
            $PYTHON_BINARY -m pip install --upgrade pip setuptools wheel
            $PYTHON_BINARY ./setup.py --ninja --lief-test build bdist_wheel
            bash scripts/osx/package_sdk.sh
      - run:
          name: LIEF deploy
          command: |
            export PYTHON_BINARY=$(pyenv root)/versions/3.9.0/bin/python3.9
            $PYTHON_BINARY -m pip install --upgrade requests mako
            $PYTHON_BINARY .github/deploy.py
      - run:
          name: ccache stats
          when: always
          command: |
            ccache --show-stats
      - save_cache:
          key: 'ccache-{{ arch }}-{{ .Branch }}'
          paths: [ "/home/circleci/.ccache" ]
      - save_cache:
          key: 'pyenv'
          paths: [ "/home/circleci/.pyenv" ]



