tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / kyua-atf-compat / dist / atf2kyua.sh
blobe969a057baec6fee16b9aa60822c6558580f3c3e
1 #! __SH__
2 # Copyright 2011 Google Inc.
3 # All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of Google Inc. nor the names of its contributors
15 # may be used to endorse or promote products derived from this software
16 # without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 # \file atf2kyua.sh
31 # Converts Atffiles to Kyuafiles for a particular test suite.
34 . "${KYUA_ATF_COMPAT_PKGDATADIR:-__PKGDATADIR__}/lib.subr"
37 # Prunes all Kyuafiles from a test suite in preparation for regeneration.
39 # \param target_root The path to the test suite.
40 remove_kyuafiles() {
41 local target_root="${1}"; shift
43 if [ -d "${target_root}" ]; then
44 lib_info "Removing stale Kyuafiles from ${target_root}"
45 find "${target_root}" -name Kyuafile -exec rm -f {} \;
50 # Obtains the list of test programs and subdirectories referenced by an Atffile.
52 # Any globs within the Atffile are expanded relative to the directory in which
53 # the Atffile lives.
55 # \param atffile The path to the Atffile to process.
57 # \post Prints the list of files referenced by the Atffile on stdout.
58 extract_files() {
59 local atffile="${1}"; shift
61 local dir="$(dirname "${atffile}")"
63 local globs="$(grep '^tp-glob:' "${atffile}" | cut -d ' ' -f 2-)"
64 local files="$(grep '^tp:' "${atffile}" | cut -d ' ' -f 2-)"
66 for file in ${files} $(cd "$(dirname "${atffile}")" && echo ${globs}); do
67 if test -d "${dir}/${file}" -o -x "${dir}/${file}"; then
68 echo "${file}"
70 done
74 # Converts an Atffile to a Kyuafile.
76 # \param atffile The path to the Atfffile to convert.
77 # \param kyuafile The path to where the Kyuafile will be written.
78 convert_atffile() {
79 local atffile="${1}"; shift
80 local kyuafile="${1}"; shift
82 lib_info "Converting ${atffile} -> ${kyuafile}"
84 local test_suite="$(grep 'prop:.*test-suite.*' "${atffile}" \
85 | cut -d \" -f 2)"
87 local dir="$(dirname "${atffile}")"
89 local subdirs=
90 local test_programs=
91 for file in $(extract_files "${atffile}"); do
92 if test -f "${dir}/${file}/Atffile"; then
93 subdirs="${subdirs} ${file}"
94 elif test -x "${dir}/${file}"; then
95 test_programs="${test_programs} ${file}"
97 done
99 mkdir -p "$(dirname "${kyuafile}")"
101 echo "syntax('kyuafile', 1)" >"${kyuafile}"
102 echo >>"${kyuafile}"
103 echo "test_suite('${test_suite}')" >>"${kyuafile}"
104 if [ -n "${subdirs}" ]; then
105 echo >>"${kyuafile}"
106 for dir in ${subdirs}; do
107 echo "include('${dir}/Kyuafile')" >>"${kyuafile}"
108 done
110 if [ -n "${test_programs}" ]; then
111 echo >>"${kyuafile}"
112 for tp in ${test_programs}; do
113 echo "atf_test_program{name='${tp}'}" >>"${kyuafile}"
114 done
119 # Adds Kyuafiles to a test suite by converting any existing Atffiles.
121 # \param source_root The path to the existing test suite root. Must contain
122 # an Atffile and the test programs.
123 # \param target_root The path to the directory where the Kyuafiles will be
124 # written. The layout will mimic that of source_root.
125 add_kyuafiles() {
126 local source_root="${1}"; shift
127 local target_root="${1}"; shift
129 for atffile in $(cd "${source_root}" && find . -name Atffile); do
130 local subdir="$(echo "${atffile}" | sed 's,Atffile$,,;s,^\./,,')"
131 convert_atffile "${source_root}/${subdir}Atffile" \
132 "${target_root}/${subdir}Kyuafile"
133 done
137 # Prints program usage to stdout.
139 # \param progname The name of the program to use for the syntax help.
140 usage() {
141 local progname="${1}"; shift
142 echo "Usage: ${progname} [-s source_root] [-t target_root]"
146 # Entry point for the program.
148 # \param ... The user-provided arguments.
149 main() {
150 local source_root=
151 local target_root=
153 while getopts ':s:t:' arg "${@}"; do
154 case "${arg}" in
156 source_root="${OPTARG}"
159 target_root="${OPTARG}"
162 lib_usage_error "Unknown option -${OPTARG}"
164 esac
165 done
166 shift $((${OPTIND} - 1))
168 [ -n "${source_root}" ] || source_root=.
169 [ -n "${target_root}" ] || target_root="${source_root}"
171 [ ${#} -eq 0 ] || lib_usage_error "No arguments allowed"
173 [ -f "${source_root}/Atffile" ] || \
174 lib_error "${source_root} is not a test suite; missing Atffile"
176 remove_kyuafiles "${target_root}"
177 add_kyuafiles "${source_root}" "${target_root}"
181 main "${@}"