<commit_before>#!/bin/bash

# Copyright 2010 The Native Client Authors.  All rights reserved.
# Use of this source code is governed by a BSD-style license that can
# be found in the LICENSE file.

set -o nounset
set -o errexit

# Paths relative to native_client
SPEC_BASE="tests/spec2k"
TC_SCRIPT="./tools/llvm/utman.sh"

#######################################################################
# Helpers
#######################################################################

StepBanner() {
  echo "**********************************************************************"
  echo "**********************************************************************"
  echo " $@"
  echo "**********************************************************************"
  echo "**********************************************************************"
}

NoteBuildStep() {
  echo "@@@BUILD_STEP $1@@@"
}

Annotate() {
  local label=$1
  shift
  StepBanner "Running: $@"
  NoteBuildStep ${label}
}

AnnotatedRun() {
  Annotate "$@"
  local label=$1
  shift
  "$@"
}

AnnotatedMayFailRun() {
  Annotate "$@"
  local label=$1
  shift

  set +o errexit
  "$@"
  local errcode=$?
  if [[ ${errcode} -ne 0 ]]; then
      echo "@@@BUILD FAILED@@@"
  fi
  set -o errexit

  return ${errcode}
}

PrepareSpec() {
  local spec_dir=$1
  pushd ${SPEC_BASE}
  AnnotatedRun "Clean" "./run_all.sh" CleanBenchmarks
  AnnotatedRun "Populate" "./run_all.sh" PopulateFromSpecHarness "${spec_dir}"
  popd
}

BuildAndRunSetups() {
  local setups=$1
  local did_fail=0
  pushd ${SPEC_BASE}
  for setup in ${setups}; do
    if ! AnnotatedMayFailRun "${setup}" \
      "./run_all.sh" TimedBuildAndRunBenchmarks ${setup}; then
      did_fail=1
    fi
  done
  popd
  return ${did_fail}
}

PrepareTranslators() {
  # Pull in sources before building translators
  AnnotatedRun "hg-update-stable" \
    env UTMAN_DEBUG=true "${TC_SCRIPT}" hg-update-stable
  # Build translators
  AnnotatedRun "build-sandboxed-translators" \
    "${TC_SCRIPT}" build-sandboxed-translators
  AnnotatedRun "install-translators" "${TC_SCRIPT}" install-translators
}

PrepareTrusted() {
  local arch=$1
  AnnotatedRun "scons-${arch}" \<commit_msg>update the bot script to clean the build directories prior to new builds.<commit_after>#!/bin/bash

# Copyright 2010 The Native Client Authors.  All rights reserved.
# Use of this source code is governed by a BSD-style license that can
# be found in the LICENSE file.

set -o nounset
set -o errexit

# Paths relative to native_client
SPEC_BASE="tests/spec2k"
TC_SCRIPT="./tools/llvm/utman.sh"

#######################################################################
# Helpers
#######################################################################

StepBanner() {
  echo "**********************************************************************"
  echo "**********************************************************************"
  echo " $@"
  echo "**********************************************************************"
  echo "**********************************************************************"
}

NoteBuildStep() {
  echo "@@@BUILD_STEP $1@@@"
}

Annotate() {
  local label=$1
  shift
  StepBanner "Running: $@"
  NoteBuildStep ${label}
}

AnnotatedRun() {
  Annotate "$@"
  local label=$1
  shift
  "$@"
}

AnnotatedMayFailRun() {
  Annotate "$@"
  local label=$1
  shift

  set +o errexit
  "$@"
  local errcode=$?
  if [[ ${errcode} -ne 0 ]]; then
      echo "@@@BUILD FAILED@@@"
  fi
  set -o errexit

  return ${errcode}
}

PrepareSpec() {
  local spec_dir=$1
  pushd ${SPEC_BASE}
  AnnotatedRun "Clean" "./run_all.sh" CleanBenchmarks
  AnnotatedRun "Populate" "./run_all.sh" PopulateFromSpecHarness "${spec_dir}"
  popd
}

BuildAndRunSetups() {
  local setups=$1
  local did_fail=0
  pushd ${SPEC_BASE}
  for setup in ${setups}; do
    if ! AnnotatedMayFailRun "${setup}" \
      "./run_all.sh" TimedBuildAndRunBenchmarks ${setup}; then
      did_fail=1
    fi
  done
  popd
  return ${did_fail}
}

PrepareTranslators() {
  # Pull in sources before building translators
  AnnotatedRun "hg-update-stable" \
    env UTMAN_DEBUG=true "${TC_SCRIPT}" hg-update-stable
  # Clean build directories
  AnnotatedRun "clean-build" "${TC_SCRIPT}" clean-build
  # Build translators
  AnnotatedRun "build-sandboxed-translators" \
    "${TC_SCRIPT}" build-sandboxed-translators
  AnnotatedRun "install-translators" "${TC_SCRIPT}" install-translators
}

PrepareTrusted() {
  local arch=$1
  AnnotatedRun "scons-${arch}" \
{'fraction_non_alphanumeric': 0.29772524531668154, 'fraction_numerical': 0.006690454950936664, 'mean_word_length': 4.75, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6311208', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1387, 'n_words': 333}