language: node_js

sudo: false

# build options and AWS keys for publishing binaries
# note: you'll need to generate your own keys for publishing a separate project
env:
  global:
   - secure: F42vcZEgWgCMDvQXlmyYmWwFo86fUjlJbsvXEwyliaMfasjCNsbmeILU61aScn8daiCGD+vRUaRlmv+XxUSS2G8FaoI8ZjwgMo2guMwthAQJ1ohTvf4bZI0JqVYKnnZpzhGPv2zD0DTdt31l30qn2GZnnGrF4yFpPU1HW2HcMuE=
   - secure: WRWrn3KjCaevRo2htdvn26euALTZNCDtcSlQvtH6Bc7yLdhlH5apj+qSuWqlN59f1cprFH+5aQ2zmBkVmAV2DT4IbsfszMIR6k6EetuY6VOugo/qsPW2x/MQbpFgjCbl95bYty4eUH9Bcf70Pz/S+XVewABXHWikJiLUiZBbLyE=
   - secure: "bvbvxQe4GXZoU1zxm6KylaUSuQuhUZKe1V4+iYM0Sde6hj6RtAUccCWT7mNacCe2I6uGVHHjVfd7wLovT5y7lyT5pzY3UtypxFwuvGxDHotH4hhTg4m8/7APdB4bf5YgBf5IC6pMUPpUloh6TsTIwYzEaJdp/52b31Qfx80FooqOGOrEqntiyvidWsdUmlrxWnpxCVndkZgwvD15Uc08DWyD8Hklor6cKW6d/3zVIFmy81uAvTQp5W5xXC47S/BYYIwz3GU0zx+CMWM1oFObSbkVMG3LXDurqyvzWf9+09ZtBlC2JW0AOt9atk7vnD115Ia1KaEWalMhb3AGwJx4M4hqonooWOx20NL5P0sqEUe94GBUwvvb295vFTbw9guSGYXL3cOeWTlh2Ol466vJUwBvfr4OQ6Qu401nb1sIIv4SoIT9xXSHbopoderRVQurrcl/wesR19hgzrQC9ytJ6QCS1xnnzKogflfMQDDayrCMwpiZ5gvMGheGNbAh661wL03YXiviMwG307+iwFk8zyw05g4nW5/v3S+OYq3QatUgk+ZDpX2JS2zX4D6Aj2QLzKtCrx9pNpngl8pN+drmac1nklUeQLANxyv8hQjJvs1a4utj7ed9CY7QEWkvfrUl7rZqXvzacKmGEWoTkZKru19pa0enLTThKQV6AOei3e4="

# enable c++11/14 builds
addons:
  apt:
    sources: [ 'ubuntu-toolchain-r-test' ]
    packages: [ 'libstdc++-4.9-dev' ]

install:
  # set up the environment by installing mason and clang++
  - ./scripts/setup.sh --config local.env
  # put mason and clang++ on PATH
  - source local.env
  - node -v
  - which node
  - clang++ -v
  - which clang++
  - make ${BUILDTYPE}
  # Build should be standalone now, so remove mason deps
  - rm -rf mason_packages

# run tests
# we use before_script rather than script to ensure fast failure (the script section continues even after an error)
# https://docs.travis-ci.com/user/customizing-the-build#Breaking-the-Build
before_script:
  - ./scripts/check_glibcxx.sh
  - npm test
  # after successful tests, publish binaries if specified in commit message
  - ./scripts/publish.sh --toolset=${TOOLSET:-} --debug=$([ "${BUILDTYPE}" == 'debug' ] && echo "true" || echo "false")

# override script default (npm test) to do nothing (we test in before_script)
script:
  - true

