1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/tools/testspr/test.sh

378 lines
11 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
# =============================================================================
# Copyright (c) 2011-2019 Bolero MURAKAMI
# https://github.com/bolero-MURAKAMI/Sprout
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# =============================================================================
#
# requires: Python (http://www.python.org/) if parallel mode
#
stagedir="testspr"
gcc_version="."
clang_version="."
gcc_root="/usr/local"
clang_root="/usr/local"
2013-09-26 14:09:53 +00:00
declare -a user_macros=()
declare -a include_paths=()
max_procs=
force=0
2017-08-06 06:47:57 +00:00
use_version=0
use_help=0
std="c++11"
2013-09-26 14:09:53 +00:00
declare -a common_options=()
2014-01-11 11:27:55 +00:00
declare -a compiler_options=()
declare -A compiler_specific_options=()
2013-09-26 14:09:53 +00:00
declare -a version_options=()
declare -A version_specific_options=(
# [clang-3.3]='-ftemplate-depth=512'
# [clang-3.4]='-ftemplate-depth=512'
)
test_cpp=$(cd $(dirname $0); pwd)/test.cpp
test_py=$(cd $(dirname $0); pwd)/test.py
get_std_option() {
vn=0
if [ "${2}" = "." ]; then
if [ "${1}" = "gcc" ]; then
read -ra current_version_array <<< `g++ --version`
vn=${current_version_array[2]//.}
elif [ "${1}" = "clang" ]; then
read -ra current_version_array <<< `clang++ --version`
vn=${current_version_array[2]//.}
fi
else
vn=${2//.}
fi
if [ "${3}" = "c++20" -o "${3}" = "c++2a" ]; then
if [ "${1}" = "gcc" ]; then
if [ "${vn}" -lt "480" ]; then
echo -n "-std=c++11"
2017-08-06 01:09:03 +00:00
elif [ "${vn}" -lt "510" ]; then
echo -n "-std=c++1y"
elif [ "${vn}" -lt "800" ]; then
echo -n "-std=c++17"
2017-08-06 01:09:03 +00:00
else
echo -n "-std=c++2a"
fi
elif [ "${1}" = "clang" ]; then
if [ "${vn}" -lt "32" ]; then
echo -n "-std=c++11"
elif [ "${vn}" -lt "350" ]; then
echo -n "-std=c++1y"
elif [ "${vn}" -lt "500" ]; then
echo -n "-std=c++1z"
elif [ "${vn}" -lt "600" ]; then
echo -n "-std=c++17"
else
echo -n "-std=c++2a"
fi
fi
elif [ "${3}" = "c++17" -o "${3}" = "c++1z" ]; then
if [ "${1}" = "gcc" ]; then
if [ "${vn}" -lt "480" ]; then
echo -n "-std=c++11"
elif [ "${vn}" -lt "510" ]; then
echo -n "-std=c++1y"
else
echo -n "-std=c++17"
fi
elif [ "${1}" = "clang" ]; then
if [ "${vn}" -lt "32" ]; then
echo -n "-std=c++11"
elif [ "${vn}" -lt "350" ]; then
echo -n "-std=c++1y"
elif [ "${vn}" -lt "500" ]; then
echo -n "-std=c++1z"
else
echo -n "-std=c++17"
fi
fi
elif [ "${3}" = "c++14" -o "${3}" = "c++1y" ]; then
if [ "${1}" = "gcc" ]; then
if [ "${vn}" -lt "480" ]; then
echo -n "-std=c++11"
2017-08-06 01:09:03 +00:00
elif [ "${vn}" -lt "510" ]; then
echo -n "-std=c++1y"
2017-08-06 01:09:03 +00:00
else
echo -n "-std=c++14"
fi
elif [ "${1}" = "clang" ]; then
if [ "${vn}" -lt "32" ]; then
echo -n "-std=c++11"
elif [ "${vn}" -lt "350" ]; then
echo -n "-std=c++1y"
else
echo -n "-std=c++14"
fi
fi
else
echo -n "-std=c++11"
fi
}
2017-08-06 06:47:57 +00:00
args=`getopt -o S:s:g:c:O:C:V:D:I:P:f -l stagedir:,source:,gcc-version:,clang-version:,gcc-root:,clang-root:,std:,option:,compiler-option:,version-option:,define:,include:,max-procs:,force,version,help -- "$@"`
if [ "$?" -ne 0 ]; then
echo >&2 "error: options parse error. See 'test.sh --help'"
exit 1
fi
eval set -- ${args}
while [ -n "$1" ]; do
case $1 in
-S|--stagedir) stagedir=$2; shift 2;;
-s|--source) test_cpp=$2; shift 2;;
-g|--gcc-version) gcc_version="$2"; shift 2;;
-c|--clang-version) clang_version="$2"; shift 2;;
--gcc-root) gcc_root="$2"; shift 2;;
--clang-root) clang_root="$2"; shift 2;;
--std) std="$2"; shift 2;;
2013-10-02 13:31:19 +00:00
-O|--option) common_options=("${common_options[@]}" "$2"); shift 2;;
2014-01-11 11:27:55 +00:00
-C|--compiler-option) compiler_options=("${compiler_options[@]}" "$2"); shift 2;;
2013-10-02 13:31:19 +00:00
-V|--version-option) version_options=("${version_options[@]}" "$2"); shift 2;;
-D|--define) user_macros=("${user_macros[@]}" "$2"); shift 2;;
-I|--include) include_paths=("${include_paths[@]}" "$2"); shift 2;;
-P|--max-procs) max_procs=$2; shift 2;;
-f|--force) force=1; shift;;
2017-08-06 06:47:57 +00:00
--version) use_version=1; shift;;
--help) use_help=1; shift;;
--) shift; break;;
*) echo >&2 "error: unknown option($1) used."; exit 1;;
esac
done
if [ ${use_help} -ne 0 ]; then
2017-08-07 10:14:27 +00:00
echo "overview:"
echo " Sprout C++ libraries automatic test script"
echo "usage:"
echo " test.sh [options]"
2017-08-06 01:44:52 +00:00
echo "options:"
echo " -S, --stagedir=<dir> Output files here."
echo " Default; 'testspr'"
echo ""
echo " -s, --source=<file> C++ source file."
echo " Default; './test.cpp'"
echo ""
echo " -g, --gcc-version=<list> Indicates gcc version list (space separated)."
echo " If '.', version that is installed on the system."
echo " Default; '.'"
echo ""
echo " -c, --clang-version=<list> Indicates clang version list (space separated)."
echo " If '.', version that is installed on the system."
echo " Default; '.'"
echo ""
echo " --gcc-root=<dir> Root directory that gcc installed."
echo " Default; '/usr/local'"
echo ""
echo " --clang-root=<dir> Root directory that clang installed."
echo " Default; '/usr/local'"
echo ""
echo " --std=<c++XX> Standard C++ version."
2017-08-06 01:09:03 +00:00
echo " c++11, c++14, or c++17."
echo " Default; 'c++11'"
echo ""
echo " -O, --option=<opt> Add compile option."
echo ""
2014-01-11 11:27:55 +00:00
echo " -C, --compiler-option=<opt> Add compiler specific compile option."
echo " Example; 'clang -ftemplate-depth=512'"
echo ""
echo " -V, --version-option=<opt> Add version specific compile option."
2013-10-02 13:31:19 +00:00
echo " Example; 'clang-3.3 -ftemplate-depth=512'"
echo ""
echo " -D, --define=<identifier> Define macro for preprocessor."
echo ""
echo " -I, --include=<dir> Add system include path."
echo ""
echo " -P, --max-procs=<value> The maximum number of process use."
echo " If other than null, processing in parallel mode."
echo " If 0, using the number of CPUs in the system."
echo ""
echo " -f, --force Allow overwrite of <stagedir>."
echo ""
2017-08-06 06:47:57 +00:00
echo " --version Show version."
echo ""
echo " --help This message."
exit 0
fi
2017-08-06 06:47:57 +00:00
if [ ${use_version} -ne 0 ]; then
script_dir=$(cd $(dirname $0); pwd)
2017-08-06 13:01:11 +00:00
version_hpp_path="${script_dir}/../../sprout/version.hpp"
sprout_version_yyyymmdd=`sed -n "s/[ \t]*#[ \t]*define[ \t]\+SPROUT_VERSION_YYYYMMDD[ \t]\+//p" ${version_hpp_path}`
sprout_copyright=`sed -n "/\/\*=/,/=\*\//s/^[ \t]\+/ /p" ${version_hpp_path}`
echo "version:"
echo " Sprout version(YYYYMMDD) = ${sprout_version_yyyymmdd}"
2017-08-06 13:01:11 +00:00
echo "copyright:"
2017-08-06 06:47:57 +00:00
echo "${sprout_copyright}"
exit 0
fi
echo "settings:"
echo " stagedir = '${stagedir}'"
echo " source = '${test_cpp}'"
echo " gcc-version = (${gcc_version})"
echo " clang-version = (${clang_version})"
echo " gcc-root = '${gcc_root}'"
echo " clang-root = '${clang_root}'"
echo " std = '${std}'"
echo " common-options = (${common_options[*]})"
2014-01-11 11:27:55 +00:00
echo " compiler-options = (${compiler_options[*]})"
echo " version-options = (${version_options[*]})"
echo " user-macros = (${user_macros[*]})"
echo " include-paths = (${include_paths[*]})"
echo " max-procs = ${max_procs}"
echo " force = ${force}"
2014-01-11 14:19:23 +00:00
if [ -z "${gcc_version}" ]; then
gcc_version=" "
fi
if [ -z "${clang_version}" ]; then
clang_version=" "
fi
for user_macro in ${user_macros[*]}; do
define_options="${define_options} -D${user_macro}"
done
for include_path in ${include_paths[*]}; do
include_options="${include_options} -I${include_path}"
done
2015-01-11 15:04:04 +00:00
all_options="-v -Wall -pedantic -pedantic-errors ${define_options} ${include_options} ${common_options[*]}"
2013-10-02 13:31:19 +00:00
vo=0
vkey=""
for option in ${compiler_options[*]}; do
2014-03-01 06:25:21 +00:00
if [ ${vo} -eq 0 ]; then
vkey=${option}
vo=1
else
compiler_specific_options[${vkey}]="${compiler_specific_options[${vkey}]} ${option}"
vo=0
fi
done
for option in ${version_options[*]}; do
2013-10-02 13:31:19 +00:00
if [ ${vo} -eq 0 ]; then
vkey=${option}
vo=1
else
version_specific_options[${vkey}]="${version_specific_options[${vkey}]} ${option}"
vo=0
fi
done
if [ -d "${stagedir}" ]; then
if [ ${force} -eq 0 ]; then
echo >&2 "error: stagedir(${stagedir}) already exists."
exit 1
else
rm -f -r ${stagedir}/*
fi
else
mkdir -p ${stagedir}
fi
echo "test:"
compile() {
local base
if [ ${2} != "." ]; then
base=${1}-${2}
else
base=${1}
fi
local bin=${stagedir}/test.${base//.}.out
local compile_log=${stagedir}/test.${base//.}.compile.log
local execute_log=${stagedir}/test.${base//.}.execute.log
local compiler
if [ ${2} != "." ]; then
2013-10-02 13:31:19 +00:00
compiler=${5}/${base}/bin/${1/%cc}++
else
compiler=${1/%cc}++
fi
echo " compile(${base})..."
2013-10-02 13:31:19 +00:00
${compiler} -o ${bin} ${4} ${version_specific_options[${base}]} ${3} >${compile_log} 2>&1
if [ $? -eq 0 ]; then
echo " compile succeeded."
echo " execute(${base})..."
${bin} >${execute_log} 2>&1
if [ $? -eq 0 ]; then
echo " execute succeeded."
else
echo >&2 " error: execute(${base}) failed."
return 1
fi
else
echo >&2 " error: compile(${base}) failed."
return 1
fi
return 0
}
if [ -z "${max_procs}" ]; then
fail_count=0
for version in ${gcc_version}; do
std_option=`get_std_option "gcc" "${version}" "${std}"`
2014-01-11 11:27:55 +00:00
compile "gcc" "${version}" "${test_cpp}" "${std_option} ${all_options} ${compiler_specific_options[gcc]}" "${gcc_root}"
let fail_count=${fail_count}+$?
done
for version in ${clang_version}; do
std_option=`get_std_option "clang" "${version}" "${std}"`
2014-01-11 11:27:55 +00:00
compile "clang" "${version}" "${test_cpp}" "${std_option} ${all_options} ${compiler_specific_options[clang]}" "${clang_root}"
let fail_count=${fail_count}+$?
done
if [ ${fail_count} -ne 0 ]; then
echo >&2 " error: test(${fail_count}) failed."
else
echo " test succeeded."
fi
else
echo " processing in parallel mode."
echo -n " "
2014-01-11 11:27:55 +00:00
serialized_compiler_specific_options={`
for key in $(echo ${!compiler_specific_options[*]}); do
echo \'${key}\':\'${compiler_specific_options[${key}]}\',
done
echo \'_\':\'\'
`}
serialized_version_specific_options={`
2013-10-02 13:31:19 +00:00
for key in $(echo ${!version_specific_options[*]}); do
echo \'${key}\':\'${version_specific_options[${key}]}\',
done
echo \'_\':\'\'
`}
serialized_std_options={`
for version in ${gcc_version}; do
if [ "${version}" = "." ]; then
echo -n \'gcc\':\'
else
echo -n \'gcc-${version}\':\'
fi
get_std_option "gcc" "${version}" "${std}"
echo \',
done
for version in ${clang_version}; do
if [ "${version}" = "." ]; then
echo -n \'clang\':\'
else
echo -n \'clang-${version}\':\'
fi
get_std_option "clang" "${version}" "${std}"
echo \',
done
echo \'_\':\'\'
`}
python "${test_py}" \
"--stagedir=${stagedir}" \
"--gcc_version=${gcc_version}" "--clang_version=${clang_version}" \
"--gcc_root=${gcc_root}" "--clang_root=${clang_root}" \
2014-01-11 11:27:55 +00:00
"--all_options=${all_options}" "--test_cpp=${test_cpp}" \
"--serialized_std_options=${serialized_std_options}" \
2014-01-11 11:27:55 +00:00
"--serialized_compiler_specific_options=${serialized_compiler_specific_options}" \
"--serialized_version_specific_options=${serialized_version_specific_options}" \
"--max_procs=${max_procs}"
fail_count=$?
echo ""
if [ ${fail_count} -ne 0 ]; then
echo >&2 " error: test(${fail_count}) failed."
else
echo " test succeeded."
fi
fi
echo "finished."