<commit_before>﻿#!/usr/bin/env bash

export PACKAGE_DIR=$1
export EXECUTION_DIR=$2
export BASEDIR=$(dirname "$0")

function copy_and_check {
  if ! [ -f $2 ]; then
    ln $1 $(dirname "$2") || exit $?
  fi
}

function print_info_from_core_file {
  local core_file_name=$1
  local executable_name=$2

  if ! [ -e $executable_name ]; then
    echo "Unable to find executable $executable_name"
    return
  elif ! [ -e $core_file_name ]; then
    echo "Unable to find core file $core_file_name"
    return
  fi

  # Check for the existence of GDB on the path
  hash gdb 2>/dev/null || { echo >&2 "GDB was not found. Unable to print core file."; return; }

  echo "Printing info from core file $core_file_name"

  # Open the dump in GDB and print the stack from each thread. We can add more
  # commands here if desired.
  gdb --batch -ex "thread apply all bt full" -ex "quit" $executable_name $core_file_name
}

function copy_core_file_to_temp_location {
  local core_file_name=$1

  local storage_location="/tmp/coredumps"

  # Create the directory (this shouldn't fail even if it already exists).
  mkdir -p $storage_location

  # Only copy the file over if the directory is empty. Otherwise, do nothing.
  if [ ! "$(ls -A $storage_location)" ]; then 
    echo "Copying core file $core_file_name to $storage_location"
    cp $core_file_name $storage_location
  fi
}

if [ "$PACKAGE_DIR" == "" ]
then
echo error: PACKAGE_DIR is not defined.  Usage: $0 PackageRoot ExecutionDir
exit -1
fi
echo Using $PACKAGE_DIR as folder for resolving package dependencies.

if [ "$EXECUTION_DIR" = "" ]
then
export EXECUTION_DIR=$BASEDIR
fi

echo Executing in $EXECUTION_DIR

# ========================= BEGIN Copying files  =============================
if [ ! -d "$EXECUTION_DIR" ]
then
    mkdir $EXECUTION_DIR
fi

if [ "$EXECUTION_DIR" != "$BASEDIR" ]; then
  echo "Copying files into execution dir."
  cp -l -f -R $BASEDIR/* $EXECUTION_DIR
else
  echo "Executing in unpack directory, do not have to copy files"
fi

echo Hard linking dependent files... 
# Format here is: cp -l $PACKAGE_DIR/<File Path> $/EXECUTION_DIR/<File Path> || exit $?
[[CopyFilesCommands]]<commit_msg>For the scenario where the execution directory is not the same as the one the test + script lives in, switch to a command that works on both Linux + OSX (#927)<commit_after>﻿#!/usr/bin/env bash

export PACKAGE_DIR=$1
export EXECUTION_DIR=$2
export BASEDIR=$(dirname "$0")

function copy_and_check {
  if ! [ -f $2 ]; then
    ln $1 $(dirname "$2") || exit $?
  fi
}

function print_info_from_core_file {
  local core_file_name=$1
  local executable_name=$2

  if ! [ -e $executable_name ]; then
    echo "Unable to find executable $executable_name"
    return
  elif ! [ -e $core_file_name ]; then
    echo "Unable to find core file $core_file_name"
    return
  fi

  # Check for the existence of GDB on the path
  hash gdb 2>/dev/null || { echo >&2 "GDB was not found. Unable to print core file."; return; }

  echo "Printing info from core file $core_file_name"

  # Open the dump in GDB and print the stack from each thread. We can add more
  # commands here if desired.
  gdb --batch -ex "thread apply all bt full" -ex "quit" $executable_name $core_file_name
}

function copy_core_file_to_temp_location {
  local core_file_name=$1

  local storage_location="/tmp/coredumps"

  # Create the directory (this shouldn't fail even if it already exists).
  mkdir -p $storage_location

  # Only copy the file over if the directory is empty. Otherwise, do nothing.
  if [ ! "$(ls -A $storage_location)" ]; then 
    echo "Copying core file $core_file_name to $storage_location"
    cp $core_file_name $storage_location
  fi
}

if [ "$PACKAGE_DIR" == "" ]
then
echo error: PACKAGE_DIR is not defined.  Usage: $0 PackageRoot ExecutionDir
exit -1
fi
echo Using $PACKAGE_DIR as folder for resolving package dependencies.

if [ "$EXECUTION_DIR" = "" ]
then
export EXECUTION_DIR=$BASEDIR
fi

echo Executing in $EXECUTION_DIR

# ========================= BEGIN Copying files  =============================
if [ ! -d "$EXECUTION_DIR" ]
then
    mkdir $EXECUTION_DIR
fi

if [ "$EXECUTION_DIR" != "$BASEDIR" ]; then
  echo "Copying files into execution dir."
  ln -f $BASEDIR/* $EXECUTION_DIR || exit -1
else
  echo "Executing in unpack directory, do not have to copy files"
fi

echo Hard linking dependent files... 
# Format here is: cp -l $PACKAGE_DIR/<File Path> $/EXECUTION_DIR/<File Path> || exit $?
[[CopyFilesCommands]]
{'fraction_non_alphanumeric': 0.12223463687150837, 'fraction_numerical': 0.0067039106145251395, 'mean_word_length': 3.9295154185022025, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3110480', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1435, 'n_words': 534}