# the matrix allows you to specify different operating systems and environments to
# run your tests and build binaries
matrix:
  include:
    # linux publishable node v0.10/release
    - os: linux
      env: BUILDTYPE=release
      node_js: "0.10"
    # linux publishable node v4/release
    - os: linux
      env: BUILDTYPE=release
      node_js: 4
    # linux publishable node v4/debug
    - os: linux
      env: BUILDTYPE=debug
      node_js: 4
    # linux publishable node v6
    - os: linux
      env: BUILDTYPE=release
      node_js: 6
    # linux publishable node v6/debug
    - os: linux
      env: BUILDTYPE=debug
      node_js: 6
    # linux publishable node v7
    - os: linux
      env: BUILDTYPE=release
      node_js: 7
    # linux publishable node v8
    - os: linux
      env: BUILDTYPE=release
      node_js: 8
    # linux publishable node v9
    - os: linux
      env: BUILDTYPE=release
      node_js: 9
    # osx publishable node v0.10
    - os: osx
      osx_image: xcode8.3
      env: BUILDTYPE=release
      node_js: "0.10"
    # osx publishable node v4
    - os: osx
      osx_image: xcode8.3
      env: BUILDTYPE=release
      node_js: 4
    # osx publishable node v4/debug
    - os: osx
      osx_image: xcode8.3
      env: BUILDTYPE=debug
      node_js: 4
    # osx publishable node v6
    - os: osx
      osx_image: xcode8.3
      env: BUILDTYPE=release
      node_js: 6
    # osx publishable node v6/debug
    - os: osx
      osx_image: xcode8.3
      env: BUILDTYPE=debug
      node_js: 6
    # osx publishable node v7
    - os: osx
      osx_image: xcode8.3
      env: BUILDTYPE=release
      node_js: 7
    # osx publishable node v8
    - os: osx
      osx_image: xcode8.3
      env: BUILDTYPE=release
      node_js: 8
    # osx publishable node v9
    - os: osx
      osx_image: xcode8.3
      env: BUILDTYPE=release
      node_js: 9
    # Sanitizer build linux node v4/Debug
    - os: linux
      env: BUILDTYPE=debug TOOLSET=-asan
      node_js: 4
      # Overrides `install` to set up custom asan flags
      install:
        - ./scripts/setup.sh --config local.env
        # put mason and clang++ on PATH
        - source local.env
        # Note: to build without stopping on errors remove the -fno-sanitize-recover=all flag
        # You might want to do this if there are multiple errors and you want to see them all before fixing
        - export CXXFLAGS="${MASON_SANITIZE_CXXFLAGS} -fno-sanitize-recover=all"
        - export LDFLAGS="${MASON_SANITIZE_LDFLAGS}"
        - make ${BUILDTYPE}
      # Overrides `script` to disable asan LD_PRELOAD before publishing
      before_script:
        - export LD_PRELOAD=${MASON_LLVM_RT_PRELOAD}
        # TODO: re-enable detect_leaks=0 once we can build and test against an asan sanitized libc++
        - export ASAN_OPTIONS=fast_unwind_on_malloc=0:detect_leaks=0:${ASAN_OPTIONS}
        - npm test
        - unset LD_PRELOAD
        # after successful tests, publish binaries if specified in commit message
        - ./scripts/publish.sh --toolset=${TOOLSET:-} --debug=$([ "${BUILDTYPE}" == 'debug' ] && echo "true" || echo "false")
    # Sanitizer build osx node v4/Debug
    - os: osx
      osx_image: xcode8.3
      env: BUILDTYPE=debug TOOLSET=-asan
      node_js: 4
      # Overrides `install` to set up custom asan flags
      install:
        - ./scripts/setup.sh --config local.env
        # put mason and clang++ on PATH
        - source local.env
        # Note: to build without stopping on errors remove the -fno-sanitize-recover=all flag
        # You might want to do this if there are multiple errors and you want to see them all before fixing
        - export CXXFLAGS="${MASON_SANITIZE_CXXFLAGS} -fno-sanitize-recover=all"
        - export LDFLAGS="${MASON_SANITIZE_LDFLAGS}"
        - make ${BUILDTYPE}
      # Overrides `script` to disable asan LD_PRELOAD before publishing
      before_script:
        - export DYLD_INSERT_LIBRARIES=${MASON_LLVM_RT_PRELOAD}
        # TODO: re-enable detect_leaks=0 once we can build and test against an asan sanitized libc++
        - export ASAN_OPTIONS=fast_unwind_on_malloc=0:detect_leaks=0:${ASAN_OPTIONS}
        - node ./node_modules/.bin/_mocha test/  --timeout 100000
        - unset DYLD_INSERT_LIBRARIES
        # after successful tests, publish binaries if specified in commit message
        - ./scripts/publish.sh --toolset=${TOOLSET:-} --debug=$([ "${BUILDTYPE}" == 'debug' ] && echo "true" || echo "false")
    # g++ build (default builds all use clang++)
    - os: linux
      env: BUILDTYPE=debug CXX="g++-6" CC="gcc-6"
      node_js: 4
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - libstdc++-6-dev
            - g++-6
      # Overrides `install` to avoid initializing clang toolchain
      install:
        - make ${BUILDTYPE}
      # Overrides `script` to disable publishing
      before_script:
        - npm test
    # test building with out SSE_MATH enabled
    - os: linux
      env: BUILDTYPE=release SSE_MATH=false
      node_js: 4
      # Overrides `script` to disable publishing
      before_script:
        - npm test
    # Coverage build
    - os: linux
      env: BUILDTYPE=debug CXXFLAGS="--coverage" LDFLAGS="--coverage"
      node_js: 4
      # Overrides `script` to publish coverage data to codecov
      before_script:
        - npm test
        - mason install llvm-cov ${MASON_LLVM_RELEASE}
        - mason link llvm-cov ${MASON_LLVM_RELEASE}
        - which llvm-cov
        - curl -S -f https://codecov.io/bash -o codecov
        - chmod +x codecov
        - ./codecov -x "llvm-cov gcov" -Z

notifications:
  slack:
    secure: wLpScQaDoEsVe0Bu28b62FGZBfmX3s/NK8DWcuSxEFx80k8RKPNgnMg8htamG0zRSf5htF+X6jy2P0IeUvbeupIaJwqtXvHaJYtlMTmemG/xuXLTpLp6k6giT2mWm/lp+ykuaF/PvUcZWUhSf1zhS6vwIekrMYIcDYvNXjO8DNw=
