<commit_before>#!/usr/bin/env bash
#**************************************************************************
#*                                                                        *
#*                                 OCaml                                  *
#*                                                                        *
#*              <NAME>, OCaml Labs                             *
#*                                                                        *
#*   Copyright 2014 Institut National de Recherche en Informatique et     *
#*     en Automatique.                                                    *
#*                                                                        *
#*   All rights reserved.  This file is distributed under the terms of    *
#*   the GNU Lesser General Public License version 2.1, with the          *
#*   special exception on linking described in the file LICENSE.          *
#*                                                                        *
#**************************************************************************

set -e

# TRAVIS_COMMIT_RANGE has the form   <commit1>...<commit2>
# TRAVIS_CUR_HEAD is <commit1>
# TRAVIS_PR_HEAD is <commit2>
#
# The following diagram illustrates the relationship between
# the commits:
#
#      (trunk)         (pr branch)
#  TRAVIS_CUR_HEAD   TRAVIS_PR_HEAD
#        |            /
#       ...         ...
#        |          /
#  TRAVIS_MERGE_BASE
#
echo "TRAVIS_COMMIT_RANGE=$TRAVIS_COMMIT_RANGE"
echo "TRAVIS_COMMIT=$TRAVIS_COMMIT"
if [[ $TRAVIS_EVENT_TYPE = 'pull_request' ]] ; then
  FETCH_HEAD=$(git rev-parse FETCH_HEAD)
  echo "FETCH_HEAD=$FETCH_HEAD"
else
  FETCH_HEAD=$TRAVIS_COMMIT
fi

if [[ $TRAVIS_EVENT_TYPE = 'push' ]] ; then
  if ! git cat-file -e "$TRAVIS_COMMIT" 2> /dev/null ; then
    echo 'TRAVIS_COMMIT does not exist - CI failure'
    exit 1
  fi
else
  if [[ $TRAVIS_COMMIT != $(git rev-parse FETCH_HEAD) ]] ; then
    echo 'WARNING! Travis TRAVIS_COMMIT and FETCH_HEAD do not agree!'
    if git cat-file -e "$TRAVIS_COMMIT" 2> /dev/null ; then
      echo 'TRAVIS_COMMIT exists, so going with it'
    else
      echo 'TRAVIS_COMMIT does not exist; setting to FETCH_HEAD'
      TRAVIS_COMMIT=$FETCH_HEAD
    fi
  fi
fi

set -x

PREFIX=~/local

MAKE="make $MAKE_ARG"
SHELL=dash

TRAVIS_CUR_HEAD=${TRAVIS_COMMIT_RANGE%%...*}
TRAVIS_PR_HEAD=${TRAVIS_COMMIT_RANGE##*...}
case $TRAVIS_EVENT_TYPE in
   # If this is not a pull request then TRAVIS_COMMIT_RANGE may be empty.
   pull_request)
     DEEPEN=50
     while ! git merge-base "$TRAVIS_CUR_HEAD" "$TRAVIS_PR_HEAD" >& /dev/null
     do
       echo "Deepening $TRAVIS_BRANCH by $DEEPEN commits"
       git fetch origin --deepen=$DEEPEN "$TRAVIS_BRANCH"
       ((DEEPEN*=2))
     done
     TRAVIS_MERGE_BASE=$(git merge-base "$TRAVIS_CUR_HEAD" "$TRAVIS_PR_HEAD");;
esac

CheckDepend () {
  cat<<EOF
------------------------------------------------------------------------
This test checks that 'alldepend' target is a no-op in the current
state, which means that dependencies are correctly stored in .depend
files. It should only be run after the compiler has been built.
If this check fails, it should be fixable by just running 'make alldepend'.
------------------------------------------------------------------------
EOF
  ./configure --disable-dependency-generation \
              --disable-debug-runtime \
              --disable-instrumented-runtime
  # Need a runtime
  $MAKE -j coldstart
  # And generated files (ocamllex compiles ocamlyacc)
  $MAKE -j ocamllex
  $MAKE alldepend
  # note: we cannot use $? as (set -e) may be set globally,
  # and disabling it locally is not worth the hassle.
  # note: we ignore the whitespace in case different C dependency
  # detectors use different indentation styles.
  git diff --ignore-all-space --quiet --exit-code **.depend \
      && result=pass || result=fail
  case $result in
      pass)
          echo "CheckDepend: success";;
      fail)
          echo "CheckDepend: failure on the following files:"
          git --no-pager diff --ignore-all-space --name-only **.depend
          exit 1;;
  esac
}

