#####################################
# Evergreen configuration for libbson
#####################################

functions:
  "fetch source" :
    - command: git.get_project
      params:
        directory: libbson
    - command: git.apply_patch
      params:
        directory: "libbson"
    - command: shell.exec
      params:
        continue_on_err: true
        # Must be http as RHEL55 has https issues
        script: "set -o xtrace; rm -f *.tar.gz; curl http://s3.amazonaws.com/mciuploads/libbson/${revision}/${version_id}/artifacts/libbson.tar.gz --output libbson.tar.gz --silent --max-time 120 --fail"

  "upload release":
    - command: shell.exec
      params:
        script: mv libbson/libbson*gz libbson.tar.gz
    - command: s3.put
      params:
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        local_file: libbson.tar.gz
        remote_file: libbson/${revision}/${version_id}/artifacts/libbson.tar.gz
        bucket: mciuploads
        permissions: public-read
        content_type: ${content_type|application/x-gzip}

  "upload scan artifacts":
    - command: shell.exec
      params:
        working_dir: "libbson"
        script: tar czf scan.tar.gz scan
    - command: s3.put
      params:
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        local_file: libbson/scan.tar.gz
        remote_file: libbson/${build_variant}/${revision}/${version_id}/${build_id}/artifacts/scan.tar.gz
        bucket: mciuploads
        permissions: public-read
        content_type: ${content_type|application/x-gzip}

  "upload artifacts":
    - command: shell.exec
      params:
        script: tar czf artifacts.tar.gz libbson
    - command: archive.targz_pack
      params:
        target: "artifacts.tar.gz"
        source_dir: "."
        include:
          - "libbson"
    - command: s3.put
      params:
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        local_file: libbson.tar.gz
        remote_file: libbson/${build_variant}/${revision}/${version_id}/${build_id}/artifacts/artifacts.tar.gz
        bucket: mciuploads
        permissions: public-read
        content_type: ${content_type|application/x-gzip}
        display_name: "artifacts.tar.gz"

  "upload results" :
    command: attach.results
    params:
      file_location: "libbson/test-results.json"

pre:
  - func: "fetch source"

post:
  - func: "upload artifacts"
  - func: "upload scan artifacts"
  - func: "upload release"
  - func: "upload results"

#######################################
#               Tasks                 #
#######################################

tasks:
    - name: debug-compile
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "DEBUG=1 CC=${CC} MARCH='${MARCH}' sh .evergreen/${FILENAME|unix}.sh"

    - name: debug-compile-c11
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "DEBUG=1 CC='${CC}' MARCH='${MARCH}' CFLAGS='-std=c11 -D_XOPEN_SOURCE=600' sh .evergreen/${FILENAME|unix}.sh"

    - name: debug-compile-c99
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "DEBUG=1 CC='${CC}' MARCH='${MARCH}' CFLAGS='-std=c99 -D_XOPEN_SOURCE=600' sh .evergreen/${FILENAME|unix}.sh"

    - name: debug-compile-c89
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "DEBUG=1 CC='${CC}' MARCH='${MARCH}' CFLAGS='-std=c89 -D_POSIX_C_SOURCE=200112L' sh .evergreen/${FILENAME|unix}.sh"

    - name: debug-compile-valgrind
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "VALGRIND=1 DEBUG=1 CC='${CC}' MARCH='${MARCH}' sh .evergreen/${FILENAME|unix}.sh"

    - name: debug-compile-sanitizer-address
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "DEBUG=1 CC='clang-3.8' MARCH='${MARCH}' CFLAGS='-fsanitize=address' sh .evergreen/${FILENAME|unix}.sh"

    - name: debug-compile-scan-build
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "DEBUG=1 CC=clang ANALYZE=1 MARCH='${MARCH}' sh .evergreen/${FILENAME|unix}.sh"

    - name: make-release-archive
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "./autogen.sh --enable-html-docs --enable-man-pages && make dist"

    - name: release-compile
      depends_on:
        - name: "make-release-archive"
          variant: releng
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "cat .evergreen/${FILENAME|unix}.sh | tr -d '\r' > .evergreen/tmp.sh && CC='${CC}' MARCH='${MARCH}' RELEASE=1 sh .evergreen/tmp.sh"

    - name: release-compile-c11
      depends_on:
        - name: "make-release-archive"
          variant: releng
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "CC='${CC}' MARCH='${MARCH}' CFLAGS='-std=c11 -D_XOPEN_SOURCE=600' RELEASE=1 sh .evergreen/${FILENAME|unix}.sh"

    - name: release-compile-c99
      depends_on:
        - name: "make-release-archive"
          variant: releng
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "CC='${CC}' MARCH='${MARCH}' CFLAGS='-std=c99 -D_XOPEN_SOURCE=600' RELEASE=1 sh .evergreen/${FILENAME|unix}.sh"

    - name: release-compile-c89
      depends_on:
        - name: "make-release-archive"
          variant: releng
      commands:
        - command: shell.exec
          params:
            working_dir: "libbson"
            script: "CC='${CC}' MARCH='${MARCH}' CFLAGS='-std=c89 -D_POSIX_C_SOURCE=200112L' RELEASE=1 sh .evergreen/${FILENAME|unix}.sh"


#######################################
#           Buildvariants             #
#######################################

buildvariants:

