-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbundle_autotests.sh
executable file
·91 lines (69 loc) · 2.22 KB
/
bundle_autotests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#
# Build a single executable for autotest including files for 0 or more embedded autotests
#
# The executable and all the autotest functionality and can also run non-embedded autotests.
#
# The executable contains a "#!" line followed by a zip of the autotest Python source.
#
# The zip files also contains xz-compressed tar files of each embedded autotest
#
# This functionality could be embdedded in autotest itself
case "$#" in
0)
echo "Usage: $0 <created-executable> [autotest-directories]" 1>&2
exit 1
esac
generated_executable="$1"
shift
embedded_autotests_package_name=embedded_autotests
src_directory=$(dirname "$(readlink -f "$0")")
test -r "$src_directory"/autotest.py || {
echo "can not find autotest source" 1>&2
exit 1
}
temp_dir=$(mktemp -d /tmp/bundle_autotests.XXXXXXXXXX) || exit 1
trap 'rm -fr $temp_dir; exit' EXIT INT TERM
cp "$src_directory"/*.py $temp_dir/
mkdir $temp_dir/$embedded_autotests_package_name
touch $temp_dir/$embedded_autotests_package_name/__init__.py
# build tar files for each autotest to be embedded
for pathname in "$@"
do
for tp in "$pathname" "$pathname"/tests.txt "$pathname"/autotest/tests.txt
do
test -f "$tp" || continue
tests_pathname="$(readlink -f "$tp")"
break
done
case "$tests_pathname" in
*/tests.txt) ;;
*)
echo "$pathname - no tests.txt found" 1>&2
exit 1
esac
autotest_directory=$(dirname "$tests_pathname")
exercise=$(basename "$autotest_directory")
test "$exercise" = autotest &&
exercise=$(basename "$(dirname "$autotest_directory")")
test -z "$exercise" && {
echo "$pathname - counld not determine exercise name" 1>&2
exit 1
}
add_to_tar=.
test -f "$pathname" &&
add_to_tar=tests.txt
# tar must be xz compressed because code in load_embedded_autotest function expects this
tar --directory "$autotest_directory" --dereference --xz -cf $temp_dir/$embedded_autotests_package_name/"$exercise.tar" $add_to_tar
done
(
cd $temp_dir
test -r __main__.py || cat >__main__.py <<'eof'
from autotest import main
if __name__ == '__main__': main()
eof
zip .src.zip --quiet -9 -r *.* $embedded_autotests_package_name
)
echo '#!/usr/bin/env python3' >$generated_executable
cat $temp_dir/.src.zip >>$generated_executable
chmod +x $generated_executable