BuildAndTest () {
  mkdir -p $PREFIX
  cat<<EOF
------------------------------------------------------------------------
This test builds the OCaml compiler distribution with your pull request
and runs its testsuite.
<commit_msg>Travis CheckDepend: show the difference, not just the problematic files<commit_after>#!/usr/bin/env bash
#**************************************************************************
#*                                                                        *
#*                                 OCaml                                  *
#*                                                                        *
#*              <NAME>, OCaml Labs                             *
#*                                                                        *
#*   Copyright 2014 Institut National de Recherche en Informatique et     *
#*     en Automatique.                                                    *
#*                                                                        *
#*   All rights reserved.  This file is distributed under the terms of    *
#*   the GNU Lesser General Public License version 2.1, with the          *
#*   special exception on linking described in the file LICENSE.          *
#*                                                                        *
#**************************************************************************

set -e

# TRAVIS_COMMIT_RANGE has the form   <commit1>...<commit2>
# TRAVIS_CUR_HEAD is <commit1>
# TRAVIS_PR_HEAD is <commit2>
#
# The following diagram illustrates the relationship between
# the commits:
#
#      (trunk)         (pr branch)
#  TRAVIS_CUR_HEAD   TRAVIS_PR_HEAD
#        |            /
#       ...         ...
#        |          /
#  TRAVIS_MERGE_BASE
#
echo "TRAVIS_COMMIT_RANGE=$TRAVIS_COMMIT_RANGE"
echo "TRAVIS_COMMIT=$TRAVIS_COMMIT"
if [[ $TRAVIS_EVENT_TYPE = 'pull_request' ]] ; then
  FETCH_HEAD=$(git rev-parse FETCH_HEAD)
  echo "FETCH_HEAD=$FETCH_HEAD"
else
  FETCH_HEAD=$TRAVIS_COMMIT
fi

if [[ $TRAVIS_EVENT_TYPE = 'push' ]] ; then
  if ! git cat-file -e "$TRAVIS_COMMIT" 2> /dev/null ; then
    echo 'TRAVIS_COMMIT does not exist - CI failure'
    exit 1
  fi
else
  if [[ $TRAVIS_COMMIT != $(git rev-parse FETCH_HEAD) ]] ; then
    echo 'WARNING! Travis TRAVIS_COMMIT and FETCH_HEAD do not agree!'
    if git cat-file -e "$TRAVIS_COMMIT" 2> /dev/null ; then
      echo 'TRAVIS_COMMIT exists, so going with it'
    else
      echo 'TRAVIS_COMMIT does not exist; setting to FETCH_HEAD'
      TRAVIS_COMMIT=$FETCH_HEAD
    fi
  fi
fi

set -x

PREFIX=~/local

MAKE="make $MAKE_ARG"
SHELL=dash

TRAVIS_CUR_HEAD=${TRAVIS_COMMIT_RANGE%%...*}
TRAVIS_PR_HEAD=${TRAVIS_COMMIT_RANGE##*...}
case $TRAVIS_EVENT_TYPE in
   # If this is not a pull request then TRAVIS_COMMIT_RANGE may be empty.
   pull_request)
     DEEPEN=50
     while ! git merge-base "$TRAVIS_CUR_HEAD" "$TRAVIS_PR_HEAD" >& /dev/null
     do
       echo "Deepening $TRAVIS_BRANCH by $DEEPEN commits"
       git fetch origin --deepen=$DEEPEN "$TRAVIS_BRANCH"
       ((DEEPEN*=2))
     done
     TRAVIS_MERGE_BASE=$(git merge-base "$TRAVIS_CUR_HEAD" "$TRAVIS_PR_HEAD");;
esac

CheckDepend () {
  cat<<EOF
------------------------------------------------------------------------
This test checks that 'alldepend' target is a no-op in the current
state, which means that dependencies are correctly stored in .depend
files. It should only be run after the compiler has been built.
If this check fails, it should be fixable by just running 'make alldepend'.
------------------------------------------------------------------------
EOF
  ./configure --disable-dependency-generation \
              --disable-debug-runtime \
              --disable-instrumented-runtime
  # Need a runtime
  $MAKE -j coldstart
  # And generated files (ocamllex compiles ocamlyacc)
  $MAKE -j ocamllex
  $MAKE alldepend
  # note: we cannot use $? as (set -e) may be set globally,
  # and disabling it locally is not worth the hassle.
  # note: we ignore the whitespace in case different C dependency
  # detectors use different indentation styles.
  git diff --ignore-all-space --quiet --exit-code **.depend \
      && result=pass || result=fail
  case $result in
      pass)
          echo "CheckDepend: success";;
      fail)
          echo "CheckDepend: failure with the following differences:"
          git --no-pager diff --ignore-all-space **.depend
          exit 1;;
  esac
}

BuildAndTest () {
  mkdir -p $PREFIX
  cat<<EOF
------------------------------------------------------------------------
This test builds the OCaml compiler distribution with your pull request
and runs its testsuite.

{'fraction_non_alphanumeric': 0.1654537184443939, 'fraction_numerical': 0.003866272458494428, 'mean_word_length': 1.7212252475247525, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '898890', 'n_tokens_mistral': 2537, 'n_tokens_neox': 2432, 'n_words': 740}