- name: releng
  display_name: "Release Archive Creator"
  run_on:
    - ubuntu1404-build
  tasks:
    - name: "make-release-archive"
      distros: # Run on any of these variants, whichever will schedule us first
      - ubuntu1604-build
      - ubuntu1604-test
      - ubuntu1404-build
      - ubuntu1404-test
    - name: "release-compile"
    - name: "debug-compile-valgrind"
      distros:
      - ubuntu1604-build
    - name: "debug-compile-sanitizer-address"
      distros:
      - ubuntu1604-build
    - name: "debug-compile-scan-build"
      distros:
      - ubuntu1604-build

## clang

- name: clang35
  display_name: "Debian 8.1 (clang 3.5)"
  expansions:
    CC: clang
  run_on:
  - debian81-build
  tasks:
    - name: "release-compile"
    - name: "release-compile-c89"
    - name: "release-compile-c99"
    - name: "release-compile-c11"

- name: clang37
  display_name: "Archlinux (clang 3.7)"
  expansions:
    CC: clang
  run_on:
    - archlinux-build
  tasks:
    - name: "debug-compile"
    - name: "debug-compile-c89"
    - name: "debug-compile-c99"
    - name: "debug-compile-c11"

- name: clang38
  display_name: "Ubuntu 16 64 (clang 3.8)"
  expansions:
    CC: clang
  run_on:
    - ubuntu1604-build
  tasks:
    - name: "debug-compile"
    - name: "debug-compile-c89"
    - name: "debug-compile-c99"
    - name: "debug-compile-c11"

## GCC
- name: gcc48
  display_name: "RHEL 7.0 64 (GCC 4.8)"
  expansions:
    CC: gcc
  run_on:
    - rhel70
  tasks:
    - name: "debug-compile"
    - name: "debug-compile-c99"
    - name: "debug-compile-c11"

- name: gcc53
  display_name: "Ubuntu 16 64 (GCC 5.3)"
  expansions:
    CC: gcc
  run_on:
    - ubuntu1604-build
  tasks:
    - name: "debug-compile"
    - name: "debug-compile-c99"
    - name: "debug-compile-c11"


# Other Linuxs
- name: ubuntu-1204-64
  display_name: "Ubu 12 gcc-4.6.3 64"
  expansions:
    CC: gcc
  run_on:
    - ubuntu1204-test
  tasks:
    - name: "debug-compile"
    - name: "debug-compile-c99"

- name: rhel-55
  display_name: "RHEL 5.5 64"
  expansions:
    CC: gcc
  run_on:
    - rhel55
    - rhel55-test
  tasks:
    - name: "release-compile"

- name: rhel-62
  display_name: "RHEL 6.2 64"
  expansions:
    CC: gcc
  run_on:
    - rhel62-test
  tasks:
    - name: "debug-compile"
    - name: "debug-compile-c99"

## ZAP
- name: rhel-72-zseries
  display_name: "RHEL 7.2 zSeries"
  expansions:
    CC: gcc
  run_on:
    - rhel72-zseries-build
  tasks:
    - name: "debug-compile"
    - name: "debug-compile-c99"
    - name: "debug-compile-c11"

- name: rhel-71-power8
  display_name: "RHEL 7.1 Power8"
  expansions:
    CC: gcc
  run_on:
    - rhel71-power8-test
  tasks:
    - name: "debug-compile"
    - name: "debug-compile-c99"
    - name: "debug-compile-c11"

## OSX
- name: os-x-1010-64
  display_name: "OSX 10.10 clang 64"
  expansions:
    CC: clang
  run_on:
    - osx-1010
  tasks:
    - name: "debug-compile"
    - name: "debug-compile-c99"
    - name: "debug-compile-c11"

## Solaris
- name: solaris-32-bit
  display_name: "Sol gcc-4.8.2 32"
  expansions:
    CC: gcc
    MARCH: i386
  run_on:
    - solaris
  tasks:
    - name: "debug-compile"

- name: solaris-64-bit
  display_name: "Sol gcc-4.8.2 64"
  expansions:
    CC: gcc
  run_on:
    - solaris
  tasks:
    - name: "debug-compile"

## Windows
- name: windows-32-vs2010
  display_name: "Win VS2010 32"
  expansions:
    CC: "Visual Studio 10 2010"
    FILENAME: "windows"
  run_on:
  - windows-64-vs2010-compile
  tasks:
    - name: "release-compile"

- name: windows-64-vs2010
  display_name: "Win VS2010 64"
  expansions:
    CC: "Visual Studio 10 2010 Win64"
    FILENAME: "windows"
  run_on:
  - windows-64-vs2010-compile
  tasks:
    - name: "release-compile"

- name: windows-32-vs2013
  display_name: "Win VS2013 32"
  expansions:
    CC: "Visual Studio 12 2013"
    FILENAME: "windows"
  run_on:
  - windows-64-vs2013-compile
  tasks:
    - name: "release-compile"

- name: windows-64-vs2013
  display_name: "Win VS2013 64"
  expansions:
    CC: "Visual Studio 12 2013 Win64"
    FILENAME: "windows"
  run_on:
  - windows-64-vs2013-compile
  tasks:
    - name: "release-compile"

- name: windows-32-vs2015
  display_name: "Win VS2015 32"
  expansions:
    CC: "Visual Studio 14 2015"
    FILENAME: "windows"
  run_on:
  - windows-64-vs2015-compile
  tasks:
    - name: "release-compile"

- name: windows-64-vs2015
  display_name: "Win VS2015 64"
  expansions:
    CC: "Visual Studio 14 2015 Win64"
    FILENAME: "windows"
  run_on:
  - windows-64-vs2015-compile
  tasks:
    - name: "release-compile"

