blob: 903ff80fe587921fb131d1a1167ff7c6dc4556df [file] [log] [blame]
#!/bin/sh
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This file takes an output file as its first parameter, followed by one or more
# FIDL schema files in JSON format. It then generates a header containing a C++
# map from schema filename to file contents, which can then be used for test
# purposes.
set -e
FILENAME="${1}"
rm -f "${FILENAME}"
cat > "${FILENAME}" << EOF
#include <map>
#include <string>
// Autogenerated: Do not modify!
namespace fidl_codec_test {
class ${2} {
public:
${2}() {
map_ = {
EOF
add_entry() {
if [ ! -f "$1" ]; then
echo "file $1 not found"
exit 1
fi;
cat >> "${FILENAME}" <<EOF
{"$1", R"FIDL($(cat "$1"))FIDL"},
EOF
}
if [ ${3} = "-content" ]; then
if [ ! -f "${4}" ]; then
echo "file ${4} not found"
exit 1
fi;
while IFS= read -r line
do
add_entry $line
done < "${4}";
else
shift 2
for i in "$@"; do
add_entry ${i}
done
fi;
cat >> "${FILENAME}" << EOF
};
}
std::map<std::string, std::string> &map() { return map_; }
private:
std::map<std::string, std::string> map_;
};
} // namespace fidl_codec_test
EOF