2018-04-15 21:29:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Run from the directory containing this script
|
|
|
|
cd `dirname $0`
|
|
|
|
|
2019-03-02 23:49:25 +00:00
|
|
|
# Global return code (flags an error if any of the actions fail)
|
|
|
|
global_rc=0
|
|
|
|
|
2018-04-15 21:29:09 +00:00
|
|
|
msg()
|
|
|
|
{
|
|
|
|
echo "INFO :: $*" >&2
|
|
|
|
}
|
|
|
|
|
2019-03-02 23:49:25 +00:00
|
|
|
warn()
|
|
|
|
{
|
|
|
|
echo "WARN :: $*" >&2
|
|
|
|
}
|
|
|
|
|
2018-04-15 21:29:09 +00:00
|
|
|
error()
|
|
|
|
{
|
|
|
|
echo "ERROR :: $*" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat >&2 <<EOF
|
|
|
|
${1:+ERROR :: $1
|
|
|
|
|
2018-04-30 06:03:26 +00:00
|
|
|
}Usage: $0 [action] [containter] [args...]
|
2018-04-15 21:29:09 +00:00
|
|
|
|
|
|
|
Action is one of:
|
|
|
|
|
|
|
|
build Build or rebuild the specified containers.
|
2018-04-30 06:03:26 +00:00
|
|
|
install Install crosstool-NG in specified containers.
|
|
|
|
sample Build a sample or if no sample name specified, all.
|
2018-04-28 06:06:21 +00:00
|
|
|
enter Spawn a shell in the specified container.
|
2018-04-30 06:03:26 +00:00
|
|
|
root Spawn a root shell in the specified container.
|
2018-04-28 06:06:21 +00:00
|
|
|
clean Clean up in the specified container.
|
2022-02-10 22:43:30 +00:00
|
|
|
distclean Same as clean but also remove installed versions of
|
|
|
|
Crosstool-NG and the previously built toolchains.
|
2018-04-15 21:29:09 +00:00
|
|
|
|
2018-04-30 06:03:26 +00:00
|
|
|
If a special container name 'all' is used, the action is performed
|
|
|
|
on all the containers.
|
2018-04-15 21:29:09 +00:00
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2018-10-28 17:44:22 +00:00
|
|
|
do_cleanup()
|
|
|
|
{
|
|
|
|
local d
|
|
|
|
|
|
|
|
for d in "$@"; do
|
|
|
|
[ -d "$d" ] || continue
|
|
|
|
chmod -R a+w "$d"
|
|
|
|
rm -rf "$d"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2018-04-15 21:29:09 +00:00
|
|
|
# Build a docker container, store its ID.
|
|
|
|
action_build()
|
|
|
|
{
|
|
|
|
local cntr=$1
|
|
|
|
|
2019-03-02 23:49:25 +00:00
|
|
|
msg "Cleaning up previous runs for ${cntr}"
|
|
|
|
do_cleanup ${cntr}/{build,install,xtools}
|
2018-04-15 21:29:09 +00:00
|
|
|
msg "Building Docker container for ${cntr}"
|
2022-02-10 22:43:30 +00:00
|
|
|
set -x
|
2018-09-28 18:44:48 +00:00
|
|
|
docker build --no-cache -t "ctng-${cntr}" --build-arg CTNG_GID=`id -g` --build-arg CTNG_UID=`id -u` "${cntr}"
|
2018-04-15 21:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Common backend for enter/test
|
|
|
|
_dckr()
|
|
|
|
{
|
|
|
|
local topdir=`cd ../.. && pwd`
|
|
|
|
local cntr=$1
|
2018-09-28 18:44:48 +00:00
|
|
|
local scmd prefix
|
2018-04-15 21:29:09 +00:00
|
|
|
shift
|
|
|
|
|
2018-10-28 17:44:22 +00:00
|
|
|
mkdir -p ${cntr}/{build,install,xtools}
|
2018-09-28 18:44:48 +00:00
|
|
|
prefix="docker run --rm -i -t \
|
|
|
|
-v `pwd`/common-scripts:/common-scripts:ro \
|
2018-04-15 21:29:09 +00:00
|
|
|
-v ${topdir}:/crosstool-ng:ro \
|
2018-10-28 17:44:22 +00:00
|
|
|
-v `pwd`/${cntr}/build:/home/ctng/work \
|
|
|
|
-v `pwd`/${cntr}/install:/opt/ctng \
|
|
|
|
-v `pwd`/${cntr}/xtools:/home/ctng/x-tools \
|
2018-09-28 18:44:48 +00:00
|
|
|
-v $HOME/src:/home/ctng/src:ro \
|
|
|
|
ctng-${cntr}"
|
|
|
|
if [ -n "${AS_ROOT}" ]; then
|
|
|
|
$prefix "$@"
|
|
|
|
elif [ -n "$*" ]; then
|
|
|
|
$prefix su -l ctng -c "$*"
|
|
|
|
else
|
|
|
|
$prefix su -l ctng
|
|
|
|
fi
|
2019-03-02 23:49:25 +00:00
|
|
|
if [ $? != 0 ]; then
|
2022-02-10 22:43:30 +00:00
|
|
|
global_rc=1
|
2019-03-02 23:49:25 +00:00
|
|
|
fi
|
2022-02-10 22:43:30 +00:00
|
|
|
return $global_rc
|
2018-04-15 21:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Run the test
|
2018-04-30 06:03:26 +00:00
|
|
|
action_install()
|
2018-04-15 21:29:09 +00:00
|
|
|
{
|
|
|
|
local cntr=$1
|
|
|
|
|
|
|
|
# The test assumes the top directory is bootstrapped, but clean.
|
|
|
|
msg "Setting up crosstool-NG in ${cntr}"
|
2018-10-28 17:44:22 +00:00
|
|
|
do_cleanup ${cntr}/build
|
2019-03-02 23:49:25 +00:00
|
|
|
if ! _dckr "${cntr}" /common-scripts/ctng-install; then
|
2022-02-10 22:43:30 +00:00
|
|
|
warn "Installation failed"
|
2019-03-02 23:49:25 +00:00
|
|
|
elif ! _dckr "${cntr}" /common-scripts/ctng-test-basic; then
|
2022-02-10 22:43:30 +00:00
|
|
|
warn "Basic tests failed"
|
2019-03-02 23:49:25 +00:00
|
|
|
fi
|
2018-04-30 06:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Run the test
|
|
|
|
action_sample()
|
|
|
|
{
|
|
|
|
local cntr=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
msg "Building samples in ${cntr} [$@]"
|
2018-10-28 17:44:22 +00:00
|
|
|
do_cleanup ${cntr}/build
|
2018-09-28 18:44:48 +00:00
|
|
|
_dckr "${cntr}" /common-scripts/ctng-build-sample "$@"
|
2018-04-15 21:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Enter the container using the same user account/environment as for testing.
|
|
|
|
action_enter()
|
|
|
|
{
|
|
|
|
local cntr=$1
|
2018-09-28 18:44:48 +00:00
|
|
|
shift
|
2018-04-15 21:29:09 +00:00
|
|
|
|
|
|
|
msg "Entering ${cntr}"
|
2018-09-28 18:44:48 +00:00
|
|
|
_dckr "${cntr}" "$@"
|
2018-04-15 21:29:09 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 06:03:26 +00:00
|
|
|
# Enter the container using the same user account/environment as for testing.
|
|
|
|
action_root()
|
|
|
|
{
|
|
|
|
local cntr=$1
|
|
|
|
|
|
|
|
msg "Entering ${cntr} as root"
|
2018-09-28 18:44:48 +00:00
|
|
|
AS_ROOT=y _dckr "${cntr}" /bin/bash
|
2018-04-30 06:03:26 +00:00
|
|
|
}
|
|
|
|
|
2018-04-15 21:29:09 +00:00
|
|
|
# Clean up after test suite run
|
|
|
|
action_clean()
|
|
|
|
{
|
|
|
|
local cntr=$1
|
|
|
|
|
|
|
|
msg "Cleaning up after ${cntr}"
|
2018-10-28 17:44:22 +00:00
|
|
|
do_cleanup ${cntr}/build
|
|
|
|
}
|
|
|
|
|
|
|
|
# Clean up after test suite run
|
|
|
|
action_distclean()
|
|
|
|
{
|
|
|
|
local cntr=$1
|
|
|
|
|
|
|
|
msg "Dist cleaning ${cntr}"
|
|
|
|
do_cleanup ${cntr}/{build,install,xtools}
|
2018-04-15 21:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
all_containers=`ls */Dockerfile | sed 's,/Dockerfile,,'`
|
2018-04-30 06:03:26 +00:00
|
|
|
action=$1
|
|
|
|
selected_containers=$2
|
|
|
|
shift 2
|
|
|
|
if [ "${selected_containers}" = "all" ]; then
|
|
|
|
selected_containers="${all_containers}"
|
|
|
|
fi
|
2018-04-15 21:29:09 +00:00
|
|
|
|
|
|
|
case "${action}" in
|
2018-10-28 17:44:22 +00:00
|
|
|
build|install|sample|enter|root|clean|distclean)
|
2018-04-15 21:29:09 +00:00
|
|
|
for c in ${selected_containers}; do
|
2020-02-04 00:11:33 +00:00
|
|
|
eval "action_${action} ${c%/} \"$@\""
|
2018-04-15 21:29:09 +00:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
"")
|
|
|
|
usage "No action specified."
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage "Unknown action ${action}."
|
|
|
|
;;
|
|
|
|
esac
|
2019-03-02 23:49:25 +00:00
|
|
|
if [ "${global_rc}" != 0 ]; then
|
|
|
|
error "Some of the actions failed, see warnings above"
|
|
|
|
fi
|
|
|
|
exit ${global_rc}
|