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


title() {
	echo
	echo
	echo
	echo
	echo "--- [ $1 ] ---"
	echo
}

die() {
	echo
	echo
	echo "   *** failed: ${1}"
	exit 1
}

run() {
	title $1; shift
	$@
}

platform_and_env_settings() {
	title "GENERAL"
	platform='unknown'
	unamestr=`uname`
	if [[ "$unamestr" == 'Linux' ]]; then
		platform='linux'
	elif [[ "$unamestr" == 'FreeBSD' ]]; then
		platform='freebsd'
	elif [[ "$unamestr" == 'Darwin' ]]; then
		platform='macos'
	fi
	echo "platform: ${platform}"

	export NPROC=1
	[ $platform == linux ] && export NPROC=$(nproc)
	[ $platform == macos ] && export NPROC=$(sysctl -n hw.ncpu)
	export platform="${platform}"
	[ "$BUILD_TYPE" == "" ] && export BUILD_TYPE="debug"

	uname -a
	cat	../build-settings.txt
}

compiler_settings() {
	if [ -n "${TRAVIS_JOB_NUMBER}" -a $platform == linux ]; then
		[ "$CC"  == "" ]    && export CC="gcc-5";
		[ "$CXX" == "" ]    && export CXX="g++-5";
		[ "$CC"  == "gcc" ] && export CC="gcc-5";
		[ "$CXX" == "g++" ] && export CXX="g++-5";
	fi
	[ -z "$CC" ]  && export CC="gcc";
	[ -z "$CXX" ] && export CXX="g++";
}

cmake_cleanup() {
	cd bootstrap
	echo " - delete CMakeCache.txt" && rm -f CMakeCache.txt
	echo " - delete CMakeFiles" && rm -rf CMakeFiles
}

configure() {
	echo "# cmake . -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
	cmake . -DCMAKE_BUILD_TYPE=${BUILD_TYPE} || die "bootstrap configure error"
}

build() {
	echo "# make -j ${NPROC}"
	make -j ${NPROC} || (run  "SOMETHING HAS FAILED" make VERBOSE=1 ; exit 1) || die "build failed"
	make check || die "check failed"
}

make_packages_deb() {
	make packages-deb || die "packages deb failed";
}

print_packages() {
	(cd "${root}/../../distrib" && find  -maxdepth 1 -and -type f  -and -not -path '*/\.*' \
		| xargs  ls -lh)
}

make_packages() {
	[ ! "${BUILD_TYPE:-}" = 'release' ] && return
	local has_pkgs=0
	[ $platform == linux ] && run "Packages DEB" make_packages_deb && has_pkgs=1
	[ $has_pkgs -ne 0 ] && run "Distribution" print_packages
	return 0
}


local_pwd=$(dirname "$0")
root=$(cd "${local_pwd}" && pwd)
pushd "${root}/../../bootstrap"

run "Platform & Env settings" platform_and_env_settings
run "C++ Compiler settings" compiler_settings
[ -z "${TRAVIS_JOB_NUMBER}" ] && cmake_cleanup

run "Bootstrap: configure" configure
run "Bootstrap: build" build
make_packages<commit_msg>travis: use terminal output folding<commit_after>#!/usr/bin/env bash


title() {
	echo
	echo
	echo
	echo
	echo "--- [ $1 ] ---"
	echo
}

die() {
	echo
	echo
	echo "   *** failed: ${1}"
	exit 1
}

run() {
	local tag="$1"
	local title="$2"
	local ANSI_CLEAR="\033[0K"
	shift
	shift
	if [ -n "${TRAVIS_JOB_NUMBER:-}" ]; then
		echo -en "travis_fold:start:${tag}\r${ANSI_CLEAR}"
		echo "${title}"
	else
		title "${title}"
	fi
	$@ || die "failed to execute '$@'"
	[ -n "${TRAVIS_JOB_NUMBER:-}" ] && echo -en "travis_fold:end:${tag}\r${ANSI_CLEAR}"
	return 0
}

platform_and_env_settings() {
	title "GENERAL"
	platform='unknown'
	unamestr=`uname`
	if [[ "$unamestr" == 'Linux' ]]; then
		platform='linux'
	elif [[ "$unamestr" == 'FreeBSD' ]]; then
		platform='freebsd'
	elif [[ "$unamestr" == 'Darwin' ]]; then
		platform='macos'
	fi
	echo "platform: ${platform}"

	export NPROC=1
	[ $platform == linux ] && export NPROC=$(nproc)
	[ $platform == macos ] && export NPROC=$(sysctl -n hw.ncpu)
	export platform="${platform}"
	[ "$BUILD_TYPE" == "" ] && export BUILD_TYPE="debug"

	uname -a
	cat	../build-settings.txt
}

compiler_settings() {
	if [ -n "${TRAVIS_JOB_NUMBER}" -a $platform == linux ]; then
		[ "$CC"  == "" ]    && export CC="gcc-5";
		[ "$CXX" == "" ]    && export CXX="g++-5";
		[ "$CC"  == "gcc" ] && export CC="gcc-5";
		[ "$CXX" == "g++" ] && export CXX="g++-5";
	fi
	[ -z "$CC" ]  && export CC="gcc";
	[ -z "$CXX" ] && export CXX="g++";
}

cmake_cleanup() {
	cd bootstrap
	echo " - delete CMakeCache.txt" && rm -f CMakeCache.txt
	echo " - delete CMakeFiles" && rm -rf CMakeFiles
}

configure() {
	echo "# cmake . -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
	cmake . -DCMAKE_BUILD_TYPE=${BUILD_TYPE} || die "bootstrap configure error"
}

build() {
	echo "# make -j ${NPROC}"
	make -j ${NPROC} || (run  "retry" "ERROR" make VERBOSE=1 ; exit 1) || die "build failed"
	make check || die "check failed"
}

make_packages_deb() {
	make packages-deb || die "packages deb failed";
}

print_packages() {
	(cd "${root}/../../distrib" && find  -maxdepth 1 -and -type f  -and -not -path '*/\.*' \
		| xargs  ls -lh)
}

make_packages() {
	[ ! "${BUILD_TYPE:-}" = 'release' ] && return
	local has_pkgs=0
	[ $platform == linux ] && run "DEB" "Packages DEB" make_packages_deb && has_pkgs=1
	[ $has_pkgs -ne 0 ] && run "output" "Distribution" print_packages
	return 0
}


local_pwd=$(dirname "$0")
root=$(cd "${local_pwd}" && pwd)
pushd "${root}/../../bootstrap"

run "settings" "Platform / Env Settings" platform_and_env_settings
run "compiler" "C++ Compiler settings" compiler_settings
[ -z "${TRAVIS_JOB_NUMBER}" ] && cmake_cleanup

run "cmake" "Bootstrap: configure" configure
run "build" "Bootstrap: build" build
make_packages
{'fraction_non_alphanumeric': 0.20965818759936408, 'fraction_numerical': 0.00794912559618442, 'mean_word_length': 3.7436380772855795, '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': '3585303', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1956, 'n_words': 475}